views:

1858

answers:

1

I read that Lucene has an internal query language where one specifies : and you make combinations of these using boolean operators. I read all about it on their website and it works just fine in LUKE, I can do things like

field1:value1 AND field2:value2

and it will return seemingly correct results.

My problem is how do I pass this who Lucene query into the API? I've seen QueryParser, but I have to specifiy a field. Does this mean I still have to manually parse my input string, fields, values, parenthesis, etc or is there a way to feed the whole thing in and let lucene do it's thing?

I'm using Lucene.NET but since it's a method by method port of the orignal java, any advice is appreciated.

+3  A: 

Are you asking whether you need to force your user to enter the field? If so, the query parser has a default field. Here's a little more info. As long as you have a default field that will do the job, they don't need to specify fields.

If you're asking how to get a Query object from the String, you need the parse method. It understands about fields, and the default field, etc. mentioned earlier. You just need to make sure that the query parser and the index builder are both using the same analysis.

Hank Gay
Oh, so the field you specify is just a default field in case none is specified?
Matt
If a user searched for "red white blue" then the query that came out of parse would search the default field. If instead they searched for "title:red title:white title:blue" then the query would only look at the title field of the index.
Hank Gay
So yes (sorry, I think I misinterpreted your comment at first).
Hank Gay