在搜索的时候经常会遇到,要查询一个field里面的多个值,类似sql语句的 select * from table where aa in ('a','b','c')。
在lucene里面用MultiPhraseQuery,案例如下:
MultiPhraseQuery query = new MultiPhraseQuery();
Term []terms = null;
if(!StringUtils.isBlank(src))
{
String []citys = StringUtils.split(src, ",");
terms = new Term[citys.length];
for (int i = 0; i < citys.length; i++)
{
String city = citys[i];
terms[i] = new Term("srcCity",city);
}
query.add(terms);
rootQuery.add(query,BooleanClause.Occur.MUST);
}