简体   繁体   中英

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. I want to search like eg:

BeautifulRainy Day. If I search "rainy day" the result should be 0 hits. If i search "beautifulrainy Day" the result should be 1 hit. If I search "Day" the result should be 0 hits.

Basically I want java (.equalignorecase ) type search not (.contains) .I want to keep using the phrase query if it is possible.

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.

(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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