mirror of
https://github.com/yv1ing/MollyBlog.git
synced 2025-09-16 14:53:45 +08:00
33 lines
749 B
Go
33 lines
749 B
Go
package mApp
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/huichen/wukong/engine"
|
|
"github.com/huichen/wukong/types"
|
|
)
|
|
|
|
func (ma *MApp) loadPostIndex() {
|
|
ma.searcher = &engine.Engine{}
|
|
|
|
ma.searcher.Init(types.EngineInitOptions{
|
|
UsePersistentStorage: true,
|
|
PersistentStorageFolder: "tmp",
|
|
StopTokenFile: "data/stop_tokens.txt",
|
|
SegmenterDictionaries: "data/dictionary.txt",
|
|
IndexerInitOptions: &types.IndexerInitOptions{
|
|
IndexType: types.LocationsIndex,
|
|
},
|
|
})
|
|
|
|
for _, post := range ma.Posts {
|
|
postFile, _ := os.OpenFile(post.HtmlPath, os.O_RDONLY, 0666)
|
|
postData, _ := io.ReadAll(postFile)
|
|
|
|
ma.searcher.IndexDocument(post.Index, types.DocumentIndexData{Content: string(postData)}, false)
|
|
}
|
|
|
|
ma.searcher.FlushIndex()
|
|
}
|