lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergiu Gordea <>
Subject Re: Having common word in the search
Date Mon, 02 Aug 2004 08:10:37 GMT
I have the same problem. Right now I think is not possible to do what 
you want by using MultifieldQueryParser.
Right now I iplemented a query normalization for our product, but I 
consider that the best way is to take the source code
and to implement:

Query q = MultiFieldQueryParser.parse(line,fields,analyzer, operator);

where operator can be  AND / OR

Another solution may be to Forget  about  MultifieldQueryParser, and to 
create an compose the correct
query parser with QueryParser and BooleanQueries.

MultifieldQueryParser failes in the case you search in two fileds for +a 
+b, because it requires that both terms to be in on of the fields.
A bigger problem is in the case you want to search for "a AND NOT b" in 
two fields. Because these error is instantly observed by users.
In the first case +a +b you will get less results then the correct one.
In teh second case you will get more results (correct ones + wrong ones).

There was a disscusion on this topic. Please search the mail archive.

  All the best,


lingaraju wrote:

>Dear  All
>Searcher searcher = new IndexSearcher("C:/index");
>Analyzer analyzer = new StandardAnalyzer();
>String line="curry asia";  
>String fields[] = new String[2];
>fields[0] = "title";
>fields[1] = "contents";
>Query q = MultiFieldQueryParser.parse(line,fields,analyzer);
>Hits hits1 =;
>In the above code Hits will return the documnet  that contains
>the word 
>1)"Curry OR asia OR recipe"
>2)"Curry OR asia AND recipe"
>3)"Curry AND asia AND recipe"
>4)"Curry AND asia OR recipe"
>But I want the result should be
>Like this 
>1)"Curry AND asia AND recipe"
>2)("Curry OR asia) AND recipe"
>My question is how to give the condition
>Actually my requirement is like this 
>User will enter some text in "text box" it may be one word or two word or n word.(Eg "curry
>but when i am searching i will append "recipe" word in the search string so the search
must contains "recipe"  word.
>Finally search should contains
>1)"Curry AND asia AND recipe"
>2)("Curry OR asia) AND recipe"
>search should not contains
>1)"Curry AND asia OR recipe"
>2)"Curry OR asia OR recipe"
>Thanks and regards

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message