mirror of
https://github.com/yv1ing/MollyBlog.git
synced 2025-09-16 14:53:45 +08:00
new: Added post search module
This commit is contained in:
32
internal/mApp/mSearch.go
Normal file
32
internal/mApp/mSearch.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user