Search in sources :

Example 51 with LocalSolrQueryRequest

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

the class SpellCheckCollatorTest method testZeroTries.

@Test
public void testZeroTries() throws Exception {
    SolrCore core = h.getCore();
    SearchComponent speller = core.getSearchComponent("spellcheck");
    assertTrue("speller is null and it shouldn't be", speller != null);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(SpellCheckComponent.COMPONENT_NAME, "true");
    params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
    params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10");
    params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true");
    params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "0");
    params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "2");
    params.add(CommonParams.Q, "lowerfilt:(+fauth)");
    SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    NamedList values = rsp.getValues();
    NamedList spellCheck = (NamedList) values.get("spellcheck");
    NamedList collationList = (NamedList) spellCheck.get("collations");
    List<?> collations = (List<?>) collationList.getAll("collation");
    assertTrue(collations.size() == 2);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SearchComponent(org.apache.solr.handler.component.SearchComponent) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 52 with LocalSolrQueryRequest

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

the class ReplicaListTransformerTest method testTransform.

@Test
public void testTransform() throws Exception {
    final String regex = ".*" + random().nextInt(10) + ".*";
    final ReplicaListTransformer transformer;
    if (random().nextBoolean()) {
        transformer = new ToyMatchingReplicaListTransformer(regex);
    } else {
        transformer = new HttpShardHandlerFactory() {

            @Override
            protected ReplicaListTransformer getReplicaListTransformer(final SolrQueryRequest req) {
                final SolrParams params = req.getParams();
                if (params.getBool("toyNoTransform", false)) {
                    return new ToyNoOpReplicaListTransformer();
                }
                final String regex = params.get("toyRegEx");
                if (regex != null) {
                    return new ToyMatchingReplicaListTransformer(regex);
                }
                return super.getReplicaListTransformer(req);
            }
        }.getReplicaListTransformer(new LocalSolrQueryRequest(null, new ModifiableSolrParams().add("toyRegEx", regex)));
    }
    final List<Replica> inputs = new ArrayList<>();
    final List<Replica> expectedTransformed = new ArrayList<>();
    final List<String> urls = createRandomUrls();
    for (int ii = 0; ii < urls.size(); ++ii) {
        final String name = "replica" + (ii + 1);
        final String url = urls.get(ii);
        final Map<String, Object> propMap = new HashMap<String, Object>();
        propMap.put("base_url", url);
        // a skeleton replica, good enough for this test's purposes
        final Replica replica = new Replica(name, propMap);
        inputs.add(replica);
        if (url.matches(regex)) {
            expectedTransformed.add(replica);
        }
    }
    final List<Replica> actualTransformed = new ArrayList<>(inputs);
    transformer.transform(actualTransformed);
    assertEquals(expectedTransformed.size(), actualTransformed.size());
    for (int ii = 0; ii < expectedTransformed.size(); ++ii) {
        assertEquals("mismatch for ii=" + ii, expectedTransformed.get(ii), actualTransformed.get(ii));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) Test(org.junit.Test)

Example 53 with LocalSolrQueryRequest

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

the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValuedIntegerFacetStats.

public void testFieldStatisticsDocValuesAndMultiValuedIntegerFacetStats() throws Exception {
    SolrCore core = h.getCore();
    String fieldName = "cat_intDocValues";
    // precondition for the test
    SchemaField catDocValues = core.getLatestSchema().getField(fieldName);
    assertTrue("schema no longer satisfies test requirements: cat_docValues no longer multivalued", catDocValues.multiValued());
    assertTrue("schema no longer satisfies test requirements: cat_docValues fieldtype no longer single valued", !catDocValues.getType().isMultiValued());
    assertTrue("schema no longer satisfies test requirements: cat_docValues no longer has docValues", catDocValues.hasDocValues());
    List<FldType> types = new ArrayList<>();
    types.add(new FldType("id", ONE_ONE, new SVal('A', 'Z', 4, 4)));
    types.add(new FldType(fieldName, ONE_ONE, new IRange(0, 0)));
    Doc d1 = createDocValuesDocument(types, fieldName, "1", -1, 3, 5);
    updateJ(toJSON(d1), null);
    Doc d2 = createDocValuesDocument(types, fieldName, "2", 3, -2, 6);
    updateJ(toJSON(d2), null);
    Doc d3 = createDocValuesDocument(types, fieldName, "3", 16, -3, 11);
    updateJ(toJSON(d3), null);
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, fieldName);
    args.put(StatsParams.STATS_FACET, fieldName);
    args.put(StatsParams.STATS_CALC_DISTINCT, "true");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQEx("can not use FieldCache on multivalued field: cat_intDocValues", req, 400);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore) ArrayList(java.util.ArrayList) SchemaField(org.apache.solr.schema.SchemaField) 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)

