Search in sources :

Example 21 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams 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 22 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams 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 23 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams 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 24 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams 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)

Example 25 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams in project xwiki-platform by xwiki.

the class XWikiDismaxQParserPluginTest method withFieldAliasesWhenNoFieldsInQuery.

@Test
public void withFieldAliasesWhenNoFieldsInQuery() {
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("qf", "title^0.4 comment^0.40");
    parameters.put("xwiki.multilingualFields", "title, foo");
    parameters.put("xwiki.supportedLocales", "en, fr");
    parameters.put("xwiki.typedDynamicFields", "property.*");
    parameters.put("xwiki.dynamicFieldTypes", "long, date");
    SolrParams paramsWithAliases = plugin.withFieldAliases("text", new MapSolrParams(parameters));
    // 5 existing parameters plus one alias.
    assertEquals(6, paramsWithAliases.toNamedList().size());
    // A default multilingual field.
    assertEquals("title__ title_en title_fr", paramsWithAliases.get("f.title.qf"));
    // Not a multilingual field.
    assertNull(paramsWithAliases.get("f.comment.qf"));
    // Not a default field.
    assertNull(paramsWithAliases.get("f.foo.qf"));
}
Also used : MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) Test(org.junit.Test)

Aggregations

MapSolrParams (org.apache.solr.common.params.MapSolrParams)50 HashMap (java.util.HashMap)33 SolrCore (org.apache.solr.core.SolrCore)24 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)20 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)19 SolrParams (org.apache.solr.common.params.SolrParams)14 Test (org.junit.Test)14 LinkedHashMap (java.util.LinkedHashMap)11 ArrayList (java.util.ArrayList)10 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)10 SolrException (org.apache.solr.common.SolrException)6 UpdateRequestHandler (org.apache.solr.handler.UpdateRequestHandler)6 SolrQueryRequestBase (org.apache.solr.request.SolrQueryRequestBase)6 Map (java.util.Map)4 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 Utils.makeMap (org.apache.solr.common.util.Utils.makeMap)4 IOException (java.io.IOException)3 SchemaField (org.apache.solr.schema.SchemaField)3 StringWriter (java.io.StringWriter)2 Collections.singletonMap (java.util.Collections.singletonMap)2