lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Victor Abeytua <>
Subject Re: Multiple field search problem
Date Tue, 26 Apr 2005 08:28:36 GMT
Thanks for the quick reply.
    As I supposed, the answer was right in front of me. To build a query 
as the one I wanted I have to use the BooleanQuery class:

        Term term1 = new Term("field1", "Policy planning");
        Term term2 = new Term("field1", "Newspapers");
        Term term3 = new Term("field2", "Spanish");
        Query query = new TermQuery(term1);
        Query query2 = new TermQuery(term2);
        Query query3 = new TermQuery(term3);
        BooleanQuery bquery = new BooleanQuery ();
        BooleanQuery bquery2 = new BooleanQuery ();
        bquery.add(query, false, false);
        bquery.add(query2, false, false);
        bquery2.add (bquery, true, false);
        bquery2.add (query3, true, false);

Gusenbauer Stefan wrote:

>Victor Abeytua wrote:
>>Hello everyone,
>>   In the project I'm currently involved we are using lucene (+
>>Digester) to index a small number of XML files. To be able to perform
>>the searches I want, I should need to query the index with something
>>similar to (where fieldN are XML tags):
>>(field1:"Policy and planning" OR  field1:Newspapers) AND field2:Spanish
>>   I haven't been able to find any class that suits my needs and if I
>>try to use QueryParse.parse() to be able to write the query in "human"
>>form, the analyzer takes the "and" away and changes the string to
>>lower case. This is something I can't afford as I need to be able to
>>search by the exact keywords.
>>   Any ideas are welcome. Perhaps the answer is right in front of me
>>but I haven't been able to figure it out.
>>   Thanks in advance,
>>   Victor Abeytua
>>To unsubscribe, e-mail:
>>For additional commands, e-mail:
>The lowercasing depends on the analyzer you use perharps you've only put
>them into apostrophs like this " if you instanciate the Queryparser you
>can specifiy which Boolean operand should be used if no operand is
>given. With query.toString() you get the query in an human readable
>format for with + for and and so on.
>To unsubscribe, e-mail:
>For additional commands, e-mail:

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

View raw message