Searching for multiple terms in a field

lucene

I want to do an AND query, say 'foo AND bar', in Lucene.NET. I have a WholeIndex field which has the whole document indexed, and I want Lucene to search in the whole document.
Up to here it's quite easy, but there's a constraint.

I want both terms 'foo' and 'bar' to be in the same field.

Is there an easy way to do this without querying the index for the full list of fields and searching in every field?

Edit: What I want to know is if there is a way to tell Lucene to perform a search in every field, without having to know all the fields in my index. An automated way to search the following:

"field1:(+foo +bar) field2:(+foo +bar) … fieldN:(+foo +bar)"

Best Answer

You can use GetFieldNames to get all the field names, and then go programmatically over the list and generating a query like the one you wrote, using BooleanQuery.

Related Topic