lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack Krupansky" <>
Subject Re: Searching both phrase and it's words
Date Sat, 30 Jun 2012 21:46:08 GMT
You didn't show us your "luceneQuery", but the gist of the solution is to 
use MUST clauses for each of the individual terms and then a SHOULD of the 
phrase. You can add an additional boost to the phrase, but lucene should 
naturally boost documents containing the phrase.

-- Jack Krupansky

-----Original Message----- 
From: sxam
Sent: Saturday, June 30, 2012 3:55 PM
Subject: Searching both phrase and it's words

Suppose we have a query "balcony table". I want results to be returned by
exact match (first priority) and by single words matching as well (for
"balcony" or for "table"). So currently my solution is:

Analyzer analyzer = new SnowballAnalyzer("English",
            QueryParser contentParser = new QueryParser(Version.LUCENE_29,
"content", analyzer);

            Query phraseContentQuery =

            if (phraseContentQuery is PhraseQuery)

            Query simpleParsedQuery =

            BooleanQuery boolQuery = new BooleanQuery();

            boolQuery.Add(simpleParsedQuery, BooleanClause.Occur.SHOULD);
            boolQuery.Add(phraseContentQuery, BooleanClause.Occur.SHOULD);

            TopDocs docs = searcher.Search(boolQuery, 1500);
            ScoreDoc[] hits = docs.scoreDocs;

Is it the right way?
Is there another way, without running two queries (simpleParsedQuery and



View this message in context:
Sent from the Lucene - Java Users mailing list archive at

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

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

View raw message