tags:

views:

201

answers:

2

Hi,

I have the following code and would appreciate your advice.

   QueryParser queryParser = new QueryParser(searchTerm, analyzer);
   Query query = queryParser.parse(searchTerm);

My first question is, this "doubled"? As I have the "String to search for (=searchTerm)" in the constructor as well as in the parse() method. Is this really required? (For further usage i need a Query object). If i do it this way, does this maybe even introduce some negative side effects?

And I am not able to specify programatically the "default field" to search for. In my quries I write "content:House" and it searches in the field "content". But how can I specify this programatically that "content:" is my default field and a user only has to enter "House" (and lucene then automatically searches in the "content" field).

thank you so much jan

A: 

as long as i know there is no such option

Trickster
+1  A: 

The first argument to the QueryParser constructor is the default search field, even if the javadoc doesn't make that obvious.

So you want this:

QueryParser queryParser = new QueryParser("content", analyzer);
Query query = queryParser.parse(searchTerm);
skaffman
Hello skaffman. Thanks so much for your help!!! jens
jens