0.0.0 • Published 5 years ago
hexo-generator-search-index v0.0.0
hexo-generator-search-index
Use js-search to generate index
Use jieba-wasm to tokenize chinese
It generates an object which key is the query and value is an array of document (post / page) index sorted as roguhly idftf desc.
You should not use this, It is just an experiment.
With index generated it almost doubled the size of search.json. So it maybe loads slower. Use indexOf to search keywords is fast enough in most cases
Install
npm i hexo-generator-search-indexUsage
- Put this in your site
_config.yml
search:
path: search.json
field: post # post or page (whether generate result for non post page)
minKeyLen: 2 # min key len in search index
indexStrategy: prefix # prefix otherwise use exact word index strategy
enableIndex: true # whether put index in the outputDemos
You can find demo ouput in demos folder.
do search
let query // user input search query
fetch('/saerch.json')
.then(res => res.json())
.then(data => {
const result = data.m[query].map(idx => data.docs[idx])
console.log(result)
})0.0.0
5 years ago