use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class TestPullReplica method testRealTimeGet.
public void testRealTimeGet() throws SolrServerException, IOException, KeeperException, InterruptedException {
// should be redirected to Replica.Type.NRT
int numReplicas = random().nextBoolean() ? 1 : 2;
CollectionAdminRequest.createCollection(collectionName, "conf", 1, numReplicas, 0, numReplicas).setMaxShardsPerNode(100).process(cluster.getSolrClient());
waitForState("Unexpected replica count", collectionName, activeReplicaCount(numReplicas, 0, numReplicas));
DocCollection docCollection = assertNumberOfReplicas(numReplicas, 0, numReplicas, false, true);
HttpClient httpClient = cluster.getSolrClient().getHttpClient();
int id = 0;
Slice slice = docCollection.getSlice("shard1");
List<String> ids = new ArrayList<>(slice.getReplicas().size());
for (Replica rAdd : slice.getReplicas()) {
try (HttpSolrClient client = getHttpSolrClient(rAdd.getCoreUrl(), httpClient)) {
client.add(new SolrInputDocument("id", String.valueOf(id), "foo_s", "bar"));
}
SolrDocument docCloudClient = cluster.getSolrClient().getById(collectionName, String.valueOf(id));
assertEquals("bar", docCloudClient.getFieldValue("foo_s"));
for (Replica rGet : slice.getReplicas()) {
try (HttpSolrClient client = getHttpSolrClient(rGet.getCoreUrl(), httpClient)) {
SolrDocument doc = client.getById(String.valueOf(id));
assertEquals("bar", doc.getFieldValue("foo_s"));
}
}
ids.add(String.valueOf(id));
id++;
}
SolrDocumentList previousAllIdsResult = null;
for (Replica rAdd : slice.getReplicas()) {
try (HttpSolrClient client = getHttpSolrClient(rAdd.getCoreUrl(), httpClient)) {
SolrDocumentList allIdsResult = client.getById(ids);
if (previousAllIdsResult != null) {
assertTrue(compareSolrDocumentList(previousAllIdsResult, allIdsResult));
} else {
// set the first response here
previousAllIdsResult = allIdsResult;
assertEquals("Unexpected number of documents", ids.size(), allIdsResult.getNumFound());
}
}
id++;
}
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class DistributedExpandComponentTest method assertExpandGroupCountAndOrder.
private void assertExpandGroupCountAndOrder(String group, int count, Map<String, SolrDocumentList> expandedResults, String... docs) throws Exception {
SolrDocumentList results = expandedResults.get(group);
if (results == null) {
throw new Exception("Group Not Found:" + group);
}
if (results.size() != count) {
throw new Exception("Expected Count " + results.size() + " Not Found:" + count);
}
for (int i = 0; i < docs.length; i++) {
String id = docs[i];
SolrDocument doc = results.get(i);
if (!doc.getFieldValue("id").toString().equals(id)) {
throw new Exception("Id not in results or out of order:" + id + "!=" + doc.getFieldValue("id"));
}
}
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class TestBaseStatsCache method checkResponse.
// in this case, as the number of shards increases, per-shard scores should
// remain identical
@Override
protected void checkResponse(QueryResponse controlRsp, QueryResponse shardRsp) {
System.out.println("======================= Control Response =======================");
System.out.println(controlRsp);
System.out.println("");
System.out.println("");
System.out.println("======================= Shard Response =======================");
System.out.println("");
System.out.println(shardRsp);
SolrDocumentList shardList = shardRsp.getResults();
SolrDocumentList controlList = controlRsp.getResults();
assertEquals(controlList.size(), shardList.size());
assertEquals(controlList.getNumFound(), shardList.getNumFound());
Iterator<SolrDocument> it = controlList.iterator();
Iterator<SolrDocument> it2 = shardList.iterator();
while (it.hasNext()) {
SolrDocument controlDoc = it.next();
SolrDocument shardDoc = it2.next();
assertEquals(controlDoc.getFieldValue("score"), shardDoc.getFieldValue("score"));
}
}
use of org.apache.solr.common.SolrDocument 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.common.SolrDocument 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);
}
Aggregations