Search in sources :

Example 1 with SolrQueryParser

use of org.apache.solr.search.SolrQueryParser in project lucene-solr by apache.

the class TestReversedWildcardFilterFactory method testQueryParsing.

@Test
public void testQueryParsing() throws Exception {
    // add some docs
    assertU(adoc("id", "1", "one", "one"));
    assertU(adoc("id", "2", "two", "two"));
    assertU(adoc("id", "3", "three", "three"));
    assertU(adoc("id", "4", "one", "four"));
    assertU(adoc("id", "5", "two", "five"));
    assertU(adoc("id", "6", "three", "si𝄞x"));
    assertU(commit());
    assertQ("should have matched", req("+id:1 +one:one"), "//result[@numFound=1]");
    assertQ("should have matched", req("+id:4 +one:f*ur"), "//result[@numFound=1]");
    assertQ("should have matched", req("+id:6 +three:*si𝄞x"), "//result[@numFound=1]");
    SolrQueryRequest req = req();
    QParser qparser = QParser.getParser("id:1", req);
    SolrQueryParser parserTwo = new SolrQueryParser(qparser, "two");
    assertTrue(parserTwo.getAllowLeadingWildcard());
    // test conditional reversal
    assertTrue(wasReversed(parserTwo, "*hree"));
    assertTrue(wasReversed(parserTwo, "t*ree"));
    assertTrue(wasReversed(parserTwo, "th*ee"));
    assertFalse(wasReversed(parserTwo, "thr*e"));
    assertTrue(wasReversed(parserTwo, "?hree"));
    assertTrue(wasReversed(parserTwo, "t?ree"));
    assertFalse(wasReversed(parserTwo, "th?ee"));
    assertFalse(wasReversed(parserTwo, "th?*ee"));
    assertFalse(wasReversed(parserTwo, "short*token"));
    assertTrue(wasReversed(parserTwo, "ver*longtoken"));
    req.close();
}
Also used : SolrQueryParser(org.apache.solr.search.SolrQueryParser) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) QParser(org.apache.solr.search.QParser) Test(org.junit.Test)

Aggregations

SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 QParser (org.apache.solr.search.QParser)1 SolrQueryParser (org.apache.solr.search.SolrQueryParser)1 Test (org.junit.Test)1