mirror of https://github.com/apache/lucene.git
LUCENE-6834: Removed BoostQuery.toString()'s hack with parenthesis.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1708146 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b3d191832c
commit
876181ff1b
|
@ -18,9 +18,6 @@ package org.apache.lucene.search;
|
|||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -36,23 +33,6 @@ import org.apache.lucene.index.Term;
|
|||
*/
|
||||
public final class BoostQuery extends Query {
|
||||
|
||||
/** By default we enclose the wrapped query within parenthesis, but this is
|
||||
* not required for all queries, so we use a whitelist of queries that don't
|
||||
* need parenthesis to have a better toString(). */
|
||||
private static final Set<Class<? extends Query>> NO_PARENS_REQUIRED_QUERIES = Collections.unmodifiableSet(
|
||||
new HashSet<>(Arrays.asList(
|
||||
TermQuery.class,
|
||||
PhraseQuery.class,
|
||||
MultiPhraseQuery.class,
|
||||
ConstantScoreQuery.class,
|
||||
TermRangeQuery.class,
|
||||
NumericRangeQuery.class,
|
||||
PrefixQuery.class,
|
||||
FuzzyQuery.class,
|
||||
WildcardQuery.class,
|
||||
RegexpQuery.class
|
||||
)));
|
||||
|
||||
private final Query query;
|
||||
private final float boost;
|
||||
|
||||
|
@ -122,15 +102,10 @@ public final class BoostQuery extends Query {
|
|||
|
||||
@Override
|
||||
public String toString(String field) {
|
||||
boolean needsParens = NO_PARENS_REQUIRED_QUERIES.contains(query.getClass()) == false;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (needsParens) {
|
||||
builder.append("(");
|
||||
}
|
||||
builder.append("(");
|
||||
builder.append(query.toString(field));
|
||||
if (needsParens) {
|
||||
builder.append(")");
|
||||
}
|
||||
builder.append(")");
|
||||
builder.append("^");
|
||||
builder.append(boost);
|
||||
return builder.toString();
|
||||
|
|
|
@ -18,9 +18,6 @@ package org.apache.lucene.search.spans;
|
|||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@ -41,21 +38,6 @@ import org.apache.lucene.search.Scorer;
|
|||
*/
|
||||
public final class SpanBoostQuery extends SpanQuery {
|
||||
|
||||
/** By default we enclose the wrapped query within parenthesis, but this is
|
||||
* not required for all queries, so we use a whitelist of queries that don't
|
||||
* need parenthesis to have a better toString(). */
|
||||
private static final Set<Class<? extends SpanQuery>> NO_PARENS_REQUIRED_QUERIES = Collections.unmodifiableSet(
|
||||
new HashSet<>(Arrays.asList(
|
||||
SpanTermQuery.class,
|
||||
SpanNearQuery.class,
|
||||
SpanOrQuery.class,
|
||||
SpanFirstQuery.class,
|
||||
SpanContainingQuery.class,
|
||||
SpanContainQuery.class,
|
||||
SpanNotQuery.class,
|
||||
SpanWithinQuery.class
|
||||
)));
|
||||
|
||||
private final SpanQuery query;
|
||||
private final float boost;
|
||||
|
||||
|
@ -119,16 +101,10 @@ public final class SpanBoostQuery extends SpanQuery {
|
|||
|
||||
@Override
|
||||
public String toString(String field) {
|
||||
boolean needsParens = NO_PARENS_REQUIRED_QUERIES.contains(query.getClass()) == false;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (needsParens) {
|
||||
builder.append("(");
|
||||
}
|
||||
builder.append("(");
|
||||
builder.append(query.toString(field));
|
||||
if (needsParens) {
|
||||
builder.append(")");
|
||||
}
|
||||
builder.append("^");
|
||||
builder.append(")^");
|
||||
builder.append(boost);
|
||||
return builder.toString();
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class TestBlendedTermQuery extends LuceneTestCase {
|
|||
assertEquals("Blended(foo:bar)", new BlendedTermQuery.Builder().add(t1).build().toString());
|
||||
Term t2 = new Term("foo", "baz");
|
||||
assertEquals("Blended(foo:bar foo:baz)", new BlendedTermQuery.Builder().add(t1).add(t2).build().toString());
|
||||
assertEquals("Blended(foo:bar^4.0 foo:baz^3.0)", new BlendedTermQuery.Builder().add(t1, 4).add(t2, 3).build().toString());
|
||||
assertEquals("Blended((foo:bar)^4.0 (foo:baz)^3.0)", new BlendedTermQuery.Builder().add(t1, 4).add(t2, 3).build().toString());
|
||||
}
|
||||
|
||||
public void testBlendedScores() throws IOException {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TestBoostQuery extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testToString() {
|
||||
assertEquals("foo:bar^2.0", new BoostQuery(new TermQuery(new Term("foo", "bar")), 2).toString());
|
||||
assertEquals("(foo:bar)^2.0", new BoostQuery(new TermQuery(new Term("foo", "bar")), 2).toString());
|
||||
BooleanQuery bq = new BooleanQuery.Builder()
|
||||
.add(new TermQuery(new Term("foo", "bar")), Occur.SHOULD)
|
||||
.add(new TermQuery(new Term("foo", "baz")), Occur.SHOULD)
|
||||
|
|
|
@ -40,11 +40,11 @@ public class TestSpanBoostQuery extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testToString() {
|
||||
assertEquals("foo:bar^2.0", new SpanBoostQuery(new SpanTermQuery(new Term("foo", "bar")), 2).toString());
|
||||
assertEquals("(foo:bar)^2.0", new SpanBoostQuery(new SpanTermQuery(new Term("foo", "bar")), 2).toString());
|
||||
SpanOrQuery bq = new SpanOrQuery(
|
||||
new SpanTermQuery(new Term("foo", "bar")),
|
||||
new SpanTermQuery(new Term("foo", "baz")));
|
||||
assertEquals("spanOr([foo:bar, foo:baz])^2.0", new SpanBoostQuery(bq, 2).toString());
|
||||
assertEquals("(spanOr([foo:bar, foo:baz]))^2.0", new SpanBoostQuery(bq, 2).toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class TestMultiAnalyzer extends BaseTokenStreamTestCase {
|
|||
assertEquals("\"(multi multi2) foo\"~10", qp.parse("\"multi foo\"~10").toString());
|
||||
|
||||
// phrase with non-default boost:
|
||||
assertEquals("\"(multi multi2) foo\"^2.0", qp.parse("\"multi foo\"^2").toString());
|
||||
assertEquals("(\"(multi multi2) foo\")^2.0", qp.parse("\"multi foo\"^2").toString());
|
||||
|
||||
// phrase after changing default slop
|
||||
qp.setPhraseSlop(99);
|
||||
|
|
|
@ -141,22 +141,22 @@ public class TestMultiFieldQueryParser extends LuceneTestCase {
|
|||
|
||||
//Check for simple
|
||||
Query q = mfqp.parse("one");
|
||||
assertEquals("b:one^5.0 t:one^10.0", q.toString());
|
||||
assertEquals("(b:one)^5.0 (t:one)^10.0", q.toString());
|
||||
|
||||
//Check for AND
|
||||
q = mfqp.parse("one AND two");
|
||||
assertEquals("+(b:one^5.0 t:one^10.0) +(b:two^5.0 t:two^10.0)", q.toString());
|
||||
assertEquals("+((b:one)^5.0 (t:one)^10.0) +((b:two)^5.0 (t:two)^10.0)", q.toString());
|
||||
|
||||
//Check for OR
|
||||
q = mfqp.parse("one OR two");
|
||||
assertEquals("(b:one^5.0 t:one^10.0) (b:two^5.0 t:two^10.0)", q.toString());
|
||||
assertEquals("((b:one)^5.0 (t:one)^10.0) ((b:two)^5.0 (t:two)^10.0)", q.toString());
|
||||
|
||||
//Check for AND and a field
|
||||
q = mfqp.parse("one AND two AND foo:test");
|
||||
assertEquals("+(b:one^5.0 t:one^10.0) +(b:two^5.0 t:two^10.0) +foo:test", q.toString());
|
||||
assertEquals("+((b:one)^5.0 (t:one)^10.0) +((b:two)^5.0 (t:two)^10.0) +foo:test", q.toString());
|
||||
|
||||
q = mfqp.parse("one^3 AND two^4");
|
||||
assertEquals("+(b:one^5.0 t:one^10.0)^3.0 +(b:two^5.0 t:two^10.0)^4.0", q.toString());
|
||||
assertEquals("+((b:one)^5.0 (t:one)^10.0)^3.0 +((b:two)^5.0 (t:two)^10.0)^4.0", q.toString());
|
||||
}
|
||||
|
||||
public void testStaticMethod1() throws ParseException {
|
||||
|
|
|
@ -237,13 +237,13 @@ public class TestPrecedenceQueryParser extends LuceneTestCase {
|
|||
assertTrue(getQuery("hello", null) instanceof TermQuery);
|
||||
assertTrue(getQuery("\"hello there\"", null) instanceof PhraseQuery);
|
||||
|
||||
assertQueryEquals("germ term^2.0", null, "germ term^2.0");
|
||||
assertQueryEquals("(term)^2.0", null, "term^2.0");
|
||||
assertQueryEquals("germ term^2.0", null, "germ (term)^2.0");
|
||||
assertQueryEquals("(term)^2.0", null, "(term)^2.0");
|
||||
assertQueryEquals("(germ term)^2.0", null, "(germ term)^2.0");
|
||||
assertQueryEquals("term^2.0", null, "term^2.0");
|
||||
assertQueryEquals("term^2", null, "term^2.0");
|
||||
assertQueryEquals("\"germ term\"^2.0", null, "\"germ term\"^2.0");
|
||||
assertQueryEquals("\"term germ\"^2", null, "\"term germ\"^2.0");
|
||||
assertQueryEquals("term^2.0", null, "(term)^2.0");
|
||||
assertQueryEquals("term^2", null, "(term)^2.0");
|
||||
assertQueryEquals("\"germ term\"^2.0", null, "(\"germ term\")^2.0");
|
||||
assertQueryEquals("\"term germ\"^2", null, "(\"term germ\")^2.0");
|
||||
|
||||
assertQueryEquals("(foo OR bar) AND (baz OR boo)", null,
|
||||
"+(foo bar) +(baz boo)");
|
||||
|
@ -279,7 +279,7 @@ public class TestPrecedenceQueryParser extends LuceneTestCase {
|
|||
assertQueryEquals("\"term germ\"~2 flork", null, "\"term germ\"~2 flork");
|
||||
assertQueryEquals("\"term\"~2", null, "term");
|
||||
assertQueryEquals("\" \"~2 germ", null, "germ");
|
||||
assertQueryEquals("\"term germ\"~2^2", null, "\"term germ\"~2^2.0");
|
||||
assertQueryEquals("\"term germ\"~2^2", null, "(\"term germ\"~2)^2.0");
|
||||
}
|
||||
|
||||
public void testNumber() throws Exception {
|
||||
|
@ -296,13 +296,13 @@ public class TestPrecedenceQueryParser extends LuceneTestCase {
|
|||
|
||||
public void testWildcard() throws Exception {
|
||||
assertQueryEquals("term*", null, "term*");
|
||||
assertQueryEquals("term*^2", null, "term*^2.0");
|
||||
assertQueryEquals("term*^2", null, "(term*)^2.0");
|
||||
assertQueryEquals("term~", null, "term~2");
|
||||
assertQueryEquals("term~0.7", null, "term~1");
|
||||
assertQueryEquals("term~^3", null, "term~2^3.0");
|
||||
assertQueryEquals("term^3~", null, "term~2^3.0");
|
||||
assertQueryEquals("term~^3", null, "(term~2)^3.0");
|
||||
assertQueryEquals("term^3~", null, "(term~2)^3.0");
|
||||
assertQueryEquals("term*germ", null, "term*germ");
|
||||
assertQueryEquals("term*germ^3", null, "term*germ^3.0");
|
||||
assertQueryEquals("term*germ^3", null, "(term*germ)^3.0");
|
||||
|
||||
assertTrue(getQuery("term*", null) instanceof PrefixQuery);
|
||||
assertTrue(getQuery("term*^2", null) instanceof BoostQuery);
|
||||
|
@ -384,7 +384,7 @@ public class TestPrecedenceQueryParser extends LuceneTestCase {
|
|||
assertQueryEquals("[ a TO z ]", null, "[a TO z]");
|
||||
assertQueryEquals("{ a TO z}", null, "{a TO z}");
|
||||
assertQueryEquals("{ a TO z }", null, "{a TO z}");
|
||||
assertQueryEquals("{ a TO z }^2.0", null, "{a TO z}^2.0");
|
||||
assertQueryEquals("{ a TO z }^2.0", null, "({a TO z})^2.0");
|
||||
assertQueryEquals("[ a TO z] OR bar", null, "[a TO z] bar");
|
||||
assertQueryEquals("[ a TO z] AND bar", null, "+[a TO z] +bar");
|
||||
assertQueryEquals("( bar blar { a TO z}) ", null, "bar blar {a TO z}");
|
||||
|
|
|
@ -89,7 +89,7 @@ public class TestMultiAnalyzerQPHelper extends LuceneTestCase {
|
|||
.toString());
|
||||
|
||||
// phrase with non-default boost:
|
||||
assertEquals("\"(multi multi2) foo\"^2.0", qp.parse("\"multi foo\"^2", "")
|
||||
assertEquals("(\"(multi multi2) foo\")^2.0", qp.parse("\"multi foo\"^2", "")
|
||||
.toString());
|
||||
|
||||
// phrase after changing default slop
|
||||
|
|
|
@ -156,24 +156,24 @@ public class TestMultiFieldQPHelper extends LuceneTestCase {
|
|||
|
||||
// Check for simple
|
||||
Query q = mfqp.parse("one", null);
|
||||
assertEquals("b:one^5.0 t:one^10.0", q.toString());
|
||||
assertEquals("(b:one)^5.0 (t:one)^10.0", q.toString());
|
||||
|
||||
// Check for AND
|
||||
q = mfqp.parse("one AND two", null);
|
||||
assertEquals("+(b:one^5.0 t:one^10.0) +(b:two^5.0 t:two^10.0)", q
|
||||
assertEquals("+((b:one)^5.0 (t:one)^10.0) +((b:two)^5.0 (t:two)^10.0)", q
|
||||
.toString());
|
||||
|
||||
// Check for OR
|
||||
q = mfqp.parse("one OR two", null);
|
||||
assertEquals("(b:one^5.0 t:one^10.0) (b:two^5.0 t:two^10.0)", q.toString());
|
||||
assertEquals("((b:one)^5.0 (t:one)^10.0) ((b:two)^5.0 (t:two)^10.0)", q.toString());
|
||||
|
||||
// Check for AND and a field
|
||||
q = mfqp.parse("one AND two AND foo:test", null);
|
||||
assertEquals("+(b:one^5.0 t:one^10.0) +(b:two^5.0 t:two^10.0) +foo:test", q
|
||||
assertEquals("+((b:one)^5.0 (t:one)^10.0) +((b:two)^5.0 (t:two)^10.0) +foo:test", q
|
||||
.toString());
|
||||
|
||||
q = mfqp.parse("one^3 AND two^4", null);
|
||||
assertEquals("+(b:one^5.0 t:one^10.0)^3.0 +(b:two^5.0 t:two^10.0)^4.0",
|
||||
assertEquals("+((b:one)^5.0 (t:one)^10.0)^3.0 +((b:two)^5.0 (t:two)^10.0)^4.0",
|
||||
q.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -478,13 +478,13 @@ public class TestQPHelper extends LuceneTestCase {
|
|||
assertTrue(getQuery("hello", null) instanceof TermQuery);
|
||||
assertTrue(getQuery("\"hello there\"", null) instanceof PhraseQuery);
|
||||
|
||||
assertQueryEquals("germ term^2.0", null, "germ term^2.0");
|
||||
assertQueryEquals("(term)^2.0", null, "term^2.0");
|
||||
assertQueryEquals("germ term^2.0", null, "germ (term)^2.0");
|
||||
assertQueryEquals("(term)^2.0", null, "(term)^2.0");
|
||||
assertQueryEquals("(germ term)^2.0", null, "(germ term)^2.0");
|
||||
assertQueryEquals("term^2.0", null, "term^2.0");
|
||||
assertQueryEquals("term^2", null, "term^2.0");
|
||||
assertQueryEquals("\"germ term\"^2.0", null, "\"germ term\"^2.0");
|
||||
assertQueryEquals("\"term germ\"^2", null, "\"term germ\"^2.0");
|
||||
assertQueryEquals("term^2.0", null, "(term)^2.0");
|
||||
assertQueryEquals("term^2", null, "(term)^2.0");
|
||||
assertQueryEquals("\"germ term\"^2.0", null, "(\"germ term\")^2.0");
|
||||
assertQueryEquals("\"term germ\"^2", null, "(\"term germ\")^2.0");
|
||||
|
||||
assertQueryEquals("(foo OR bar) AND (baz OR boo)", null,
|
||||
"+(foo bar) +(baz boo)");
|
||||
|
@ -518,7 +518,7 @@ public class TestQPHelper extends LuceneTestCase {
|
|||
assertQueryEquals("\"term germ\"~2 flork", null, "\"term germ\"~2 flork");
|
||||
assertQueryEquals("\"term\"~2", null, "term");
|
||||
assertQueryEquals("\" \"~2 germ", null, "germ");
|
||||
assertQueryEquals("\"term germ\"~2^2", null, "\"term germ\"~2^2.0");
|
||||
assertQueryEquals("\"term germ\"~2^2", null, "(\"term germ\"~2)^2.0");
|
||||
}
|
||||
|
||||
public void testNumber() throws Exception {
|
||||
|
@ -541,15 +541,15 @@ public class TestQPHelper extends LuceneTestCase {
|
|||
|
||||
public void testWildcard() throws Exception {
|
||||
assertQueryEquals("term*", null, "term*");
|
||||
assertQueryEquals("term*^2", null, "term*^2.0");
|
||||
assertQueryEquals("term*^2", null, "(term*)^2.0");
|
||||
assertQueryEquals("term~", null, "term~2");
|
||||
assertQueryEquals("term~0.7", null, "term~1");
|
||||
|
||||
assertQueryEquals("term~^3", null, "term~2^3.0");
|
||||
assertQueryEquals("term~^3", null, "(term~2)^3.0");
|
||||
|
||||
assertQueryEquals("term^3~", null, "term~2^3.0");
|
||||
assertQueryEquals("term^3~", null, "(term~2)^3.0");
|
||||
assertQueryEquals("term*germ", null, "term*germ");
|
||||
assertQueryEquals("term*germ^3", null, "term*germ^3.0");
|
||||
assertQueryEquals("term*germ^3", null, "(term*germ)^3.0");
|
||||
|
||||
assertTrue(getQuery("term*", null) instanceof PrefixQuery);
|
||||
assertTrue(getQuery("term*^2", null) instanceof BoostQuery);
|
||||
|
@ -635,7 +635,7 @@ public class TestQPHelper extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testQPA() throws Exception {
|
||||
assertQueryEquals("term term^3.0 term", qpAnalyzer, "term term^3.0 term");
|
||||
assertQueryEquals("term term^3.0 term", qpAnalyzer, "term (term)^3.0 term");
|
||||
assertQueryEquals("term stop^3.0 term", qpAnalyzer, "term term");
|
||||
|
||||
assertQueryEquals("term term term", qpAnalyzer, "term term term");
|
||||
|
@ -693,7 +693,7 @@ public class TestQPHelper extends LuceneTestCase {
|
|||
assertQueryEquals("[ a TO z ]", null, "[a TO z]");
|
||||
assertQueryEquals("{ a TO z}", null, "{a TO z}");
|
||||
assertQueryEquals("{ a TO z }", null, "{a TO z}");
|
||||
assertQueryEquals("{ a TO z }^2.0", null, "{a TO z}^2.0");
|
||||
assertQueryEquals("{ a TO z }^2.0", null, "({a TO z})^2.0");
|
||||
assertQueryEquals("[ a TO z] OR bar", null, "[a TO z] bar");
|
||||
assertQueryEquals("[ a TO z] AND bar", null, "+[a TO z] +bar");
|
||||
assertQueryEquals("( bar blar { a TO z}) ", null, "bar blar {a TO z}");
|
||||
|
|
|
@ -368,13 +368,13 @@ public abstract class QueryParserTestBase extends LuceneTestCase {
|
|||
assertTrue(getQuery("hello") instanceof TermQuery);
|
||||
assertTrue(getQuery("\"hello there\"") instanceof PhraseQuery);
|
||||
|
||||
assertQueryEquals("germ term^2.0", null, "germ term^2.0");
|
||||
assertQueryEquals("(term)^2.0", null, "term^2.0");
|
||||
assertQueryEquals("germ term^2.0", null, "germ (term)^2.0");
|
||||
assertQueryEquals("(term)^2.0", null, "(term)^2.0");
|
||||
assertQueryEquals("(germ term)^2.0", null, "(germ term)^2.0");
|
||||
assertQueryEquals("term^2.0", null, "term^2.0");
|
||||
assertQueryEquals("term^2", null, "term^2.0");
|
||||
assertQueryEquals("\"germ term\"^2.0", null, "\"germ term\"^2.0");
|
||||
assertQueryEquals("\"term germ\"^2", null, "\"term germ\"^2.0");
|
||||
assertQueryEquals("term^2.0", null, "(term)^2.0");
|
||||
assertQueryEquals("term^2", null, "(term)^2.0");
|
||||
assertQueryEquals("\"germ term\"^2.0", null, "(\"germ term\")^2.0");
|
||||
assertQueryEquals("\"term germ\"^2", null, "(\"term germ\")^2.0");
|
||||
|
||||
assertQueryEquals("(foo OR bar) AND (baz OR boo)", null,
|
||||
"+(foo bar) +(baz boo)");
|
||||
|
@ -415,7 +415,7 @@ public abstract class QueryParserTestBase extends LuceneTestCase {
|
|||
assertQueryEquals("\"term germ\"~2 flork", null, "\"term germ\"~2 flork");
|
||||
assertQueryEquals("\"term\"~2", null, "term");
|
||||
assertQueryEquals("\" \"~2 germ", null, "germ");
|
||||
assertQueryEquals("\"term germ\"~2^2", null, "\"term germ\"~2^2.0");
|
||||
assertQueryEquals("\"term germ\"~2^2", null, "(\"term germ\"~2)^2.0");
|
||||
}
|
||||
|
||||
public void testNumber() throws Exception {
|
||||
|
@ -432,14 +432,14 @@ public abstract class QueryParserTestBase extends LuceneTestCase {
|
|||
|
||||
public void testWildcard() throws Exception {
|
||||
assertQueryEquals("term*", null, "term*");
|
||||
assertQueryEquals("term*^2", null, "term*^2.0");
|
||||
assertQueryEquals("term*^2", null, "(term*)^2.0");
|
||||
assertQueryEquals("term~", null, "term~2");
|
||||
assertQueryEquals("term~1", null, "term~1");
|
||||
assertQueryEquals("term~0.7", null, "term~1");
|
||||
assertQueryEquals("term~^3", null, "term~2^3.0");
|
||||
assertQueryEquals("term^3~", null, "term~2^3.0");
|
||||
assertQueryEquals("term~^3", null, "(term~2)^3.0");
|
||||
assertQueryEquals("term^3~", null, "(term~2)^3.0");
|
||||
assertQueryEquals("term*germ", null, "term*germ");
|
||||
assertQueryEquals("term*germ^3", null, "term*germ^3.0");
|
||||
assertQueryEquals("term*germ^3", null, "(term*germ)^3.0");
|
||||
|
||||
assertTrue(getQuery("term*") instanceof PrefixQuery);
|
||||
assertTrue(getQuery("term*^2") instanceof BoostQuery);
|
||||
|
@ -524,7 +524,7 @@ public abstract class QueryParserTestBase extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testQPA() throws Exception {
|
||||
assertQueryEquals("term term^3.0 term", qpAnalyzer, "term term^3.0 term");
|
||||
assertQueryEquals("term term^3.0 term", qpAnalyzer, "term (term)^3.0 term");
|
||||
assertQueryEquals("term stop^3.0 term", qpAnalyzer, "term term");
|
||||
|
||||
assertQueryEquals("term term term", qpAnalyzer, "term term term");
|
||||
|
@ -585,7 +585,7 @@ public abstract class QueryParserTestBase extends LuceneTestCase {
|
|||
assertQueryEquals("[ a TO z ]", null, "[a TO z]");
|
||||
assertQueryEquals("{ a TO z}", null, "{a TO z}");
|
||||
assertQueryEquals("{ a TO z }", null, "{a TO z}");
|
||||
assertQueryEquals("{ a TO z }^2.0", null, "{a TO z}^2.0");
|
||||
assertQueryEquals("{ a TO z }^2.0", null, "({a TO z})^2.0");
|
||||
assertQueryEquals("[ a TO z] OR bar", null, "[a TO z] bar");
|
||||
assertQueryEquals("[ a TO z] AND bar", null, "+[a TO z] +bar");
|
||||
assertQueryEquals("( bar blar { a TO z}) ", null, "bar blar {a TO z}");
|
||||
|
|
|
@ -517,13 +517,13 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
|
|||
"//str[@name='parsedquery_toString'][.='+id:42']");
|
||||
|
||||
assertQ(req("defType","edismax", "debugQuery","true", "rows","0", "uf","*^5.0", "q","id:42"),
|
||||
"//str[@name='parsedquery_toString'][.='+id:42^5.0']");
|
||||
"//str[@name='parsedquery_toString'][.='+(id:42)^5.0']");
|
||||
|
||||
assertQ(req("defType","edismax", "debugQuery","true", "rows","0", "uf","*^2.0 id^5.0 -xyz", "q","name:foo"),
|
||||
"//str[@name='parsedquery_toString'][.='+name:foo^2.0']");
|
||||
"//str[@name='parsedquery_toString'][.='+(name:foo)^2.0']");
|
||||
|
||||
assertQ(req("defType","edismax", "debugQuery","true", "rows","0", "uf","i*^5.0", "q","id:42"),
|
||||
"//str[@name='parsedquery_toString'][.='+id:42^5.0']");
|
||||
"//str[@name='parsedquery_toString'][.='+(id:42)^5.0']");
|
||||
|
||||
|
||||
assertQ(req("defType","edismax", "uf","-*", "q","cannons"),
|
||||
|
@ -754,19 +754,19 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
|
|||
"ps", "3",
|
||||
"defType", "edismax",
|
||||
"debugQuery", "true"),
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx cccc vvvv\"~1^10.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx cccc vvvv\"~2^20.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx cccc vvvv\"~3^30.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx\"~2^22.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"xxxx cccc\"~2^22.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"cccc vvvv\"~2^22.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx\"~3^33.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"xxxx cccc\"~3^33.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"cccc vvvv\"~3^33.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx cccc\"~2^222.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"xxxx cccc vvvv\"~2^222.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx cccc\"~3^333.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"xxxx cccc vvvv\"~3^333.0')]"
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"zzzz xxxx cccc vvvv\"~1)^10.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"zzzz xxxx cccc vvvv\"~2)^20.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"zzzz xxxx cccc vvvv\"~3)^30.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"zzzz xxxx\"~2)^22.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"xxxx cccc\"~2)^22.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"cccc vvvv\"~2)^22.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"zzzz xxxx\"~3)^33.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"xxxx cccc\"~3)^33.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"cccc vvvv\"~3)^33.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"zzzz xxxx cccc\"~2)^222.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"xxxx cccc vvvv\"~2)^222.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"zzzz xxxx cccc\"~3)^333.0')]",
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"xxxx cccc vvvv\"~3)^333.0')]"
|
||||
);
|
||||
|
||||
assertQ(
|
||||
|
@ -806,7 +806,7 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
|
|||
"ps2", "4",
|
||||
"defType", "edismax",
|
||||
"debugQuery", "true"),
|
||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx\"~2^22.0')]"
|
||||
"//str[@name='parsedquery'][contains(.,'(phrase_sw:\"zzzz xxxx\"~2)^22.0')]"
|
||||
);
|
||||
|
||||
assertQ("phrase field queries spanning multiple fields should be within their own dismax queries",
|
||||
|
|
|
@ -155,14 +155,14 @@ public class TestSolrQueryParser extends SolrTestCaseJ4 {
|
|||
assertJQ(req("fq","id:1", "fl","id,score", "q", subqq+"^3", "qq","text:x^2"
|
||||
, "debug","query"
|
||||
)
|
||||
,"/debug/parsedquery_toString=='(text:x^2.0)^3.0'"
|
||||
,"/debug/parsedquery_toString=='((text:x)^2.0)^3.0'"
|
||||
);
|
||||
|
||||
// boost should multiply
|
||||
assertJQ(req("fq","id:1", "fl","id,score", "q", " {!v=$qq}^3", "qq","text:x^2"
|
||||
, "debug","query"
|
||||
)
|
||||
,"/debug/parsedquery_toString=='(text:x^2.0)^3.0'"
|
||||
,"/debug/parsedquery_toString=='((text:x)^2.0)^3.0'"
|
||||
);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue