lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Brusic <i...@brusic.com>
Subject MultiFieldQueryParser and the NOT operator
Date Mon, 28 Jun 2010 14:54:51 GMT
I inherited some code that does a multi field search based on several form
values.  One field in particular is used by MultiFieldQueryParser.  This
field should be able to support a single "not" query.  The result of the
MultiFieldQueryParser is then appended with other clauses before a search
is actually executed.

// BEGIN CODE

private static String[] multiFieldQueryFields = new String[] {
            "title", "content", "author.name", "source.name"};
            
private static Map multiFieldQueryFieldsBoosts = new HashMap()
{{put("source.name", 0.5f);}};

QueryParser luceneQueryParser = new
MultiFieldQueryParser(multiFieldQueryFields, analyzer,
multiFieldQueryFieldsBoosts);
luceneQueryParser.setDefaultOperator(MultiFieldQueryParser.AND_OPERATOR);
luceneQueryParser.setAllowLeadingWildcard(true);

String escapedKeywords = "not microsoft";
Query luceneQuery = luceneQueryParser.parse(escapedKeywords);

// END CODE

The result is a BooleanQuery with two clauses: one for "not" and one for
"microsoft"

luceneQuery = {org.apache.lucene.search.BooleanQuery@8497}"+(title:not
content:not author.name:not source.name:not^0.5) +(title:microsoft
content:microsoft author.name:microsoft source.name:microsoft^0.5)"

I went through the code and it seems like the issues are with
QueryParse.parse() (technically inside TopLevelQuery and Query).  I know
that Lucene does not support NOT queries with only one term, but am I
correct to expect "not microsoft" to be one clause and not two?  I do think
I have other issues with the AND_OPERATOR, but I am trying to solve the
parsing issue first.

Cheers,

Ivan

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


Mime
View raw message