Java – How to search across multiple fields in Lucene using Query Syntax

indexingjavalucene

I'm searching a lucene index and I'm building search queries like

field1:"hello" AND field2:"world"

but I'd like to search for a value in any field as well as the values in specific fields in the same query i.e.

field1:"hello" AND anyField:"world"

Can anyone tell me how I can search across all indexed fields in this way?

Best Answer

Based on the answers I got for this question: Impact of repeat value across multiple fields in Lucene...

I can put the same search term into multiple fields and therefore create an "all" field which I put everything in. This way I can create a query like...

field1:"hello" AND all:"world"

This seems to work very nicely, prevents the need for huge search queries, and apparently the performance impact is minimal.

Related Topic