use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class CloudMLTQParserTest method testBoost.
@Test
public void testBoost() throws Exception {
QueryResponse queryResponse = cluster.getSolrClient().query(COLLECTION, new SolrQuery("{!mlt qf=lowerfilt_u boost=true}17"));
SolrDocumentList solrDocuments = queryResponse.getResults();
int[] expectedIds = new int[] { 7, 9, 13, 14, 15, 16, 20, 22, 24, 32 };
int[] actualIds = new int[solrDocuments.size()];
int i = 0;
for (SolrDocument solrDocument : solrDocuments) {
actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
}
assertArrayEquals(expectedIds, actualIds);
queryResponse = cluster.getSolrClient().query(COLLECTION, new SolrQuery("{!mlt qf=lowerfilt_u^10,lowerfilt1_u^1000 boost=false mintf=0 mindf=0}30"));
solrDocuments = queryResponse.getResults();
expectedIds = new int[] { 31, 18, 23, 13, 14, 20, 22, 32, 19, 21 };
actualIds = new int[solrDocuments.size()];
i = 0;
for (SolrDocument solrDocument : solrDocuments) {
actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
}
System.out.println("DEBUG ACTUAL IDS 1: " + Arrays.toString(actualIds));
assertArrayEquals(expectedIds, actualIds);
queryResponse = cluster.getSolrClient().query(COLLECTION, new SolrQuery("{!mlt qf=lowerfilt_u^10,lowerfilt1_u^1000 boost=true mintf=0 mindf=0}30"));
solrDocuments = queryResponse.getResults();
expectedIds = new int[] { 29, 31, 32, 18, 23, 13, 14, 20, 22, 19 };
actualIds = new int[solrDocuments.size()];
i = 0;
for (SolrDocument solrDocument : solrDocuments) {
actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
}
System.out.println("DEBUG ACTUAL IDS 2: " + Arrays.toString(actualIds));
assertArrayEquals(expectedIds, actualIds);
}
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);
}
Aggregations