简体   繁体   English

Lucene中的AND OR搜索语法

[英]AND OR search syntax in lucene

I am using Lucene. 我正在使用Lucene。 I have three columns which are 我有三列

DocId - TermID - TermFrequency
 1    -   004  -      667
 2    -   005  -      558

If i use mysql then query for AND operation is 如果我使用mysql,则查询AND操作是

SELECT * FROM table_name WHERE DocId='1' AND TermId='004'

How can i write above query in Lucene using JAVA. 如何使用JAVA在Lucene中编写以上查询。 For one column search code i am using is 我正在使用的一列搜索代码是

Query query = new QueryParser(Version.LUCENE_35,"TermID", analyzer).parse("004");

How can i use AND operation in QueryParser ?? 如何在QueryParser中使用AND操作?

Terms can be grouped with the AND keyword like so: 可以使用AND关键字对术语进行分组,如下所示:

Query query = new QueryParser(Version.LUCENE_35,"TermID", analyzer).parse("004 AND DocId:1");

Note that you don't need to qualify the field for your "004" term because you've set "TermId" as the default field. 请注意,由于您已将"TermId"设置为默认字段,因此无需使该字段符合您的"004"字词。

You should read the manual on the query syntax...it's pretty expressive. 您应该阅读有关查询语法的手册 ...它非常具有表达力。

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

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