我正在尝试为我的POJO类上的完成建议属性设置上下文,但是,大多数在线文档都基于配置设置。有什么想法可以实现这一目标吗?
[Completion]
public CompletionField Suggest { get; set; }
答案 0 :(得分:0)
用于索引:
[Completion(Name = "FieldNameSuggest")]
public CompletionField Suggest
{
get
{
List<string> data = new List<string>();
data.AddRange(new List<string>() {"word1",word2"word3",... });//for suggest
return new CompletionField()
{
Input = data,
Weight = 1
};
}
}
要获取建议:
查询制作:
var sugContainer = new SuggestContainer
{
{ "completion-suggest", new SuggestBucket
{
Prefix ="word",//text for search
Completion = new CompletionSuggester
{
//Fuzzy = new FuzzySuggester
//{
// Fuzziness = Fuzziness.Auto,
// MinLength = 1,
// PrefixLength = 2,
// Transpositions = true,
// UnicodeAware = false
//},
Analyzer = "simple",
Field =new Field("FieldNameSuggest"),
Size =10, //SuggestionCount
SkipDuplicates=true,
}
}
}
};
最终搜索:
var Result = Client.Search<T>(new SearchRequest<T>
{
Suggest = sugContainer ,
...
});