Search in sources :

Example 51 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class JsonLoaderTest method testEmptyChildDocs.

@Test
public void testEmptyChildDocs() throws Exception {
    String str = "{\n" + "    \"add\": {\n" + "        \"doc\": {\n" + "            \"id\": \"1\",\n" + "            \"_childDocuments_\": []\n" + "        }\n" + "    }\n" + "}";
    SolrQueryRequest req = req("commit", "true");
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    JsonLoader loader = new JsonLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
    assertEquals(1, p.addCommands.size());
    AddUpdateCommand add = p.addCommands.get(0);
    SolrInputDocument d = add.solrDoc;
    SolrInputField f = d.getField("id");
    assertEquals("1", f.getValue());
    List<SolrInputDocument> cd = d.getChildDocuments();
    assertNull(cd);
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) SolrInputField(org.apache.solr.common.SolrInputField) JsonLoader(org.apache.solr.handler.loader.JsonLoader) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 52 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class TestSchemalessBufferedUpdates method processAdd.

private SolrInputDocument processAdd(final SolrInputDocument docIn) throws IOException {
    UpdateRequestProcessorChain processorChain = h.getCore().getUpdateProcessingChain(UPDATE_CHAIN);
    assertNotNull("Undefined URP chain '" + UPDATE_CHAIN + "'", processorChain);
    List<UpdateRequestProcessorFactory> factoriesUpToDUP = new ArrayList<>();
    for (UpdateRequestProcessorFactory urpFactory : processorChain.getProcessors()) {
        factoriesUpToDUP.add(urpFactory);
        if (urpFactory.getClass().equals(DistributedUpdateProcessorFactory.class))
            break;
    }
    UpdateRequestProcessorChain chainUpToDUP = new UpdateRequestProcessorChain(factoriesUpToDUP, h.getCore());
    assertNotNull("URP chain '" + UPDATE_CHAIN + "'", chainUpToDUP);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = req();
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        AddUpdateCommand cmd = new AddUpdateCommand(req);
        cmd.solrDoc = docIn;
        UpdateRequestProcessor processor = chainUpToDUP.createProcessor(req, rsp);
        processor.processAdd(cmd);
        if (cmd.solrDoc.get("f_dt").getValue() instanceof Date) {
            // Non-JSON types (Date in this case) aren't handled properly in noggit-0.6.  Although this is fixed in 
            // https://github.com/yonik/noggit/commit/ec3e732af7c9425e8f40297463cbe294154682b1 to call obj.toString(), 
            // Date::toString produces a Date representation that Solr doesn't like, so we convert using Instant::toString
            cmd.solrDoc.get("f_dt").setValue(((Date) cmd.solrDoc.get("f_dt").getValue()).toInstant().toString());
        }
        return cmd.solrDoc;
    } finally {
        SolrRequestInfo.clearRequestInfo();
        req.close();
    }
}
Also used : UpdateRequestProcessorFactory(org.apache.solr.update.processor.UpdateRequestProcessorFactory) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) ArrayList(java.util.ArrayList) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Date(java.util.Date)

Example 53 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class QueryEqualityTest method assertQueryEquals.

/**
   * NOTE: defType is not only used to pick the parser, but, if non-null it is 
   * also to record the parser being tested for coverage sanity checking
   *
   * @see QueryUtils#check
   * @see QueryUtils#checkEqual
   * @see #testParserCoverage
   */
protected void assertQueryEquals(final String defType, final SolrQueryRequest req, final String... inputs) throws Exception {
    if (null != defType)
        qParsersTested.add(defType);
    final Query[] queries = new Query[inputs.length];
    try {
        SolrQueryResponse rsp = new SolrQueryResponse();
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        for (int i = 0; i < inputs.length; i++) {
            queries[i] = (QParser.getParser(inputs[i], defType, req).getQuery());
        }
    } finally {
        SolrRequestInfo.clearRequestInfo();
    }
    for (int i = 0; i < queries.length; i++) {
        QueryUtils.check(queries[i]);
        // of which caller/callee is used.
        for (int j = 0; j < queries.length; j++) {
            QueryUtils.checkEqual(queries[i], queries[j]);
        }
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Query(org.apache.lucene.search.Query) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo)

Example 54 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class SpellCheckCollatorTest method testCollateWithMultipleRequestHandlers.

@Test
public void testCollateWithMultipleRequestHandlers() 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(SpellingParams.SPELLCHECK_DICT, "multipleFields");
    params.add(SpellingParams.SPELLCHECK_BUILD, "true");
    params.add(SpellingParams.SPELLCHECK_COUNT, "10");
    params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "1");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1");
    params.add(CommonParams.Q, "peac");
    //SpellCheckCompRH has no "qf" defined.  It will not find "peace" from "peac" despite it being in the dictionary
    //because requrying against this Request Handler results in 0 hits.
    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 collationHolder = (NamedList) spellCheck.get("collations");
    String singleCollation = (String) collationHolder.get("collation");
    assertNull(singleCollation);
    //SpellCheckCompRH1 has "lowerfilt1" defined in the "qf" param.  It will find "peace" from "peac" because
    //requrying field "lowerfilt1" returns the hit.
    params.remove(SpellingParams.SPELLCHECK_BUILD);
    handler = core.getRequestHandler("spellCheckCompRH1");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    values = rsp.getValues();
    spellCheck = (NamedList) values.get("spellcheck");
    collationHolder = (NamedList) spellCheck.get("collations");
    singleCollation = (String) collationHolder.get("collation");
    assertEquals(singleCollation, "peace");
}
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) 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 55 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class SpellCheckCollatorTest method testExtendedCollate.

