jf-roku/docs/api/scripts/fulltext-search.js
Charles Ewert 00a6858c22
Auto update api docs and upload api docs to gh-pages (#1418)
Co-authored-by: cewert <cewert@users.noreply.github.com>
2023-10-26 22:19:51 -04:00

36 lines
980 B
JavaScript

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();
})();