我有一个lucene搜索,我试图用LanguageIds过滤我的搜索,但我无法做到这一点。我正在传递我的Languageids,如“1,2,3”,但它没有正确过滤,它只采用了带有languageIds“1,2,3”的值。但我想要的结果是languageIds为“1”,“1,2”,“1,3”,“1,2,3”。任何机构都可以告诉我如何在Lucene.net中为单个termQuery传递多个值吗?
我迄今为止做过的是
if (languagelds.Contains(","))
{
List<String> languageld = languagelds.Trim().Split(',').ToList();
languageld.ForEach(lid =>
{
TermQuery languageQuery = new TermQuery(new Term("resourceLanguageIds", lid));
filterQuery.Add(languageQuery, BooleanClause.Occur.MUST);
});
}
else
{
TermQuery languageQuery = new TermQuery(new Term("resourceLanguageIds", languagelds));
filterQuery.Add(languageQuery, BooleanClause.Occur.MUST);
}
filterQuery.Add(productQuery, BooleanClause.Occur.MUST);
Filter filter = new CachingWrapperFilter(new QueryWrapperFilter(filterQuery));
TopScoreDocCollector collector = TopScoreDocCollector.create(100, true);
Hits hits = null;
if (sortField != "Rank")
{
hits = indexSearch.Search(searchQuery, filter, sort);
indexSearch.SetDefaultFieldSortScoring(true, true);
}
else
{
hits = indexSearch.Search(searchQuery, filter);
}
答案 0 :(得分:1)
你可以尝试多次添加相同的字段,同时索引像
doc.Add( new Field(resourceLanguageId,"1"...
doc.Add( new Field(resourceLanguageId,"2"...
doc.Add( new Field(resourceLanguageId,"3"...