简体   繁体   English

lucene.net的IN运算符

[英]IN operator for lucene.net

SQL server can query using IN operator for the specific IDs like: SQL Server可以使用IN运算符查询特定的ID,例如:

ID in (2,23,122,44,22) 

I was using the same query for displaying related results in another page. 我使用同一查询在另一页中显示相关结果。 I have to move to lucene.net for increasing speed of display so I need to replace the old code I used above. 我必须移至lucene.net以提高显示速度,所以我需要替换上面使用的旧代码。 I searched a lot on Google but did not find any alternative for it. 我在Google上进行了很多搜索,但没有找到其他选择。

I tried composing boolean query in lucene.net like: 我试着在lucene.net中组成布尔查询,如下所示:

ID:1 OR ID:2 OR ID:3 

... but due to limitation of 1024 expressions I am unable to use this way too. ...但是由于1024个表达式的限制,我也无法使用这种方式。 Please suggest how can I resolve this problem. 请提出如何解决此问题的建议。

The maximum number of clauses in a boolean query is 1024 by default. 默认情况下,布尔查询中子句的最大数量为1024。

You can increase this limit. 您可以增加此限制。

There would be performance penalty, though. 但是,这将导致性能下降。 or you can index the values on the document and search for them (lucene will do an OR operation on different fields with the same name). 或者,您可以为文档中的值建立索引并进行搜索(lucene将对具有相同名称的不同字段执行“或”操作)。

You can change the limit using a static property on BooleanQuery class: 您可以使用BooleanQuery类的静态属性来更改限制:

 BooleanQuery.MaxClauseCount = 99999;

Omri 奥姆里

By default all terms in a query are ORed by default: 默认情况下,查询中的所有术语默认情况下都经过“或”运算:

ID: 1 2 3

This will return a list of all documents with ids 1, 2 and 3. 这将返回ID为1、2和3的所有文档的列表。

You can use a simple query, 您可以使用一个简单的查询,

var ids = new[] { "1", "2", "3" };
var query = new QueryParser(version, idProperty, analyzer).Parse(string.Join(" ", ids));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM