use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class CloudMLTQParserTest method testHighDFValue.
@Test
public void testHighDFValue() throws Exception {
// Test out a high value of df and make sure nothing matches.
QueryResponse queryResponse = cluster.getSolrClient().query(COLLECTION, new SolrQuery("{!mlt qf=lowerfilt_u mindf=20 mintf=1}3"));
SolrDocumentList solrDocuments = queryResponse.getResults();
assertEquals("Expected to match 0 documents with a mindf of 20 but found more", solrDocuments.size(), 0);
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class CloudMLTQParserTest method testHighWLValue.
@Test
public void testHighWLValue() throws Exception {
// Test out a high value of wl and make sure nothing matches.
QueryResponse queryResponse = cluster.getSolrClient().query(COLLECTION, new SolrQuery("{!mlt qf=lowerfilt_u minwl=4 mintf=1}3"));
SolrDocumentList solrDocuments = queryResponse.getResults();
assertEquals("Expected to match 0 documents with a minwl of 4 but found more", solrDocuments.size(), 0);
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class TestInPlaceUpdatesStandalone method getDocId.
/**
* Helper method to search for the specified (uniqueKey field) id using <code>fl=[docid]</code>
* and return the internal lucene docid.
*/
private int getDocId(String id) throws NumberFormatException, Exception {
SolrDocumentList results = client.query(params("q", "id:" + id, "fl", "[docid]")).getResults();
assertEquals(1, results.getNumFound());
assertEquals(1, results.size());
Object docid = results.get(0).getFieldValue("[docid]");
assertTrue(docid instanceof Integer);
return ((Integer) docid);
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class SolrExampleTests method testRawFields.
@Test
public void testRawFields() throws Exception {
String rawJson = "{ \"raw\": 1.234, \"id\":\"111\" }";
String rawXml = "<hello>this is <some/><xml/></hello>";
SolrClient client = getSolrClient();
// Empty the database...
// delete everything!
client.deleteByQuery("*:*");
// Now add something...
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "111");
doc.addField("name", "doc1");
doc.addField("json_s", rawJson);
doc.addField("xml_s", rawXml);
client.add(doc);
// make sure this gets in first
client.commit();
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.set(CommonParams.FL, "id,json_s:[json],xml_s:[xml]");
QueryRequest req = new QueryRequest(query);
req.setResponseParser(new BinaryResponseParser());
QueryResponse rsp = req.process(client);
SolrDocumentList out = rsp.getResults();
assertEquals(1, out.getNumFound());
SolrDocument out1 = out.get(0);
assertEquals("111", out1.getFieldValue("id"));
// Check that the 'raw' fields are unchanged using the standard formats
assertEquals(rawJson, out1.get("json_s"));
assertEquals(rawXml, out1.get("xml_s"));
if (client instanceof EmbeddedSolrServer) {
// the EmbeddedSolrServer ignores the configured parser
return;
}
// Check raw JSON Output
query.set("fl", "id,json_s:[json],xml_s:[xml]");
query.set(CommonParams.WT, "json");
req = new QueryRequest(query);
req.setResponseParser(new NoOpResponseParser("json"));
NamedList<Object> resp = client.request(req);
String raw = (String) resp.get("response");
// Check that the response parses as JSON
JSONParser parser = new JSONParser(raw);
int evt = parser.nextEvent();
while (evt != JSONParser.EOF) {
evt = parser.nextEvent();
}
// no escaping
assertTrue(raw.indexOf(rawJson) > 0);
// quoted xml
assertTrue(raw.indexOf('"' + rawXml + '"') > 0);
// Check raw XML Output
req.setResponseParser(new NoOpResponseParser("xml"));
query.set("fl", "id,json_s:[json],xml_s:[xml]");
query.set(CommonParams.WT, "xml");
req = new QueryRequest(query);
req.setResponseParser(new NoOpResponseParser("xml"));
resp = client.request(req);
raw = (String) resp.get("response");
// Check that we get raw xml and json is escaped
// escaped
assertTrue(raw.indexOf('>' + rawJson + '<') > 0);
// raw xml
assertTrue(raw.indexOf(rawXml) > 0);
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class SolrExampleTests method testUpdateRequestWithParameters.
@Test
public void testUpdateRequestWithParameters() throws Exception {
SolrClient client = createNewSolrClient();
client.deleteByQuery("*:*");
client.commit();
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "id1");
UpdateRequest req = new UpdateRequest();
req.setParam("overwrite", "false");
req.add(doc);
client.request(req);
client.request(req);
client.commit();
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
QueryResponse rsp = client.query(query);
SolrDocumentList out = rsp.getResults();
assertEquals(2, out.getNumFound());
if (!(client instanceof EmbeddedSolrServer)) {
/* Do not close in case of using EmbeddedSolrServer,
* as that would close the CoreContainer */
client.close();
}
}
Aggregations