开发者

What is the equallent operator like "IN" of SQL Server for LUCENE.NET

开发者 https://www.devze.com 2023-03-30 09:15 出处:网络
How can i get \" IN \" (of SQL Server) functionality in LUCENE.NET? Suppose assume that some records are exist with ID : a开发者_如何学运维,b,c,d,e,f,..

How can i get " IN " (of SQL Server) functionality in LUCENE.NET?

Suppose assume that some records are exist with ID : a开发者_如何学运维,b,c,d,e,f,..

So I want to get the records which are in ('a','b','c') by using Lucene.net.

Please let me know how can i write this query in Lucene.net.

Thanks in Advance.


You need to use a BooleanQuery with the SHOULD clause.

BooleanQuery query = new BooleanQuery();
query.Add(new TermQuery(new Term("ID", "a"), Occur.SHOULD));
query.Add(new TermQuery(new Term("ID", "b"), Occur.SHOULD));
query.Add(new TermQuery(new Term("ID", "c"), Occur.SHOULD));

This means that any result must have either ID = a, b, or c.


Query q = new QueryParser("ID", new YourAnalyzer()).Parse("a b c d") :)

0

精彩评论

暂无评论...
验证码 换一张
取 消