Search in sources :

Example 31 with LocalSolrQueryRequest

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

the class TolerantUpdateProcessorTest method add.

protected SolrQueryResponse add(final String chain, SolrParams requestParams, final Collection<SolrInputDocument> docs) throws IOException {
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
    assertNotNull("No Chain named: " + chain, pc);
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.add("responseHeader", new SimpleOrderedMap<Object>());
    if (requestParams == null) {
        requestParams = new ModifiableSolrParams();
    }
    SolrQueryRequest req = new LocalSolrQueryRequest(core, requestParams);
    UpdateRequestProcessor processor = null;
    try {
        processor = pc.createProcessor(req, rsp);
        for (SolrInputDocument doc : docs) {
            AddUpdateCommand cmd = new AddUpdateCommand(req);
            cmd.solrDoc = doc;
            processor.processAdd(cmd);
        }
        processor.finish();
    } finally {
        IOUtils.closeQuietly(processor);
        req.close();
    }
    return rsp;
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrCore(org.apache.solr.core.SolrCore) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 32 with LocalSolrQueryRequest

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

the class UpdateProcessorTestBase method processAdd.

/**
   * Runs a document through the specified chain, and returns the final
   * document used when the chain is completed (NOTE: some chains may
   * modify the document in place
   */
protected SolrInputDocument processAdd(final String chain, final SolrParams requestParams, final SolrInputDocument docIn) throws IOException {
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
    assertNotNull("No Chain named: " + chain, pc);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = new LocalSolrQueryRequest(core, requestParams);
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        AddUpdateCommand cmd = new AddUpdateCommand(req);
        cmd.solrDoc = docIn;
        UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
        if (null != processor) {
            // test chain might be empty or short circuited.
            processor.processAdd(cmd);
        }
        return cmd.solrDoc;
    } finally {
        SolrRequestInfo.clearRequestInfo();
        req.close();
    }
}
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) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 33 with LocalSolrQueryRequest

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

the class UpdateProcessorTestBase method processDeleteById.

protected void processDeleteById(final String chain, String id) throws IOException {
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
    assertNotNull("No Chain named: " + chain, pc);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
    DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
    cmd.setId(id);
    UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
    try {
        processor.processDelete(cmd);
    } finally {
        req.close();
    }
}
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) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 34 with LocalSolrQueryRequest

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

the class StatsComponentTest method testFieldStatisticsResultsStringFieldAlwaysMissing.

public void testFieldStatisticsResultsStringFieldAlwaysMissing() 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_s");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test string statistics values", req, "//lst[@name='active_s']/long[@name='count'][.='0']", "//lst[@name='active_s']/long[@name='missing'][.='4']", "//lst[@name='active_s']/null[@name='min']", "//lst[@name='active_s']/null[@name='max']", // if new stats are supported, this will break - update test to assert values for each
    "count(//lst[@name='active_s']/*)=4");
    assertQ("test string statistics values", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}active_s"), "//lst[@name='active_s']/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 35 with LocalSolrQueryRequest

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

the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValued.

// SOLR-6024
public void testFieldStatisticsDocValuesAndMultiValued() throws Exception {
    SolrCore core = h.getCore();
    // precondition for the test
    SchemaField catDocValues = core.getLatestSchema().getField("cat_docValues");
    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("cat_docValues", new IRange(2, 2), new SVal('a', 'z', 1, 30)));
    Doc d1 = createDoc(types);
    d1.getValues("id").set(0, "1");
    d1.getValues("cat_docValues").set(0, "test");
    d1.getValues("cat_docValues").set(1, "testtw");
    updateJ(toJSON(d1), null);
    Doc d2 = createDoc(types);
    d2.getValues("id").set(0, "2");
    d2.getValues("cat_docValues").set(0, "test");
    d2.getValues("cat_docValues").set(1, "testtt");
    updateJ(toJSON(d2), null);
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "cat_docValues");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test min/max on docValues and multiValued", req, "//lst[@name='cat_docValues']/str[@name='min'][.='test']", "//lst[@name='cat_docValues']/str[@name='max'][.='testtw']");
    assertQ("cardinality", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}cat_docValues"), "//lst[@name='cat_docValues']/long[@name='cardinality'][.='3']");
}
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)

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