use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testMatchAllQueryParsing.
public void testMatchAllQueryParsing() throws Exception {
// test simple parsing of MatchAllDocsQuery
String oldDefaultField = getDefaultField();
setDefaultField("key");
CommonQueryParserConfiguration qp = getParserConfig(new MockAnalyzer(random()));
assertEquals(new MatchAllDocsQuery(), getQuery(new MatchAllDocsQuery().toString(), qp));
// test parsing with non-default boost
Query query = new MatchAllDocsQuery();
query = new BoostQuery(query, 2.3f);
assertEquals(query, getQuery(query.toString(), qp));
setDefaultField(oldDefaultField);
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testCollatedRange.
public void testCollatedRange() throws Exception {
CommonQueryParserConfiguration qp = getParserConfig(new MockCollationAnalyzer());
Query expected = TermRangeQuery.newStringRange(getDefaultField(), "collatedabc", "collateddef", true, true);
Query actual = getQuery("[abc TO def]", qp);
assertEquals(expected, actual);
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testBoost.
public void testBoost() throws Exception {
CharacterRunAutomaton stopWords = new CharacterRunAutomaton(Automata.makeString("on"));
Analyzer oneStopAnalyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, stopWords);
CommonQueryParserConfiguration qp = getParserConfig(oneStopAnalyzer);
Query q = getQuery("on^1.0", qp);
assertNotNull(q);
q = getQuery("\"hello\"^2.0", qp);
assertNotNull(q);
assertEquals(((BoostQuery) q).getBoost(), (float) 2.0, (float) 0.5);
q = getQuery("hello^2.0", qp);
assertNotNull(q);
assertEquals(((BoostQuery) q).getBoost(), (float) 2.0, (float) 0.5);
q = getQuery("\"on\"^1.0", qp);
assertNotNull(q);
Analyzer a2 = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET);
CommonQueryParserConfiguration qp2 = getParserConfig(a2);
q = getQuery("the^3", qp2);
// "the" is a stop word so the result is an empty query:
assertNotNull(q);
assertMatchNoDocsQuery(q);
assertFalse(q instanceof BoostQuery);
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testMatchAllDocs.
public void testMatchAllDocs() throws Exception {
CommonQueryParserConfiguration qp = getParserConfig(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false));
assertEquals(new MatchAllDocsQuery(), getQuery("*:*", qp));
assertEquals(new MatchAllDocsQuery(), getQuery("(*:*)", qp));
BooleanQuery bq = (BooleanQuery) getQuery("+*:* -*:*", qp);
assertEquals(2, bq.clauses().size());
for (BooleanClause clause : bq) {
assertTrue(clause.getQuery() instanceof MatchAllDocsQuery);
}
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testRange.
public void testRange() throws Exception {
assertQueryEquals("[ a TO z]", null, "[a TO z]");
assertQueryEquals("[ a TO z}", null, "[a TO z}");
assertQueryEquals("{ a TO z]", null, "{a TO z]");
assertEquals(MultiTermQuery.CONSTANT_SCORE_REWRITE, ((TermRangeQuery) getQuery("[ a TO z]")).getRewriteMethod());
CommonQueryParserConfiguration qp = getParserConfig(new MockAnalyzer(random(), MockTokenizer.SIMPLE, true));
qp.setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_REWRITE);
assertEquals(MultiTermQuery.SCORING_BOOLEAN_REWRITE, ((TermRangeQuery) getQuery("[ a TO z]", qp)).getRewriteMethod());
// test open ranges
assertQueryEquals("[ a TO * ]", null, "[a TO *]");
assertQueryEquals("[ * TO z ]", null, "[* TO z]");
assertQueryEquals("[ * TO * ]", null, "[* TO *]");
// mixing exclude and include bounds
assertQueryEquals("{ a TO z ]", null, "{a TO z]");
assertQueryEquals("[ a TO z }", null, "[a TO z}");
assertQueryEquals("{ a TO * ]", null, "{a TO *]");
assertQueryEquals("[ * TO z }", null, "[* TO z}");
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] 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}");
assertQueryEquals("gack ( bar blar { a TO z}) ", null, "gack (bar blar {a TO z})");
assertQueryEquals("[* TO Z]", null, "[* TO z]");
assertQueryEquals("[A TO *]", null, "[a TO *]");
assertQueryEquals("[* TO *]", null, "[* TO *]");
}
Aggregations