Search in sources :

Example 11 with SolrQueryRequestBase

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

the class UniqFieldsUpdateProcessorFactoryTest method addDoc.

private void addDoc(String doc) throws Exception {
    Map<String, String[]> params = new HashMap<>();
    MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
    params.put(UpdateParams.UPDATE_CHAIN, new String[] { "uniq-fields" });
    SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) {
    };
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    ArrayList<ContentStream> streams = new ArrayList<>(2);
    streams.add(new ContentStreamBase.StringStream(doc));
    req.setContentStreams(streams);
    handler.handleRequestBody(req, new SolrQueryResponse());
    req.close();
}
Also used : ContentStream(org.apache.solr.common.util.ContentStream) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 12 with SolrQueryRequestBase

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

the class DocumentAnalysisRequestHandlerTest method testResolveAnalysisRequest.

/**
   * Tests the {@link DocumentAnalysisRequestHandler#resolveAnalysisRequest(org.apache.solr.request.SolrQueryRequest)}
   */
@Test
public void testResolveAnalysisRequest() throws Exception {
    String docsInput = "<docs>" + "<doc>" + "<field name=\"id\">1</field>" + "<field name=\"whitetok\">The Whitetok</field>" + "<field name=\"text\">The Text</field>" + "</doc>" + "</docs>";
    final ContentStream cs = new ContentStreamBase.StringStream(docsInput);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("analysis.query", "The Query String");
    params.add("analysis.showmatch", "true");
    SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {

        @Override
        public Iterable<ContentStream> getContentStreams() {
            return Collections.singleton(cs);
        }
    };
    DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
    assertNotNull(request);
    assertTrue(request.isShowMatch());
    assertNotNull(request.getQuery());
    assertEquals("The Query String", request.getQuery());
    List<SolrInputDocument> documents = request.getDocuments();
    assertNotNull(documents);
    assertEquals(1, documents.size());
    SolrInputDocument document = documents.get(0);
    SolrInputField field = document.getField("id");
    assertNotNull(field);
    assertEquals("1", field.getFirstValue());
    field = document.getField("whitetok");
    assertNotNull(field);
    assertEquals("The Whitetok", field.getFirstValue());
    field = document.getField("text");
    assertNotNull(field);
    assertEquals("The Text", field.getFirstValue());
    req.close();
}
Also used : ContentStream(org.apache.solr.common.util.ContentStream) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrInputField(org.apache.solr.common.SolrInputField) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) DocumentAnalysisRequest(org.apache.solr.client.solrj.request.DocumentAnalysisRequest) Test(org.junit.Test)

Example 13 with SolrQueryRequestBase

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

the class MoreLikeThisHandlerTest method testInterface.

