use of org.apache.solr.client.solrj.SolrQuery 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.SolrQuery 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.SolrQuery 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.SolrQuery 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.SolrQuery in project lucene-solr by apache.
the class SolrIndexSplitterTest method testSplitByCores.
@Test
public void testSplitByCores() throws Exception {
// add two docs
String id1 = "dorothy";
assertU(adoc("id", id1));
String id2 = "kansas";
assertU(adoc("id", id2));
assertU(commit());
assertJQ(req("q", "*:*"), "/response/numFound==2");
List<DocRouter.Range> ranges = getRanges(id1, id2);
SolrCore core1 = null, core2 = null;
try {
core1 = h.getCoreContainer().create("split1", ImmutableMap.of("dataDir", indexDir1.getAbsolutePath(), "configSet", "minimal"));
core2 = h.getCoreContainer().create("split2", ImmutableMap.of("dataDir", indexDir2.getAbsolutePath(), "configSet", "minimal"));
LocalSolrQueryRequest request = null;
try {
request = lrf.makeRequest("q", "dummy");
SplitIndexCommand command = new SplitIndexCommand(request, null, Lists.newArrayList(core1, core2), ranges, new PlainIdRouter(), null, null);
new SolrIndexSplitter(command).split();
} finally {
if (request != null)
request.close();
}
EmbeddedSolrServer server1 = new EmbeddedSolrServer(h.getCoreContainer(), "split1");
EmbeddedSolrServer server2 = new EmbeddedSolrServer(h.getCoreContainer(), "split2");
server1.commit(true, true);
server2.commit(true, true);
assertEquals("id:dorothy should be present in split index1", 1, server1.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
assertEquals("id:kansas should not be present in split index1", 0, server1.query(new SolrQuery("id:kansas")).getResults().getNumFound());
assertEquals("id:dorothy should not be present in split index2", 0, server2.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
assertEquals("id:kansas should be present in split index2", 1, server2.query(new SolrQuery("id:kansas")).getResults().getNumFound());
} finally {
h.getCoreContainer().unload("split2");
h.getCoreContainer().unload("split1");
}
}
Aggregations