You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by James Berrettini <ji...@jivesoftware.com> on 2003/02/13 18:04:18 UTC

BooleanQuery

I'm having some trouble retrieving data I need from a combined query.

Here's what I'm trying to do: I want to search on several fields of my
documents and then return the best hits. I'm doing something like this:
            org.apache.lucene.search.Query bodyQuery =
                QueryParser.parse(queryString.toLowerCase(), "body",
analyzer);

            org.apache.lucene.search.Query subjectQuery =
                QueryParser.parse(queryString.toLowerCase(), "subject",
analyzer);

            org.apache.lucene.search.Query attachmentsQuery =
                QueryParser.parse(queryString.toLowerCase(),
"attachmentsText", analyzer);

            BooleanQuery bQuery = new BooleanQuery();
            bQuery.add(subjectQuery,false,false);
            bQuery.add(bodyQuery,false,false);
            bQuery.add(attachmentsQuery, false, false);

            Hits hits = searcher.search(comboQuery);

All well and good. But when I'm displaying the results, I want to know which
fields were responsible for the hit. It doesn't seem like this is something
that is available within in the hit. One option is to search again in all
hits for the field where this occurred. That doesn't seem efficient. Another
is to conduct several queries, but then merging the results becomes a little
problematic. Any recommendations of which way to go?

Jim


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org