Title asks it all… I want to do a multi field – phrase search in Lucene.. How to do it ?
for example :
I have fields as String s[] = {"title","author","content"};
I want to search harry potter across all fields.. How do I do it ?
Can someone please provide an example snippet ?
Use
MultiFieldQueryParser, its a QueryParser which constructs queries to search multiple fields..Other way is to use Create a BooleanQuery consisting of TermQurey (in your case phrase query).
Third way is to include the content of other fields into your
defaultcontent field.Add
Generally speaking, querying on multiple fields isn’t the best practice for user-entered queries. More commonly, all words you want searched are indexed into a contents or keywords field by combining various fields.
Update
Usage:
The
MultiFieldQueryParserwill resolve the query in this way: (See javadoc)Hope this helps.