Search in sources :

Example 16 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.

the class TestRandomFaceting method getIndexSortedAllFacetValues.

private String getIndexSortedAllFacetValues(ModifiableSolrParams in, List<String> methods) throws Exception {
    ModifiableSolrParams params = new ModifiableSolrParams(in);
    params.set("facet.sort", "index");
    String goodOldMethod = methods.get(random().nextInt(methods.size()));
    params.set("facet.method", goodOldMethod);
    params.set("facet.exists", "false");
    if (random().nextBoolean()) {
        params.remove("facet.exists");
    }
    params.set("facet.limit", -1);
    params.set("facet.offset", 0);
    final String query;
    SolrQueryRequest req = null;
    try {
        req = req(params);
        query = h.query(req);
    } finally {
        req.close();
    }
    return query;
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 17 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.

the class TestTrie method testTrieFloatRangeSearch.

@Test
public void testTrieFloatRangeSearch() throws Exception {
    for (int i = 0; i < 10; i++) {
        assertU(adoc("id", String.valueOf(i), "tfloat", String.valueOf(i * i * 31.11f)));
    }
    assertU(commit());
    SolrQueryRequest req = req("q", "*:*", "fq", "tfloat:[0 TO 2518.0]");
    assertQ("Range filter must match only 5 documents", req, "//*[@numFound='9']");
    req = req("q", "*:*", "fq", "tfloat:[0 TO *]");
    assertQ("Range filter must match 10 documents", req, "//*[@numFound='10']");
    // Sorting
    assertQ("Sort descending does not work correctly on tfloat fields", req("q", "*:*", "sort", "tfloat desc"), "//*[@numFound='10']", "//float[@name='tfloat'][.='2519.9102']");
    assertQ("Sort ascending does not work correctly on tfloat fields", req("q", "*:*", "sort", "tfloat asc"), "//*[@numFound='10']", "//float[@name='tfloat'][.='0.0']");
    // Function queries
    assertQ("Function queries does not work correctly on tfloat fields", req("q", "_val_:\"sum(tfloat,1.0)\""), "//*[@numFound='10']", "//float[@name='tfloat'][.='2519.9102']");
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Test(org.junit.Test)

Example 18 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.

the class TestTrie method testTrieFacet_PrecisionStep.

@Test
public void testTrieFacet_PrecisionStep() throws Exception {
    // Future protect - assert 0<precisionStep<64
    checkPrecisionSteps("tint");
    checkPrecisionSteps("tfloat");
    checkPrecisionSteps("tdouble");
    checkPrecisionSteps("tlong");
    checkPrecisionSteps("tdate");
    // For tdate tests
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    DateMathParser dmp = new DateMathParser(DateMathParser.UTC);
    for (int i = 0; i < 10; i++) {
        long l = Integer.MAX_VALUE + i * 1L;
        // index 10 days starting with today
        String d = format.format(i == 0 ? dmp.parseMath("/DAY") : dmp.parseMath("/DAY+" + i + "DAYS"));
        assertU(adoc("id", String.valueOf(i), "tint", String.valueOf(i), "tlong", String.valueOf(l), "tfloat", String.valueOf(i * i * 31.11f), "tdouble", String.valueOf(i * 2.33d), "tdate", d));
    }
    for (int i = 0; i < 5; i++) {
        long l = Integer.MAX_VALUE + i * 1L;
        String d = format.format(i == 0 ? dmp.parseMath("/DAY") : dmp.parseMath("/DAY+" + i + "DAYS"));
        assertU(adoc("id", String.valueOf((i + 1) * 10), "tint", String.valueOf(i), "tlong", String.valueOf(l), "tfloat", String.valueOf(i * i * 31.11f), "tdouble", String.valueOf(i * 2.33d), "tdate", d));
    }
    assertU(commit());
    SolrQueryRequest req = req("q", "*:*", "facet", "true", "rows", "15", "facet.field", "tint", "facet.field", "tlong", "facet.field", "tfloat", "facet.field", "tdouble");
    testFacetField(req, "tint", "0", "2");
    testFacetField(req, "tint", "5", "1");
    testFacetField(req, "tlong", String.valueOf(Integer.MAX_VALUE), "2");
    testFacetField(req, "tlong", String.valueOf(Integer.MAX_VALUE + 5L), "1");
    testFacetField(req, "tfloat", String.valueOf(31.11f), "2");
    testFacetField(req, "tfloat", String.valueOf(5 * 5 * 31.11f), "1");
    testFacetField(req, "tdouble", String.valueOf(2.33d), "2");
    testFacetField(req, "tdouble", String.valueOf(5 * 2.33d), "1");
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) DateMathParser(org.apache.solr.util.DateMathParser) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 19 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.

the class TestTrie method testTrieLongRangeSearch.

@Test
public void testTrieLongRangeSearch() throws Exception {
    for (long i = Integer.MAX_VALUE, c = 0; i < (long) Integer.MAX_VALUE + 10l; i++) {
        assertU(adoc("id", String.valueOf(c++), "tlong", String.valueOf(i)));
    }
    assertU(commit());
    String fq = "tlong:[" + Integer.MAX_VALUE + " TO " + (5l + Integer.MAX_VALUE) + "]";
    SolrQueryRequest req = req("q", "*:*", "fq", fq);
    assertQ("Range filter must match only 5 documents", req, "//*[@numFound='6']");
    assertQ("Range filter tlong:[* to *] must match 10 documents", req("q", "*:*", "fq", "tlong:[* TO *]"), "//*[@numFound='10']");
    // Sorting
    assertQ("Sort descending does not work correctly on tlong fields", req("q", "*:*", "sort", "tlong desc"), "//*[@numFound='10']", "//long[@name='tlong'][.='2147483656']");
    assertQ("Sort ascending does not work correctly on tlong fields", req("q", "*:*", "sort", "tlong asc"), "//*[@numFound='10']", "//long[@name='tlong'][.='2147483647']");
    // Function queries
    assertQ("Function queries does not work correctly on tlong fields", req("q", "_val_:\"sum(tlong,1.0)\""), "//*[@numFound='10']", "//long[@name='tlong'][.='2147483656']");
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Test(org.junit.Test)

Example 20 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest 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)362 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)148 Test (org.junit.Test)143 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)129 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)106 SolrCore (org.apache.solr.core.SolrCore)58 ArrayList (java.util.ArrayList)49 NamedList (org.apache.solr.common.util.NamedList)48 SolrInputDocument (org.apache.solr.common.SolrInputDocument)45 HashMap (java.util.HashMap)43 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)37 SolrParams (org.apache.solr.common.params.SolrParams)36 SolrException (org.apache.solr.common.SolrException)34 IOException (java.io.IOException)24 Query (org.apache.lucene.search.Query)24 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 List (java.util.List)23 MapSolrParams (org.apache.solr.common.params.MapSolrParams)23 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)23 Map (java.util.Map)22