Search in sources :

Example 36 with LocalSolrQueryRequest

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

the class StatsComponentTest method testFieldStatisticsResultsNumericFieldAlwaysMissing.

public void testFieldStatisticsResultsNumericFieldAlwaysMissing() throws Exception {
    SolrCore core = h.getCore();
    assertU(adoc("id", "1"));
    assertU(adoc("id", "2"));
    assertU(commit());
    assertU(adoc("id", "3"));
    assertU(adoc("id", "4"));
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "active_i");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test string statistics values", req, "//lst[@name='active_i']/long[@name='count'][.='0']", "//lst[@name='active_i']/long[@name='missing'][.='4']", "//lst[@name='active_i']/null[@name='min']", "//lst[@name='active_i']/null[@name='max']", "//lst[@name='active_i']/double[@name='sum'][.='0.0']", "//lst[@name='active_i']/double[@name='sumOfSquares'][.='0.0']", "//lst[@name='active_i']/double[@name='stddev'][.='0.0']", "//lst[@name='active_i']/double[@name='mean'][.='NaN']", // if new stats are supported, this will break - update test to assert values for each
    "count(//lst[@name='active_i']/*)=8");
    // NOTE: empty set percentiles covered in testPercentiles()
    assertQ("test cardinality of missing", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}active_i"), "//lst[@name='active_i']/long[@name='cardinality'][.='0']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore)

Example 37 with LocalSolrQueryRequest

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

the class StatsComponentTest method testFieldStatisticsResultsDateField.

public void testFieldStatisticsResultsDateField() throws Exception {
    SolrCore core = h.getCore();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT);
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    String date1 = dateFormat.format(new Date(123456789)) + "Z";
    String date2 = dateFormat.format(new Date(987654321)) + "Z";
    assertU(adoc("id", "1", "active_dt", date1));
    assertU(adoc("id", "2", "active_dt", date2));
    assertU(adoc("id", "3"));
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "active_dt");
    args.put("f.active_dt.stats.calcdistinct", "true");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test date statistics values", req, "//long[@name='count'][.='2']", "//long[@name='missing'][.='1']", "//date[@name='min'][.='1970-01-02T10:17:36Z']", "//date[@name='max'][.='1970-01-12T10:20:54Z']", "//long[@name='countDistinct'][.='2']", "count(//arr[@name='distinctValues']/date)=2");
    assertQ("cardinality", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}active_dt"), "//lst[@name='active_dt']/long[@name='cardinality'][.='2']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 38 with LocalSolrQueryRequest

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

the class StatsComponentTest method testFieldStatisticsResultsDateFieldAlwaysMissing.

//SOLR-3160
public void testFieldStatisticsResultsDateFieldAlwaysMissing() throws Exception {
    SolrCore core = h.getCore();
    assertU(adoc("id", "1"));
    assertU(adoc("id", "2"));
    assertU(commit());
    assertU(adoc("id", "3"));
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "active_dt");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test string statistics values", req, "//lst[@name='active_dt']/long[@name='count'][.='0']", "//lst[@name='active_dt']/long[@name='missing'][.='3']", "//lst[@name='active_dt']/null[@name='min']", "//lst[@name='active_dt']/null[@name='max']", "//lst[@name='active_dt']/null[@name='mean']", "//lst[@name='active_dt']/double[@name='sum'][.='0.0']", "//lst[@name='active_dt']/double[@name='sumOfSquares'][.='0.0']", "//lst[@name='active_dt']/double[@name='stddev'][.='0.0']", // if new stats are supported, this will break - update test to assert values for each
    "count(//lst[@name='active_dt']/*)=8");
    assertQ("cardinality", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}active_dt"), "//lst[@name='active_dt']/long[@name='cardinality'][.='0']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore)

Example 39 with LocalSolrQueryRequest

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

the class StatsComponentTest method testFieldStatisticsResultsDateFieldOverflow.