Example 54 with LocalSolrQueryRequest

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

the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValuedInteger.

public void testFieldStatisticsDocValuesAndMultiValuedInteger() throws Exception {
    SolrCore core = h.getCore();
    String fieldName = "cat_intDocValues";
    // precondition for the test
    SchemaField catDocValues = core.getLatestSchema().getField(fieldName);
    assertTrue("schema no longer satisfies test requirements: cat_docValues no longer multivalued", catDocValues.multiValued());
    assertTrue("schema no longer satisfies test requirements: cat_docValues fieldtype no longer single valued", !catDocValues.getType().isMultiValued());
    assertTrue("schema no longer satisfies test requirements: cat_docValues no longer has docValues", catDocValues.hasDocValues());
    List<FldType> types = new ArrayList<>();
    types.add(new FldType("id", ONE_ONE, new SVal('A', 'Z', 4, 4)));
    types.add(new FldType(fieldName, ONE_ONE, new IRange(0, 0)));
    Doc d1 = createDocValuesDocument(types, fieldName, "1", -1, 3, 5);
    updateJ(toJSON(d1), null);
    Doc d2 = createDocValuesDocument(types, fieldName, "2", 3, -2, 6);
    updateJ(toJSON(d2), null);
    Doc d3 = createDocValuesDocument(types, fieldName, "3", 16, -3, 11);
    updateJ(toJSON(d3), null);
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, fieldName);
    args.put(StatsParams.STATS_CALC_DISTINCT, "true");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test min/max on docValues and multiValued", req, "//lst[@name='" + fieldName + "']/double[@name='min'][.='-3.0']", "//lst[@name='" + fieldName + "']/double[@name='max'][.='16.0']", "//lst[@name='" + fieldName + "']/long[@name='count'][.='12']", "//lst[@name='" + fieldName + "']/long[@name='countDistinct'][.='9']", "//lst[@name='" + fieldName + "']/double[@name='sum'][.='38.0']", "//lst[@name='" + fieldName + "']/double[@name='mean'][.='3.1666666666666665']", "//lst[@name='" + fieldName + "']/double[@name='stddev'][.='5.638074031784151']", "//lst[@name='" + fieldName + "']/double[@name='sumOfSquares'][.='470.0']", "//lst[@name='" + fieldName + "']/long[@name='missing'][.='0']");
    assertQ("cardinality", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}" + fieldName), "//lst[@name='" + fieldName + "']/long[@name='cardinality'][.='9']");
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore) ArrayList(java.util.ArrayList) SchemaField(org.apache.solr.schema.SchemaField) 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)

Example 55 with LocalSolrQueryRequest

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

the class StatsComponentTest method testStatsExcludeFilterQuery.

//SOLR-3177
public void testStatsExcludeFilterQuery() throws Exception {
    SolrCore core = h.getCore();
    assertU(adoc("id", "1"));
    assertU(adoc("id", "2"));
    assertU(adoc("id", "3"));
    assertU(adoc("id", "4"));
    assertU(commit());
    Map<String, String> args = new HashMap<String, String>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "{!ex=id}id");
    args.put("fq", "{!tag=id}id:[2 TO 3]");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test exluding filter query", req, "//lst[@name='id']/double[@name='min'][.='1.0']", "//lst[@name='id']/double[@name='max'][.='4.0']");
    args = new HashMap<String, String>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "{!key=id2}id");
    args.put("fq", "{!tag=id}id:[2 TO 3]");
    req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test rename field", req, "//lst[@name='id2']/double[@name='min'][.='2.0']", "//lst[@name='id2']/double[@name='max'][.='3.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)

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