use of org.apache.solr.common.SolrDocumentList in project Xponents by OpenSextant.
the class SolrProxy method searchGazetteer.
/**
* Search an OpenSextant solr gazetteer.
*
* @param index solr server handle
* @param qparams search parameters
* @return list of places
* @throws SolrServerException on err
*/
public static List<Place> searchGazetteer(SolrServer index, SolrParams qparams) throws SolrServerException {
QueryResponse response = index.query(qparams, SolrRequest.METHOD.GET);
List<Place> places = new ArrayList<>();
SolrDocumentList docList = response.getResults();
for (SolrDocument solrDoc : docList) {
places.add(SolrProxy.createPlace(solrDoc));
}
return places;
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class TestContentStreamDataSource method testSimple.
@Test
public void testSimple() throws Exception {
DirectXmlRequest req = new DirectXmlRequest("/dataimport", xml);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command", "full-import");
params.set("clean", "false");
req.setParams(params);
try (HttpSolrClient solrClient = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
solrClient.request(req);
ModifiableSolrParams qparams = new ModifiableSolrParams();
qparams.add("q", "*:*");
QueryResponse qres = solrClient.query(qparams);
SolrDocumentList results = qres.getResults();
assertEquals(2, results.getNumFound());
SolrDocument doc = results.get(0);
assertEquals("1", doc.getFieldValue("id"));
assertEquals("Hello C1", ((List) doc.getFieldValue("desc")).get(0));
}
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class MockSolrEntityProcessor method buildIterator.
//@Override
//protected SolrDocumentList doQuery(int start) {
// queryCount++;
// return getDocs(start, rows);
// }
@Override
protected void buildIterator() {
if (rowIterator == null || (!rowIterator.hasNext() && ((SolrDocumentListIterator) rowIterator).hasMoreRows())) {
queryCount++;
SolrDocumentList docs = getDocs(start, rows);
rowIterator = new SolrDocumentListIterator(docs);
start += docs.size();
}
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class MockSolrEntityProcessor method getDocs.
private SolrDocumentList getDocs(int start, int rows) {
SolrDocumentList docs = new SolrDocumentList();
docs.setNumFound(docsData.size());
docs.setStart(start);
int endIndex = start + rows;
int end = docsData.size() < endIndex ? docsData.size() : endIndex;
for (int i = start; i < end; i++) {
SolrDocument doc = new SolrDocument();
SolrTestCaseJ4.Doc testDoc = docsData.get(i);
doc.addField("id", testDoc.id);
doc.addField("description", testDoc.getValues("description"));
docs.add(doc);
}
return docs;
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class QueryComponent method returnFields.
protected void returnFields(ResponseBuilder rb, ShardRequest sreq) {
if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0;
String keyFieldName = rb.req.getSchema().getUniqueKeyField().getName();
boolean removeKeyField = !rb.rsp.getReturnFields().wantsField(keyFieldName);
if (rb.rsp.getReturnFields().getFieldRenames().get(keyFieldName) != null) {
// if id was renamed we need to use the new name
keyFieldName = rb.rsp.getReturnFields().getFieldRenames().get(keyFieldName);
}
for (ShardResponse srsp : sreq.responses) {
if (srsp.getException() != null) {
// Don't try to get the documents if there was an exception in the shard
if (rb.req.getParams().getBool(ShardParams.SHARDS_INFO, false)) {
@SuppressWarnings("unchecked") NamedList<Object> shardInfo = (NamedList<Object>) rb.rsp.getValues().get(ShardParams.SHARDS_INFO);
@SuppressWarnings("unchecked") SimpleOrderedMap<Object> nl = (SimpleOrderedMap<Object>) shardInfo.get(srsp.getShard());
if (nl.get("error") == null) {
// Add the error to the shards info section if it wasn't added before
Throwable t = srsp.getException();
if (t instanceof SolrServerException) {
t = ((SolrServerException) t).getCause();
}
nl.add("error", t.toString());
StringWriter trace = new StringWriter();
t.printStackTrace(new PrintWriter(trace));
nl.add("trace", trace.toString());
}
}
continue;
}
SolrDocumentList docs = (SolrDocumentList) srsp.getSolrResponse().getResponse().get("response");
for (SolrDocument doc : docs) {
Object id = doc.getFieldValue(keyFieldName);
ShardDoc sdoc = rb.resultIds.get(id.toString());
if (sdoc != null) {
if (returnScores) {
doc.setField("score", sdoc.score);
} else {
// Score might have been added (in createMainQuery) to shard-requests (and therefore in shard-response-docs)
// Remove score if the outer request did not ask for it returned
doc.remove("score");
}
if (removeKeyField) {
doc.removeFields(keyFieldName);
}
rb.getResponseDocs().set(sdoc.positionInResponse, doc);
}
}
}
}
}
Aggregations