@Test
public void testExtendedCollate() 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(CommonParams.QT, "spellCheckCompRH");
    params.add(CommonParams.Q, "lowerfilt:(+fauth +home +loane)");
    params.add(SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true");
    params.add(SpellCheckComponent.COMPONENT_NAME, "true");
    params.add(SpellingParams.SPELLCHECK_BUILD, "true");
    params.add(SpellingParams.SPELLCHECK_COUNT, "10");
    params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
    // Testing backwards-compatible behavior.
    // Returns 1 collation as a single string.
    // All words are "correct" per the dictionary, but this collation would
    // return no results if tried.
    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 collationHolder = (NamedList) spellCheck.get("collations");
    String singleCollation = (String) collationHolder.get("collation");
    assertEquals("lowerfilt:(+faith +homer +loaves)", singleCollation);
    // Testing backwards-compatible response format but will only return a
    // collation that would return results.
    params.remove(SpellingParams.SPELLCHECK_BUILD);
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "5");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1");
    handler = core.getRequestHandler("spellCheckCompRH");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    values = rsp.getValues();
    spellCheck = (NamedList) values.get("spellcheck");
    collationHolder = (NamedList) spellCheck.get("collations");
    singleCollation = (String) collationHolder.get("collation");
    assertEquals("lowerfilt:(+faith +hope +loaves)", singleCollation);
    // Testing returning multiple collations if more than one valid
    // combination exists.
    params.remove(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES);
    params.remove(SpellingParams.SPELLCHECK_MAX_COLLATIONS);
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "2");
    handler = core.getRequestHandler("spellCheckCompRH");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    values = rsp.getValues();
    spellCheck = (NamedList) values.get("spellcheck");
    collationHolder = (NamedList) spellCheck.get("collations");
    List<String> collations = collationHolder.getAll("collation");
    assertTrue(collations.size() == 2);
    for (String multipleCollation : collations) {
        assertTrue(multipleCollation.equals("lowerfilt:(+faith +hope +love)") || multipleCollation.equals("lowerfilt:(+faith +hope +loaves)"));
    }
    // Testing return multiple collations with expanded collation response
    // format.
    params.add(SpellingParams.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "true");
    handler = core.getRequestHandler("spellCheckCompRH");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    values = rsp.getValues();
    spellCheck = (NamedList) values.get("spellcheck");
    collationHolder = (NamedList) spellCheck.get("collations");
    List<NamedList> expandedCollationList = collationHolder.getAll("collation");
    Set<String> usedcollations = new HashSet<>();
    assertTrue(expandedCollationList.size() == 2);
    for (NamedList expandedCollation : expandedCollationList) {
        String multipleCollation = (String) expandedCollation.get("collationQuery");
        assertTrue(multipleCollation.equals("lowerfilt:(+faith +hope +love)") || multipleCollation.equals("lowerfilt:(+faith +hope +loaves)"));
        assertTrue(!usedcollations.contains(multipleCollation));
        usedcollations.add(multipleCollation);
        int hits = (Integer) expandedCollation.get("hits");
        assertTrue(hits == 1);
        NamedList misspellingsAndCorrections = (NamedList) expandedCollation.get("misspellingsAndCorrections");
        assertTrue(misspellingsAndCorrections.size() == 3);
        String correctionForFauth = (String) misspellingsAndCorrections.get("fauth");
        String correctionForHome = (String) misspellingsAndCorrections.get("home");
        String correctionForLoane = (String) misspellingsAndCorrections.get("loane");
        assertTrue(correctionForFauth.equals("faith"));
        assertTrue(correctionForHome.equals("hope"));
        assertTrue(correctionForLoane.equals("love") || correctionForLoane.equals("loaves"));
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) 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) SearchComponent(org.apache.solr.handler.component.SearchComponent) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)258 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)128 Test (org.junit.Test)100 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)80 NamedList (org.apache.solr.common.util.NamedList)68 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)58 SolrCore (org.apache.solr.core.SolrCore)52 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)40 SolrException (org.apache.solr.common.SolrException)32 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)29 ArrayList (java.util.ArrayList)26 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)22 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)21 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)20 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)20 JsonLoader (org.apache.solr.handler.loader.JsonLoader)17 IOException (java.io.IOException)16 HashMap (java.util.HashMap)16