// Check for overflow of sumOfSquares
public void testFieldStatisticsResultsDateFieldOverflow() throws Exception {
    SolrCore core = h.getCore();
    assertU(adoc("id", "1", "active_dt", "2015-12-14T09:00:00Z"));
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "active_dt");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test date statistics values", req, "//long[@name='count'][.='1']", "//date[@name='min'][.='2015-12-14T09:00:00Z']", "//date[@name='max'][.='2015-12-14T09:00:00Z']", "//double[@name='sum'][.='1.4500836E12']", "//date[@name='mean'][.='2015-12-14T09:00:00Z']", "//double[@name='sumOfSquares'][.='" + Double.toString(2102742446988960000000000.0) + "']");
    assertU(adoc("id", "2", "active_dt", "2115-12-14T09:00:00Z"));
    assertU(adoc("id", "3", "active_dt", "2215-12-14T09:00:00Z"));
    assertU(commit());
    assertQ("test date statistics values", req, "//long[@name='count'][.='3']", "//date[@name='min'][.='2015-12-14T09:00:00Z']", "//date[@name='max'][.='2215-12-14T09:00:00Z']", "//double[@name='sum'][.='1.38172716E13']", "//date[@name='mean'][.='2115-12-14T09:00:00Z']", "//double[@name='sumOfSquares'][.='" + Double.toString(83555549895529430000000000.0) + "']", // That number is not precise, and the implementation should be fixed.
    "//double[@name='stddev'][.='" + Double.toString(3155673599999.999) + "']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore)

Example 40 with LocalSolrQueryRequest

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

the class QueryElevationComponentTest method testSorting.

@Test
public void testSorting() throws Exception {
    try {
        init("schema12.xml");
        assertU(adoc("id", "a", "title", "ipod trash trash", "str_s1", "a"));
        assertU(adoc("id", "b", "title", "ipod ipod  trash", "str_s1", "b"));
        assertU(adoc("id", "c", "title", "ipod ipod  ipod ", "str_s1", "c"));
        assertU(adoc("id", "x", "title", "boosted", "str_s1", "x"));
        assertU(adoc("id", "y", "title", "boosted boosted", "str_s1", "y"));
        assertU(adoc("id", "z", "title", "boosted boosted boosted", "str_s1", "z"));
        assertU(commit());
        String query = "title:ipod";
        // reusing args & requests this way is a solr-test-antipattern.  PLEASE DO NOT COPY THIS CODE
        Map<String, String> args = new HashMap<>();
        args.put(CommonParams.Q, query);
        args.put(CommonParams.QT, "/elevate");
        args.put(CommonParams.FL, "id,score");
        args.put("indent", "true");
        //args.put( CommonParams.FL, "id,title,score" );
        SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        IndexReader reader = req.getSearcher().getIndexReader();
        QueryElevationComponent booster = (QueryElevationComponent) req.getCore().getSearchComponent("elevate");
        assertQ("Make sure standard sort works as expected", req, "//*[@numFound='3']", "//result/doc[1]/str[@name='id'][.='c']", "//result/doc[2]/str[@name='id'][.='b']", "//result/doc[3]/str[@name='id'][.='a']");
        // Explicitly set what gets boosted
        booster.elevationCache.clear();
        booster.setTopQueryResults(reader, query, new String[] { "x", "y", "z" }, null);
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        assertQ("All six should make it", req, "//*[@numFound='6']", "//result/doc[1]/str[@name='id'][.='x']", "//result/doc[2]/str[@name='id'][.='y']", "//result/doc[3]/str[@name='id'][.='z']", "//result/doc[4]/str[@name='id'][.='c']", "//result/doc[5]/str[@name='id'][.='b']", "//result/doc[6]/str[@name='id'][.='a']");
        booster.elevationCache.clear();
        // now switch the order:
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        booster.setTopQueryResults(reader, query, new String[] { "a", "x" }, null);
        assertQ("All four should make it", req, "//*[@numFound='4']", "//result/doc[1]/str[@name='id'][.='a']", "//result/doc[2]/str[@name='id'][.='x']", "//result/doc[3]/str[@name='id'][.='c']", "//result/doc[4]/str[@name='id'][.='b']");
        // Test reverse sort
        args.put(CommonParams.SORT, "score asc");
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        assertQ("All four should make it", req, "//*[@numFound='4']", // NOTE REVERSED doc[X] indices
        "//result/doc[4]/str[@name='id'][.='a']", "//result/doc[3]/str[@name='id'][.='x']", "//result/doc[2]/str[@name='id'][.='c']", "//result/doc[1]/str[@name='id'][.='b']");
        // Try normal sort by 'id'
        // default 'forceBoost' should be false
        assertEquals(false, booster.forceElevation);
        args.put(CommonParams.SORT, "str_s1 asc");
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        assertQ(null, req, "//*[@numFound='4']", "//result/doc[1]/str[@name='id'][.='a']", "//result/doc[2]/str[@name='id'][.='b']", "//result/doc[3]/str[@name='id'][.='c']", "//result/doc[4]/str[@name='id'][.='x']");
        args.put(CommonParams.SORT, "id asc");
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        assertQ(null, req, "//*[@numFound='4']", "//result/doc[1]/str[@name='id'][.='a']", "//result/doc[2]/str[@name='id'][.='b']", "//result/doc[3]/str[@name='id'][.='c']", "//result/doc[4]/str[@name='id'][.='x']");
        booster.forceElevation = true;
        args.put(CommonParams.SORT, "id asc");
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        assertQ(null, req, "//*[@numFound='4']", "//result/doc[1]/str[@name='id'][.='a']", "//result/doc[2]/str[@name='id'][.='x']", "//result/doc[3]/str[@name='id'][.='b']", "//result/doc[4]/str[@name='id'][.='c']");
        //Test exclusive (not to be confused with exclusion)
        args.put(QueryElevationParams.EXCLUSIVE, "true");
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        booster.setTopQueryResults(reader, query, new String[] { "x", "a" }, new String[] {});
        assertQ(null, req, "//*[@numFound='2']", "//result/doc[1]/str[@name='id'][.='x']", "//result/doc[2]/str[@name='id'][.='a']");
        // Test exclusion
        booster.elevationCache.clear();
        args.remove(CommonParams.SORT);
        args.remove(QueryElevationParams.EXCLUSIVE);
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        booster.setTopQueryResults(reader, query, new String[] { "x" }, new String[] { "a" });
        assertQ(null, req, "//*[@numFound='3']", "//result/doc[1]/str[@name='id'][.='x']", "//result/doc[2]/str[@name='id'][.='c']", "//result/doc[3]/str[@name='id'][.='b']");
        // Test setting ids and excludes from http parameters
        booster.elevationCache.clear();
        args.put(QueryElevationParams.IDS, "x,y,z");
        args.put(QueryElevationParams.EXCLUDE, "b");
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        assertQ("All five should make it", req, "//*[@numFound='5']", "//result/doc[1]/str[@name='id'][.='x']", "//result/doc[2]/str[@name='id'][.='y']", "//result/doc[3]/str[@name='id'][.='z']", "//result/doc[4]/str[@name='id'][.='c']", "//result/doc[5]/str[@name='id'][.='a']");
        args.put(QueryElevationParams.IDS, "x,z,y");
        args.put(QueryElevationParams.EXCLUDE, "b,c");
        req.close();
        req = new LocalSolrQueryRequest(h.getCore(), new MapSolrParams(args));
        assertQ("All four should make it", req, "//*[@numFound='4']", "//result/doc[1]/str[@name='id'][.='x']", "//result/doc[2]/str[@name='id'][.='z']", "//result/doc[3]/str[@name='id'][.='y']", "//result/doc[4]/str[@name='id'][.='a']");
        req.close();
    } finally {
        delete();
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) IndexReader(org.apache.lucene.index.IndexReader) Test(org.junit.Test)

Aggregations

LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)107 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)61 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)49 SolrCore (org.apache.solr.core.SolrCore)47 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 Test (org.junit.Test)41 HashMap (java.util.HashMap)32 NamedList (org.apache.solr.common.util.NamedList)26 ArrayList (java.util.ArrayList)23 MapSolrParams (org.apache.solr.common.params.MapSolrParams)21 SolrException (org.apache.solr.common.SolrException)18 List (java.util.List)15 LinkedHashMap (java.util.LinkedHashMap)11 SolrParams (org.apache.solr.common.params.SolrParams)10 SearchComponent (org.apache.solr.handler.component.SearchComponent)10 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)10 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)10 Map (java.util.Map)9 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)9 IOException (java.io.IOException)8