0
votes

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.

2

2 Answers

0
votes

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?)

0
votes

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.