new: Added post search module

This commit is contained in:
2024-12-17 16:15:51 +08:00
parent 474bf3e6bb
commit 9386306e7e
26 changed files with 590608 additions and 11 deletions

32
internal/mApp/mSearch.go Normal file
View 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()
}