use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.
the class CloudMLTQParserTest method testMinDF.
@Test
public void testMinDF() throws Exception {
QueryResponse queryResponse = cluster.getSolrClient().query(COLLECTION, new SolrQuery("{!mlt qf=lowerfilt_u mindf=0 mintf=1}3").setShowDebugInfo(true));
SolrDocumentList solrDocuments = queryResponse.getResults();
int[] expectedIds = new int[] { 29, 27, 26, 28 };
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);
String[] expectedQueryStrings = new String[] { "+(lowerfilt_u:bmw lowerfilt_u:usa) -id:3", "+(lowerfilt_u:usa lowerfilt_u:bmw) -id:3" };
String[] actualParsedQueries;
if (queryResponse.getDebugMap().get("parsedquery") instanceof String) {
String parsedQueryString = (String) queryResponse.getDebugMap().get("parsedquery");
assertTrue(parsedQueryString.equals(expectedQueryStrings[0]) || parsedQueryString.equals(expectedQueryStrings[1]));
} else {
actualParsedQueries = ((ArrayList<String>) queryResponse.getDebugMap().get("parsedquery")).toArray(new String[0]);
Arrays.sort(actualParsedQueries);
assertArrayEquals(expectedQueryStrings, actualParsedQueries);
}
}
use of org.apache.solr.client.solrj.response.QueryResponse 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.client.solrj.response.QueryResponse 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.client.solrj.response.QueryResponse 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.client.solrj.response.QueryResponse in project lucene-solr by apache.
the class SolrExampleTests method testUpdateField.
@Test
public void testUpdateField() throws Exception {
//no versions
SolrClient client = getSolrClient();
client.deleteByQuery("*:*");
client.commit();
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("name", "gadget");
doc.addField("price", 1);
client.add(doc);
client.commit();
SolrQuery q = new SolrQuery("*:*");
q.setFields("id", "price", "name", "_version_");
QueryResponse resp = client.query(q);
assertEquals("Doc count does not match", 1, resp.getResults().getNumFound());
Long version = (Long) resp.getResults().get(0).getFirstValue("_version_");
assertNotNull("no version returned", version);
assertEquals(1.0f, resp.getResults().get(0).getFirstValue("price"));
//update "price" with incorrect version (optimistic locking)
//need better api for this???
HashMap<String, Object> oper = new HashMap<>();
oper.put("set", 100);
doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("_version_", version + 1);
doc.addField("price", oper);
try {
client.add(doc);
if (client instanceof HttpSolrClient) {
//XXX concurrent client reports exceptions differently
fail("Operation should throw an exception!");
} else {
//just to be sure the client has sent the doc
client.commit();
ErrorTrackingConcurrentUpdateSolrClient concurrentClient = (ErrorTrackingConcurrentUpdateSolrClient) client;
assertNotNull("ConcurrentUpdateSolrClient did not report an error", concurrentClient.lastError);
assertTrue("ConcurrentUpdateSolrClient did not report an error", concurrentClient.lastError.getMessage().contains("Conflict"));
}
} catch (SolrException se) {
assertTrue("No identifiable error message", se.getMessage().contains("version conflict for unique"));
}
//update "price", use correct version (optimistic locking)
doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("_version_", version);
doc.addField("price", oper);
client.add(doc);
client.commit();
resp = client.query(q);
assertEquals("Doc count does not match", 1, resp.getResults().getNumFound());
assertEquals("price was not updated?", 100.0f, resp.getResults().get(0).getFirstValue("price"));
assertEquals("no name?", "gadget", resp.getResults().get(0).getFirstValue("name"));
//update "price", no version
oper.put("set", 200);
doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("price", oper);
client.add(doc);
client.commit();
resp = client.query(q);
assertEquals("Doc count does not match", 1, resp.getResults().getNumFound());
assertEquals("price was not updated?", 200.0f, resp.getResults().get(0).getFirstValue("price"));
assertEquals("no name?", "gadget", resp.getResults().get(0).getFirstValue("name"));
}
Aggregations