Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search across multiple fields in Lucene using Query Syntax?

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?

like image 540
Edd Avatar asked Nov 28 '11 17:11

Edd


1 Answers

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.

like image 149
Edd Avatar answered Sep 17 '22 11:09

Edd