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());
}
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));
}
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);
}
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);
}
}
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);
}
Aggregations