简体   繁体   English

lucene词组精确搜索

[英]lucene phrase exact search

I am using phrase query for hibernate lucene search in my code.It is working but I want to do exact search which is case Insensitive.I have tried term query but it is case sensitive. 我在我的代码中使用短语查询进行休眠Lucene搜索。它正在工作,但我想执行不区分大小写的精确搜索。我尝试过术语查询,但它区分大小写。 I want to search like eg: 我想搜索例如:

BeautifulRainy Day. 美丽的雨天。 If I search "rainy day" the result should be 0 hits. 如果我搜索“雨天”,则结果应为0。 If i search "beautifulrainy Day" the result should be 1 hit. 如果我搜索“ beautifulrainy Day”,结果应该是1次点击。 If I search "Day" the result should be 0 hits. 如果我搜索“天”,则结果应为0。

Basically I want java (.equalignorecase ) type search not (.contains) .I want to keep using the phrase query if it is possible. 基本上我不希望Java(.equalignorecase)类型搜索(.contains)。如果可能的话,我想继续使用短语查询。

If you want case-insensitive matching, you have to index your data case-insensitive. 如果要使用不区分大小写的匹配,则必须索引不区分大小写的数据。

You can do this by, for example, adding another field to your class with the toLowerCase() value of your String and search that field instead. 例如,您可以通过使用String的toLowerCase()值将另一个字段添加到类中并搜索该字段来实现。

(Or maybe hibernate search allows case-insensitive indexing with a option?) (或者,休眠搜索允许带选项的不区分大小写的索引编制?)

Hi Please go through this answer given by me. 嗨,请仔细阅读我给出的答案 which search exact case insensitive term. 哪个搜索不区分大小写的精确术语。 Have just passed the search string in double quotes which act as exact match search. 刚刚在搜索字符串中使用了双引号,这是完全匹配搜索。

QueryParser parser = new QueryParser(Version.LUCENE_34, "TITLE" ,new StandardAnalyzer(Version.LUCENE_34));

    Query query;

    query = parser.parse("\"beautifulrainy Day\"");

    TopDocs hits = searcher.search(query,3);

Here TITLE is the name of the field, so place field name which you have used at the time of indexing. 这里的TITLE是字段的名称,因此请放置索引时使用的字段名称。

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

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