7

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?

rae1
  • 6,066
  • 4
  • 27
  • 48
Edd
  • 8,402
  • 14
  • 47
  • 73

3 Answers3

7

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.

Community
  • 1
  • 1
Edd
  • 8,402
  • 14
  • 47
  • 73
2

Boolean (OR) queries with a clause for each field are used to search multiple fields. The MultiFieldQueryParser will do that as well, but the fields still need to be enumerated. There's no implicit "all" fields; but IndexReader.getFieldNames can acquire them.

A. Coady
  • 54,452
  • 8
  • 34
  • 40
  • I've created an explicit "all" field... it doesn't seem ideal but every time I create a field I also add to the "all" field. It works but seems a bit rubbish. Really what I'd like to do is define multiple names for each indexed field so I can create categories or be able to search fields using wildcard characters in the field names so I could search "name*" for "name.firstname:bob" – Edd Nov 29 '11 at 12:17
0

This might not apply to you, but in Azure Search, which is based on Lucene, using Lucene syntax, I use this:

name:plywood^100 OR plywood

Results with "plywood" in the "name" field are boosted.