How to filter Lucene search with a field by 2 values?
I have a lucene search where i was trying to filter my search with LanguageIds, but i was unable to do that. I was passing my Languageids like "1,2,3",but its not filtering correctly,its only taking values having languageIds "1,2,3". but i want results having languageIds with "1", "1,2", "1,3", "1,2,3". Can any body tell me how to pass multiple values for a single termQuery in Lucene.net?
Wat i have done so far is
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);
});
}
开发者_JS百科 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);
}
you can try to add the same field multiple times while indexing like
doc.Add( new Field(resourceLanguageId,"1"...
doc.Add( new Field(resourceLanguageId,"2"...
doc.Add( new Field(resourceLanguageId,"3"...
精彩评论