use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class TestQueryParser method testQPA.
// TODO: Remove this specialization once the flexible standard parser gets multi-word synonym support
@Override
public void testQPA() throws Exception {
boolean oldSplitOnWhitespace = splitOnWhitespace;
splitOnWhitespace = false;
assertQueryEquals("term phrase term", qpAnalyzer, "term phrase1 phrase2 term");
CommonQueryParserConfiguration cqpc = getParserConfig(qpAnalyzer);
setDefaultOperatorAND(cqpc);
assertQueryEquals(cqpc, "field", "term phrase term", "+term +phrase1 +phrase2 +term");
splitOnWhitespace = oldSplitOnWhitespace;
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method assertWildcardQueryEquals.
public void assertWildcardQueryEquals(String query, String result, boolean allowLeadingWildcard) throws Exception {
CommonQueryParserConfiguration cqpC = getParserConfig(null);
cqpC.setAllowLeadingWildcard(allowLeadingWildcard);
Query q = getQuery(query, cqpC);
String s = q.toString("field");
if (!s.equals(result)) {
fail("WildcardQuery /" + query + "/ yielded /" + s + "/, expecting /" + result + "/");
}
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testAutoGeneratePhraseQueriesOn.
public void testAutoGeneratePhraseQueriesOn() throws Exception {
// individual CJK chars as terms
SimpleCJKAnalyzer analyzer = new SimpleCJKAnalyzer();
PhraseQuery expected = new PhraseQuery("field", "中", "国");
CommonQueryParserConfiguration qp = getParserConfig(analyzer);
if (qp instanceof QueryParser) {
// Always true, since TestStandardQP overrides this method
// LUCENE-7533
((QueryParser) qp).setSplitOnWhitespace(true);
}
setAutoGeneratePhraseQueries(qp, true);
assertEquals(expected, getQuery("中国", qp));
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testQPA.
public void testQPA() throws Exception {
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");
assertQueryEquals("term +stop term", qpAnalyzer, "term term");
assertQueryEquals("term -stop term", qpAnalyzer, "term term");
assertQueryEquals("drop AND (stop) AND roll", qpAnalyzer, "+drop +roll");
assertQueryEquals("term +(stop) term", qpAnalyzer, "term term");
assertQueryEquals("term -(stop) term", qpAnalyzer, "term term");
assertQueryEquals("drop AND stop AND roll", qpAnalyzer, "+drop +roll");
// TODO: Re-enable once flexible standard parser gets multi-word synonym support
// assertQueryEquals("term phrase term", qpAnalyzer,
// "term phrase1 phrase2 term");
assertQueryEquals("term AND NOT phrase term", qpAnalyzer, "+term -(phrase1 phrase2) term");
assertMatchNoDocsQuery("stop^3", qpAnalyzer);
assertMatchNoDocsQuery("stop", qpAnalyzer);
assertMatchNoDocsQuery("(stop)^3", qpAnalyzer);
assertMatchNoDocsQuery("((stop))^3", qpAnalyzer);
assertMatchNoDocsQuery("(stop^3)", qpAnalyzer);
assertMatchNoDocsQuery("((stop)^3)", qpAnalyzer);
assertMatchNoDocsQuery("(stop)", qpAnalyzer);
assertMatchNoDocsQuery("((stop))", qpAnalyzer);
assertTrue(getQuery("term term term", qpAnalyzer) instanceof BooleanQuery);
assertTrue(getQuery("term +stop", qpAnalyzer) instanceof TermQuery);
CommonQueryParserConfiguration cqpc = getParserConfig(qpAnalyzer);
setDefaultOperatorAND(cqpc);
// TODO: Re-enable once flexible standard parser gets multi-word synonym support
// assertQueryEquals(cqpc, "field", "term phrase term",
// "+term +phrase1 +phrase2 +term");
assertQueryEquals(cqpc, "field", "phrase", "+phrase1 +phrase2");
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method assertHits.
@SuppressWarnings("unused")
private void assertHits(int expected, String query, IndexSearcher is) throws Exception {
String oldDefaultField = getDefaultField();
setDefaultField("date");
CommonQueryParserConfiguration qp = getParserConfig(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false));
qp.setLocale(Locale.ENGLISH);
Query q = getQuery(query, qp);
ScoreDoc[] hits = is.search(q, 1000).scoreDocs;
assertEquals(expected, hits.length);
setDefaultField(oldDefaultField);
}
Aggregations