mirror of https://github.com/apache/lucene.git
LUCENE-3542: Group expanded query terms to preserve parent boolean operator in StandardQueryParser
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1195275 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
55ad4c6be1
commit
a4794c135b
|
@ -139,6 +139,9 @@ Bug Fixes
|
||||||
* LUCENE-3508: Decompounders based on CompoundWordTokenFilterBase can now be
|
* LUCENE-3508: Decompounders based on CompoundWordTokenFilterBase can now be
|
||||||
used with custom attributes. All those attributes are preserved and set on all
|
used with custom attributes. All those attributes are preserved and set on all
|
||||||
added decompounded tokens. (Spyros Kapnissis, Uwe Schindler)
|
added decompounded tokens. (Spyros Kapnissis, Uwe Schindler)
|
||||||
|
|
||||||
|
* LUCENE-3542: Group expanded query terms to preserve parent boolean operator
|
||||||
|
in StandartQueryParser. (Simon Willnauer)
|
||||||
|
|
||||||
API Changes
|
API Changes
|
||||||
|
|
||||||
|
|
|
@ -203,12 +203,8 @@ public class AnalyzerQueryNodeProcessor extends QueryNodeProcessorImpl {
|
||||||
children.add(new FieldQueryNode(field, term, -1, -1));
|
children.add(new FieldQueryNode(field, term, -1, -1));
|
||||||
|
|
||||||
}
|
}
|
||||||
if (positionCount == 1)
|
return new GroupQueryNode(
|
||||||
return new GroupQueryNode(
|
new StandardBooleanQueryNode(children, positionCount==1));
|
||||||
new StandardBooleanQueryNode(children, true));
|
|
||||||
else
|
|
||||||
return new StandardBooleanQueryNode(children, false);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// phrase query:
|
// phrase query:
|
||||||
MultiPhraseQueryNode mpq = new MultiPhraseQueryNode();
|
MultiPhraseQueryNode mpq = new MultiPhraseQueryNode();
|
||||||
|
|
|
@ -359,8 +359,16 @@ public class TestQPHelper extends LuceneTestCase {
|
||||||
BooleanQuery expected = new BooleanQuery();
|
BooleanQuery expected = new BooleanQuery();
|
||||||
expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.SHOULD);
|
expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.SHOULD);
|
||||||
expected.add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
|
expected.add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
|
||||||
|
|
||||||
assertEquals(expected, getQuery("中国", analyzer));
|
assertEquals(expected, getQuery("中国", analyzer));
|
||||||
|
|
||||||
|
expected = new BooleanQuery();
|
||||||
|
expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.MUST);
|
||||||
|
BooleanQuery inner = new BooleanQuery();
|
||||||
|
inner.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.SHOULD);
|
||||||
|
inner.add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
|
||||||
|
expected.add(inner, BooleanClause.Occur.MUST);
|
||||||
|
assertEquals(expected, getQuery("中 AND 中国", new SimpleCJKAnalyzer()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCJKBoostedTerm() throws Exception {
|
public void testCJKBoostedTerm() throws Exception {
|
||||||
|
@ -609,7 +617,7 @@ public class TestQPHelper extends LuceneTestCase {
|
||||||
|
|
||||||
assertQueryEquals("drop AND stop AND roll", qpAnalyzer, "+drop +roll");
|
assertQueryEquals("drop AND stop AND roll", qpAnalyzer, "+drop +roll");
|
||||||
assertQueryEquals("term phrase term", qpAnalyzer,
|
assertQueryEquals("term phrase term", qpAnalyzer,
|
||||||
"term phrase1 phrase2 term");
|
"term (phrase1 phrase2) term");
|
||||||
|
|
||||||
assertQueryEquals("term AND NOT phrase term", qpAnalyzer,
|
assertQueryEquals("term AND NOT phrase term", qpAnalyzer,
|
||||||
"+term -(phrase1 phrase2) term");
|
"+term -(phrase1 phrase2) term");
|
||||||
|
|
Loading…
Reference in New Issue