为快速实现一个中文API搜索原型(中文API文档浏览器 · Issue #165 · program-in-chinese/overview), 使用了JS Search库, 参考JS Search演示

演示地址: API搜索演示

演示:

2019-07-30_api搜索原型

源码库: program-in-chinese/team_website

部分JavaScript代码:

var 重建索引 = function() {
  搜索 = new JsSearch.Search('');

  搜索.tokenizer = new JsSearch.StopWordsTokenizer(搜索.tokenizer);
  搜索.indexStrategy = new JsSearch.AllSubstringsIndexStrategy();
  
  搜索.addIndex('');
  搜索.addIndex('');

  搜索.addDocuments(所有数据);
};

...
var 进行搜索 = function() {
  var 原始输入 = 搜索框.value;
  var 关键字 = 原始输入;
  if (中英词典[原始输入]) {
    关键字 = 中英词典[原始输入]
  }
  搜索结果 = 搜索.search(关键字);
  更新显示();
};