如何查询使用Lucene.Net,类似于SQL的IN操作符集合中的条款? [英] How to query for terms IN a collection using Lucene.Net, similar to SQL's IN operator?
本文介绍了如何查询使用Lucene.Net,类似于SQL的IN操作符集合中的条款?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在查找的文件是否有一个特定的字段值的可能值的集合,
We are trying to search whether documents have a particular field value in a collection of possible values,
field:[value1, value2, value3, ..., valueN]
这将返回元素,如果它匹配任何的输入值,类似于SQL的在()
运营商。
这是类似于范围
查询,但该元素不一定描述一个范围。
This would be similar to a range
query, but the elements do not necessarily describe a range.
使用Lucene.Net API的一个例子是,
An example using Lucene.Net API would be,
var query = new QueryParser(version, "FieldName", analyzer).In("value1", "value2", "value3");
这是可能的Lucene.Net?
Is this possible in Lucene.Net?
推荐答案
字段:值1场:值2 ....
应该做的伎俩。默认情况下所有术语或
版
field:value1 field:value2 ....
should do the trick. By default all terms are OR
ed.
编程,你可以试试,
public static Query In(string fieldName, IEnumerable<string> values)
{
var query = new BooleanQuery();
foreach (var val in values)
{
query.Add(new TermQuery(new Lucene.Net.Index.Term(fieldName, val)), BooleanClause.Occur.SHOULD);
}
return query;
}
这篇关于如何查询使用Lucene.Net,类似于SQL的IN操作符集合中的条款?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文