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.booleanqu...@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: [email protected]
For additional commands, e-mail: [email protected]