1
votes

I am using Hibernate Search and Lucene for full text Search on the content field of my document database. I have a search text box which is taking user query. I have fixed the search to phrase matching based search. I want to use the combination of search. To explain my point let's say user wants to search "United States". If I use phrase based search, it will give me every occurrence on the query and ignoring individual occurrences of "United" and "States". If I make the search to field matching, it will fetch all the results containing individual query words. My question is, Is there any direct way so that if user search for a phrase with quotations mark or any other mark, the hibernate search apply phrase based search. Other wise it retrieve the word based results. If user enter two query words separated with any Boolean character, it apply boolean search, etc. For example:

Example Query     | Description
United States     | Search for all occurrences of two words: United and States
"United States"   | Search for phrase "United States"  
United NOT States | Apply Boolean not query on United and States

etc

I want to implement something like google, I know that google is too power full but at least a little bit of it can be done. I just want to know that is there any built in functionality in Hibernate Search and lucene for this type of thing or I need to give user some operators, parse user query manually, implement some logic to find out operators, and other symbols and then apply query based on found symbols. Kindly Help

1

1 Answers

0
votes

There is nothing like that directly in Hibernate Search, but Lucene has a query parser. For its syntax have a look at - http://lucene.apache.org/core/4_10_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description.

If you are happy with its functionality and syntax you could just pass the user input to the Lucene query parser. If not, you will need to write your own syntax and syntax parser which will translate the query into an appropriate Hibernate Search / Lucene query.