最新代码
This commit is contained in:
36
public/sdk/docs/scripts/fulltext-search.js
Normal file
36
public/sdk/docs/scripts/fulltext-search.js
Normal file
@ -0,0 +1,36 @@
|
||||
window.Searcher = (function() {
|
||||
function Searcher() {
|
||||
this._index = lunr(function () {
|
||||
this.field('title', {boost: 10})
|
||||
this.field('body')
|
||||
this.ref('id')
|
||||
}) ;
|
||||
|
||||
this._indexContent = undefined;
|
||||
}
|
||||
|
||||
Searcher.prototype.init = function() {
|
||||
var self = this;
|
||||
|
||||
$("script[type='text/x-docstrap-searchdb']").each(function(idx, item) {
|
||||
self._indexContent = JSON.parse(item.innerHTML);
|
||||
|
||||
for (var entryId in self._indexContent) {
|
||||
self._index.add(self._indexContent[entryId]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Searcher.prototype.search = function(searchTerm) {
|
||||
var results = [],
|
||||
searchResults = this._index.search(searchTerm);
|
||||
|
||||
for (var idx = 0; idx < searchResults.length; idx++) {
|
||||
results.push(this._indexContent[searchResults[idx].ref])
|
||||
}
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
return new Searcher();
|
||||
})();
|
Reference in New Issue
Block a user