@Override public void process(OutputStream out) throws IOException { IOUtils.write("<docs>", out, StandardCharsets.UTF_8); for (SolrDocument doc : response.getResults()) { final String xml = ClientUtils.toXML(toSolrInputDocument(doc)); IOUtils.write(xml, out, StandardCharsets.UTF_8); } IOUtils.write("</docs>", out, StandardCharsets.UTF_8); }
@Override public List<SolrDocument> getResponseDocuments(QueryResponse response) { List<SolrDocument> docs; if (response.getGroupResponse() == null) { docs = response.getResults(); } else { docs = new ArrayList<SolrDocument>(); GroupResponse gr = response.getGroupResponse(); for (GroupCommand gc : gr.getValues()) { for (Group g : gc.getValues()) { for (SolrDocument d : g.getResult()) { docs.add(d); } } } } return docs; }
logger.debug("Executed query [{}] in {} ms", query.getQuery(), response.getElapsedTime()); int totalHits = response.getResults().size(); if (!query.hasLimit() && totalHits >= maxResults) { logger.warn("Query result set truncated to first [{}] elements for query: {}", maxResults, query); for (SolrDocument hit : response.getResults()) { double score = Double.parseDouble(hit.getFieldValue("score").toString()); result.add(new RawQuery.Result<String>(hit.getFieldValue(keyIdField).toString(), score));
SolrDocumentList results = response.getResults();
SolrDocumentList results = response.getResults();
logger.debug("Executed query [{}] in {} ms", query.getCondition(), response.getElapsedTime()); int totalHits = response.getResults().size(); for (SolrDocument hit : response.getResults()) { result.add(hit.getFieldValue(keyIdField).toString());
SolrDocumentList results = response.getResults(); if ((results != null) && (results.getNumFound() > 0)) { for (String field : results.get(0).getFieldNames()) {
SolrDocumentList results = response.getResults(); if ((results != null) && (results.getNumFound() > 0)) { for (String field : results.get(0).getFieldNames()) {
final SolrDocumentList documentList = response.getResults(); if (response.getResults().size() > 0) { final SolrDocument lastSolrDocument = documentList.get(response.getResults().size()-1); final String latestDateValue = df.format(lastSolrDocument.get(dateField)); final String newCursorMark = response.getNextCursorMark(); for (SolrDocument doc : response.getResults()) { doc.removeFields(dateField); .asControllerService(RecordSetWriterFactory.class); final RecordSchema schema = writerFactory.getSchema(null, null); final RecordSet recordSet = SolrUtils.solrDocumentsToRecordSet(response.getResults(), schema); final StringBuffer mimeType = new StringBuffer(); flowFile = session.write(flowFile, new OutputStreamCallback() { continuePaging.set(response.getResults().size() == Integer.parseInt(context.getProperty(BATCH_SIZE).getValue()));
timer.stop(); final Long totalNumberOfResults = response.getResults().getNumFound(); flowFileResponse = session.putAllAttributes(flowFileResponse, responseAttributes); if (response.getResults().size() > 0) { .asControllerService(RecordSetWriterFactory.class); final RecordSchema schema = writerFactory.getSchema(flowFileResponse.getAttributes(), null); final RecordSet recordSet = SolrUtils.solrDocumentsToRecordSet(response.getResults(), schema); final StringBuffer mimeType = new StringBuffer(); flowFileResponse = session.write(flowFileResponse, out -> {
import org.apache.noggit.JSONUtil; SolrQuery sQuery = new SolrQuery(); sQuery.setQuery("name:test"); QueryResponse resp = server.query(sQuery); SolrDocumentList docs = resp.getResults(); String returnValue = JSONUtil.toJSON(docs); //this has the json documents
response = solrConfiguration.getServer().query(solrQuery, getSolrQueryMethod()); responseDocuments = getResponseDocuments(response); numResults = (int) response.getResults().getNumFound();
@Override public Document getLatest(String guid, String sensorType) throws IOException { if (MetaAlertConstants.METAALERT_TYPE.equals(sensorType)) { // Unfortunately, we can't just defer to the indexDao for this. Child alerts in Solr end up // having to be dug out. String guidClause = Constants.GUID + ":" + guid; SolrQuery query = new SolrQuery(); query.setQuery(guidClause) .setFields("*", "[child parentFilter=" + guidClause + " limit=999]"); try { QueryResponse response = solrDao.getSolrClient(solrDao.getZkHosts()) .query(METAALERTS_COLLECTION, query); // GUID is unique, so it's definitely the first result if (response.getResults().size() == 1) { SolrDocument result = response.getResults().get(0); return SolrUtilities.toDocument(result); } else { return null; } } catch (SolrServerException e) { throw new IOException("Unable to retrieve metaalert", e); } } else { return solrDao.getLatest(guid, sensorType); } }
protected SearchResponse buildSearchResponse( SearchRequest searchRequest, QueryResponse solrResponse) { SearchResponse searchResponse = new SearchResponse(); SolrDocumentList solrDocumentList = solrResponse.getResults(); searchResponse.setTotal(solrDocumentList.getNumFound()); // search hits --> search results List<SearchResult> results = solrDocumentList.stream() .map(solrDocument -> SolrUtilities.getSearchResult(solrDocument, searchRequest.getFields(), accessConfig.getIndexSupplier())) .collect(Collectors.toList()); searchResponse.setResults(results); // handle facet fields List<String> facetFields = searchRequest.getFacetFields(); if (facetFields != null) { searchResponse.setFacetCounts(getFacetCounts(facetFields, solrResponse)); } if (LOG.isDebugEnabled()) { String response; try { response = JSONUtils.INSTANCE.toJSON(searchResponse, false); } catch (JsonProcessingException e) { response = e.getMessage(); } LOG.debug("Built search response; response={}", response); } return searchResponse; }
QueryResponse rsp = solrClient.query(METAALERTS_COLLECTION, solrQuery); String nextCursorMark = rsp.getNextCursorMark(); rsp.getResults().stream() .map(solrDocument -> SolrUtilities.getSearchResult(solrDocument, null, solrSearchDao.getAccessConfig().getIndexSupplier()))
/** * Returns a list of Documents representing the specified Resource (empty * when no such Document exists yet). Each document represent a set of * statements with the specified Resource as a subject, which are stored in a * specific context */ private SolrDocumentList getDocuments(SolrQuery query) throws SolrServerException, IOException { return search(query).getResults(); }
void doQuery(String expectedDocs, String... queryParams) throws Exception { Set<String> expectedIds = new HashSet<>( StrUtils.splitSmart(expectedDocs, ",", true) ); QueryResponse rsp = cloudClient.query(params(queryParams)); Set<String> obtainedIds = new HashSet<>(); for (SolrDocument doc : rsp.getResults()) { obtainedIds.add((String) doc.get("id")); } assertEquals(expectedIds, obtainedIds); }
public static SolrDocumentList query(SolrServer server, SolrQuery solrParams) throws DSpaceSolrException { try { solrParams.addSortField("item.id", ORDER.asc); QueryResponse response = server.query(solrParams); return response.getResults(); } catch (SolrServerException ex) { throw new DSpaceSolrException(ex.getMessage(), ex); } }
@Override public ObjectCount queryTotal(String query, String filterQuery) throws SolrServerException { QueryResponse queryResponse = query(query, filterQuery, null, 0, -1, null, null, null, null, null, false); ObjectCount objCount = new ObjectCount(); objCount.setCount(queryResponse.getResults().getNumFound()); return objCount; }
public Iterator<SolrDocument> getCandidates(String title) throws SolrServerException { String etitle = escape(title); //<co id="co.rm.escape"/> query.setQuery("title:\""+etitle+"\""); //<co id="co.rm.quotes"/> QueryResponse response = solr.query(query); SolrDocumentList dl = response.getResults(); return dl.iterator(); } /*