Search in sources :

Example 91 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.

the class TestSuggesterResponse method testSuggesterResponseObject.

@Test
public void testSuggesterResponseObject() throws Exception {
    getSolrClient();
    addSampleDocs();
    SolrQuery query = new SolrQuery("*:*");
    query.set(CommonParams.QT, "/suggest");
    query.set("suggest.dictionary", "mySuggester");
    query.set("suggest.q", "Com");
    query.set("suggest.build", true);
    QueryRequest request = new QueryRequest(query);
    QueryResponse queryResponse = request.process(client);
    SuggesterResponse response = queryResponse.getSuggesterResponse();
    Map<String, List<Suggestion>> dictionary2suggestions = response.getSuggestions();
    assertTrue(dictionary2suggestions.keySet().contains("mySuggester"));
    List<Suggestion> mySuggester = dictionary2suggestions.get("mySuggester");
    assertEquals("Computational framework", mySuggester.get(0).getTerm());
    assertEquals(0, mySuggester.get(0).getWeight());
    assertEquals("", mySuggester.get(0).getPayload());
    assertEquals("Computer", mySuggester.get(1).getTerm());
    assertEquals(0, mySuggester.get(1).getWeight());
    assertEquals("", mySuggester.get(1).getPayload());
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) List(java.util.List) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 92 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.

the class TestSuggesterResponse method testSuggesterResponseTerms.

@Test
public void testSuggesterResponseTerms() throws Exception {
    getSolrClient();
    addSampleDocs();
    SolrQuery query = new SolrQuery("*:*");
    query.set(CommonParams.QT, "/suggest");
    query.set("suggest.dictionary", "mySuggester");
    query.set("suggest.q", "Com");
    query.set("suggest.build", true);
    QueryRequest request = new QueryRequest(query);
    QueryResponse queryResponse = request.process(client);
    SuggesterResponse response = queryResponse.getSuggesterResponse();
    Map<String, List<String>> dictionary2suggestions = response.getSuggestedTerms();
    assertTrue(dictionary2suggestions.keySet().contains("mySuggester"));
    List<String> mySuggester = dictionary2suggestions.get("mySuggester");
    assertEquals("Computational framework", mySuggester.get(0));
    assertEquals("Computer", mySuggester.get(1));
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) List(java.util.List) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 93 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.

the class TermsResponseTest method testTermsResponse.

@Test
public void testTermsResponse() throws Exception {
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", 1);
    doc.setField("terms_s", "samsung");
    getSolrClient().add(doc);
    getSolrClient().commit(true, true);
    SolrQuery query = new SolrQuery();
    query.setRequestHandler("/terms");
    query.setTerms(true);
    query.setTermsLimit(5);
    query.setTermsLower("s");
    query.setTermsPrefix("s");
    query.addTermsField("terms_s");
    query.setTermsMinCount(1);
    QueryRequest request = new QueryRequest(query);
    List<Term> terms = request.process(getSolrClient()).getTermsResponse().getTerms("terms_s");
    Assert.assertNotNull(terms);
    Assert.assertEquals(terms.size(), 1);
    Term term = terms.get(0);
    Assert.assertEquals(term.getTerm(), "samsung");
    Assert.assertEquals(term.getFrequency(), 1);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) Term(org.apache.solr.client.solrj.response.TermsResponse.Term) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 94 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.

the class NoOpResponseParserTest method testQueryParse.

/**
   * Parse response from query using NoOpResponseParser.
   */
@Test
public void testQueryParse() throws Exception {
    try (HttpSolrClient client = (HttpSolrClient) createNewSolrClient()) {
        SolrQuery query = new SolrQuery("id:1234");
        QueryRequest req = new QueryRequest(query);
        client.setParser(new NoOpResponseParser());
        NamedList<Object> resp = client.request(req);
        String responseString = (String) resp.get("response");
        assertResponse(responseString);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) NoOpResponseParser(org.apache.solr.client.solrj.impl.NoOpResponseParser) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 95 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.

the class TestReplicationHandler method assertVersions.

private void assertVersions(SolrClient client1, SolrClient client2) throws Exception {
    NamedList<Object> details = getDetails(client1);
    ArrayList<NamedList<Object>> commits = (ArrayList<NamedList<Object>>) details.get("commits");
    Long maxVersionClient1 = getVersion(client1);
    Long maxVersionClient2 = getVersion(client2);
    if (maxVersionClient1 > 0 && maxVersionClient2 > 0) {
        assertEquals(maxVersionClient1, maxVersionClient2);
    }
    // check vs /replication?command=indexversion call
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", ReplicationHandler.PATH);
    params.set("_trace", "assertVersions");
    params.set("command", "indexversion");
    QueryRequest req = new QueryRequest(params);
    NamedList<Object> resp = client1.request(req);
    Long version = (Long) resp.get("indexversion");
    assertEquals(maxVersionClient1, version);
    // check vs /replication?command=indexversion call
    resp = client2.request(req);
    version = (Long) resp.get("indexversion");
    assertEquals(maxVersionClient2, version);
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)112 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)77 SolrRequest (org.apache.solr.client.solrj.SolrRequest)35 NamedList (org.apache.solr.common.util.NamedList)35 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)29 Test (org.junit.Test)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)21 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)17 Map (java.util.Map)17 SolrQuery (org.apache.solr.client.solrj.SolrQuery)17 IOException (java.io.IOException)16 SolrException (org.apache.solr.common.SolrException)15 SolrInputDocument (org.apache.solr.common.SolrInputDocument)14 SolrClient (org.apache.solr.client.solrj.SolrClient)13 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)12 List (java.util.List)11 SolrServerException (org.apache.solr.client.solrj.SolrServerException)8 RemoteSolrException (org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)8 SolrDocumentList (org.apache.solr.common.SolrDocumentList)8