@Test
public void testInterface() throws Exception {
    SolrCore core = h.getCore();
    MoreLikeThisHandler mlt = new MoreLikeThisHandler();
    ModifiableSolrParams params = new ModifiableSolrParams();
    SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
    };
    // requires 'q' or single content stream
    try {
        mlt.handleRequestBody(req, new SolrQueryResponse());
    }// expected
     catch (Exception ex) {
    }
    // requires 'q' or single content stream
    try {
        ArrayList<ContentStream> streams = new ArrayList<>(2);
        streams.add(new ContentStreamBase.StringStream("hello"));
        streams.add(new ContentStreamBase.StringStream("there"));
        req.setContentStreams(streams);
        mlt.handleRequestBody(req, new SolrQueryResponse());
    }// expected
     catch (Exception ex) {
    } finally {
        req.close();
    }
    assertU(adoc("id", "42", "name", "Tom Cruise", "subword", "Top Gun", "subword", "Risky Business", "subword", "The Color of Money", "subword", "Minority Report", "subword", "Days of Thunder", "subword", "Eyes Wide Shut", "subword", "Far and Away", "foo_ti", "10"));
    assertU(adoc("id", "43", "name", "Tom Hanks", "subword", "The Green Mile", "subword", "Forest Gump", "subword", "Philadelphia Story", "subword", "Big", "subword", "Cast Away", "foo_ti", "10"));
    assertU(adoc("id", "44", "name", "Harrison Ford", "subword", "Star Wars", "subword", "Indiana Jones", "subword", "Patriot Games", "subword", "Regarding Henry"));
    assertU(adoc("id", "45", "name", "George Harrison", "subword", "Yellow Submarine", "subword", "Help", "subword", "Magical Mystery Tour", "subword", "Sgt. Peppers Lonley Hearts Club Band"));
    assertU(adoc("id", "46", "name", "Nicole Kidman", "subword", "Batman", "subword", "Days of Thunder", "subword", "Eyes Wide Shut", "subword", "Far and Away"));
    assertU(commit());
    params.set(CommonParams.Q, "id:42");
    params.set(MoreLikeThisParams.MLT, "true");
    params.set(MoreLikeThisParams.SIMILARITY_FIELDS, "name,subword");
    params.set(MoreLikeThisParams.INTERESTING_TERMS, "details");
    params.set(MoreLikeThisParams.MIN_TERM_FREQ, "1");
    params.set(MoreLikeThisParams.MIN_DOC_FREQ, "1");
    params.set("indent", "true");
    SolrQueryRequest mltreq = new LocalSolrQueryRequest(core, params);
    assertQ("morelikethis - tom cruise", mltreq, "//result/doc[1]/int[@name='id'][.='46']", "//result/doc[2]/int[@name='id'][.='43']");
    params.set(MoreLikeThisParams.BOOST, "true");
    mltreq.close();
    mltreq = new LocalSolrQueryRequest(core, params);
    assertQ("morelikethis - tom cruise", mltreq, "//result/doc[1]/int[@name='id'][.='46']", "//result/doc[2]/int[@name='id'][.='43']");
    params.set(CommonParams.Q, "id:44");
    mltreq.close();
    mltreq = new LocalSolrQueryRequest(h.getCore(), params);
    assertQ("morelike this - harrison ford", mltreq, "//result/doc[1]/int[@name='id'][.='45']");
    // test MoreLikeThis debug
    params.set(CommonParams.DEBUG_QUERY, "true");
    mltreq.close();
    mltreq = new LocalSolrQueryRequest(h.getCore(), params);
    assertQ("morelike this - harrison ford", mltreq, "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='rawMLTQuery']", "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='boostedMLTQuery']", "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='realMLTQuery']", "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/lst[@name='explain']/str[@name='45']");
    // test that qparser plugins work
    params.remove(CommonParams.DEBUG_QUERY);
    params.set(CommonParams.Q, "{!field f=id}44");
    mltreq.close();
    mltreq = new LocalSolrQueryRequest(h.getCore(), params);
    assertQ(mltreq, "//result/doc[1]/int[@name='id'][.='45']");
    params.set(CommonParams.Q, "id:42");
    params.set(MoreLikeThisParams.QF, "name^5.0 subword^0.1");
    mltreq.close();
    mltreq = new LocalSolrQueryRequest(h.getCore(), params);
    assertQ("morelikethis with weights", mltreq, "//result/doc[1]/int[@name='id'][.='43']", "//result/doc[2]/int[@name='id'][.='46']");
    // test that qparser plugins work w/ the MoreLikeThisHandler
    params.set(CommonParams.QT, "/mlt");
    params.set(CommonParams.Q, "{!field f=id}44");
    mltreq.close();
    mltreq = new LocalSolrQueryRequest(h.getCore(), params);
    assertQ(mltreq, "//result/doc[1]/int[@name='id'][.='45']");
    // test that debugging works (test for MoreLikeThis*Handler*)
    params.set(CommonParams.QT, "/mlt");
    params.set(CommonParams.DEBUG_QUERY, "true");
    mltreq.close();
    mltreq = new LocalSolrQueryRequest(h.getCore(), params);
    assertQ(mltreq, "//result/doc[1]/int[@name='id'][.='45']", "//lst[@name='debug']/lst[@name='explain']");
    // params.put(MoreLikeThisParams.QF,new String[]{"foo_ti"});
    // String response = h.query(mltreq);
    // System.out.println(response);
    mltreq.close();
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrCore(org.apache.solr.core.SolrCore) ArrayList(java.util.ArrayList) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) ContentStream(org.apache.solr.common.util.ContentStream) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 14 with SolrQueryRequestBase

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

the class TestRerankBase method bulkIndex.

protected static void bulkIndex(String filePath) throws Exception {
    final SolrQueryRequestBase req = lrf.makeRequest(CommonParams.STREAM_CONTENTTYPE, "application/xml");
    final List<ContentStream> streams = new ArrayList<ContentStream>();
    final File file = new File(filePath);
    streams.add(new ContentStreamBase.FileStream(file));
    req.setContentStreams(streams);
    try {
        final SolrQueryResponse res = new SolrQueryResponse();
        h.updater.handleRequest(req, res);
    } catch (final Throwable ex) {
        // Ignore. Just log the exception and go to the next file
        log.error(ex.getMessage(), ex);
    }
    assertU(commit());
}
Also used : ContentStream(org.apache.solr.common.util.ContentStream) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) ArrayList(java.util.ArrayList) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) File(java.io.File) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 15 with SolrQueryRequestBase

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

the class CloudMLTQParser method getDocument.

private SolrDocument getDocument(String id) {
    SolrCore core = req.getCore();
    SolrQueryResponse rsp = new SolrQueryResponse();
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(ID, id);
    SolrQueryRequestBase request = new SolrQueryRequestBase(core, params) {
    };
    core.getRequestHandler("/get").handleRequest(request, rsp);
    NamedList response = rsp.getValues();
    return (SolrDocument) response.get("doc");
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrDocument(org.apache.solr.common.SolrDocument) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

SolrQueryRequestBase (org.apache.solr.request.SolrQueryRequestBase)15 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)11 SolrCore (org.apache.solr.core.SolrCore)8 ContentStream (org.apache.solr.common.util.ContentStream)7 UpdateRequestHandler (org.apache.solr.handler.UpdateRequestHandler)7 MapSolrParams (org.apache.solr.common.params.MapSolrParams)6 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)5 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)5 ArrayList (java.util.ArrayList)4 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)4 Test (org.junit.Test)4 DocumentAnalysisRequest (org.apache.solr.client.solrj.request.DocumentAnalysisRequest)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 File (java.io.File)2 HashMap (java.util.HashMap)2 SolrException (org.apache.solr.common.SolrException)2 MultiMapSolrParams (org.apache.solr.common.params.MultiMapSolrParams)2 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1