搜索
ling-base common/search 模块文档
在线 Playground
在浏览器中直接体验本页相关 API,无需本地安装 Go 环境。
search
Full-text search engine abstraction built on top of Bleve, supporting indexing, batch indexing, deletion, complex queries, facets, highlighting, and auto-complete suggestions.
Key types
Engine— the full-text search interface (Index,IndexBatch,Delete,Search, suggestions,DocCount,Stats,Close)ExtendedEngine— additional operations (GetByID,Update,BulkDelete,DeleteByQuery,Scroll,SearchAfter,Refresh,HealthCheck)Doc— a document to index (ID, Type, Fields)SearchRequest— query with keyword, term filters, range filters, match/phrase/prefix/wildcard/regex/fuzzy clauses, facets, sorting, pagination, highlightingSearchResult/Hit/FacetResult— search responsesConfig— index path, analyzer, default search fields, timeouts, batch size
Quick start
import "github.com/LingByte/ling-base/common/search"
eng, err := search.NewDefault("/tmp/myindex")
if err != nil {
log.Fatal(err)
}
defer eng.Close()
eng.Index(ctx, search.Doc{
ID: "doc1",
Type: "article",
Fields: map[string]any{
"title": "Hello World",
"content": "This is a test document",
},
})
res, _ := eng.Search(ctx, search.SearchRequest{Keyword: "hello", Size: 10})
for _, hit := range res.Hits {
fmt.Println(hit.ID, hit.Score)
}