我正在尝试为Go的Elasticsearch中的完成建议添加上下文。我正在为Go使用Olivere的elasticsearch库,但无法确定必须传递给 ContextQueries() 的参数。我可以看到它需要一种 SuggesterContextQuery 类型,但是我不确定如何制作。
我尝试过docs,但我仍然不清楚。
func (q *CompletionSuggester) ContextQueries(queries ...SuggesterContextQuery) *CompletionSuggester {
q.contextQueries = append(q.contextQueries, queries...)
return q
}
type SuggesterContextQuery interface {
Source() (interface{}, error)
}
这是我的代码
sugg := "sticker-suggest"
tagSuggester := elastic.NewCompletionSuggester(sugg).Fuzziness(0).Text(term).Field("tags").SkipDuplicates(true)
searchSource := elastic.NewSearchSource().
Suggester(tagSuggester).
FetchSource(false).
TrackScores(true)
searchResult, err := client.Search().
Index(index).
Type(Type).
SearchSource(searchSource).
Do(ctx)
如何为完成提示添加上下文?