Iterator<SolrDocument> iterator() { if (iterator == null) { iterator = page.iterator(); } return iterator; } };
@Override public Iterator<SearchResultDocument> iterator() { return new SearchResultDocumentIterator(solrDocs.iterator()); }
/*************************/ public ComplexResultIterator ( SolrDocumentList results ) { if ( results != null ) { numberOfResults = results.size ( ) ; iterator = results.iterator ( ) ; nextResult = iterator.hasNext ( ) ? getFieldValues ( ) : null ; } else { throw new IllegalArgumentException ( "You must pass a SolrDocumentList not null to create a ComplexResultIterator" ) ; } }
@Override public void finishStage(ResponseBuilder rb) { if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) { // We may not have been able to retrieve all the docs due to an // index change. Remove any null documents. for (Iterator<SolrDocument> iter = rb._responseDocs.iterator(); iter.hasNext();) { if (iter.next() == null) { iter.remove(); rb._responseDocs.setNumFound(rb._responseDocs.getNumFound()-1); } } rb.rsp.add("response", rb._responseDocs); } }
public SolrDocumentListIterator(SolrDocumentList solrDocumentList) { this.solrDocumentIterator = solrDocumentList.iterator(); this.numFound = solrDocumentList.getNumFound(); // SolrQuery has the start field of type int while SolrDocumentList of // type long. We are always querying with an int so we can't receive a // long as output. That's the reason why the following cast seems safe this.start = (int) solrDocumentList.getStart(); this.size = solrDocumentList.size(); }
private String findNameAndSynonyms(OntologySearcher searcher, String id, String defaultValue) throws SolrServerException { QueryResponse queryResponse = searcher.searchByChildId(id, 0, 1); String childName = null; if (queryResponse.getResults().getNumFound() > 0) { final SolrDocument solrDocument = queryResponse.getResults().iterator().next(); childName = (String) solrDocument.getFieldValue(OntologyFieldNames.CHILD_NAME); Collection<Object> fieldValues = solrDocument.getFieldValues(OntologyFieldNames.CHILDREN_SYNONYMS); synonymsStr = new HashSet<String>(); if(fieldValues != null){ for (Object fieldValue : fieldValues) { synonymsStr.add(fieldValue.toString()); } } } return childName == null ? defaultValue : childName; }
@Override public List<IDeviceLocation> getLocationsNear(double latitude, double longitude, double distance, IDateRangeSearchCriteria criteria) throws SiteWhereException { ModifiableSolrParams params = new ModifiableSolrParams(); try { QueryResponse response = getSolr().getSolrClient().query(params); SolrDocumentList docs = response.getResults(); while (docs.iterator().hasNext()) { SolrDocument doc = docs.iterator().next(); doc.getFieldNames(); } List<IDeviceLocation> results = new ArrayList<IDeviceLocation>(); return results; } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute 'getLocationsNear' query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }
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(); } /*
@Override public List<IDeviceLocation> getLocationsNear(double latitude, double longitude, double distance, IDateRangeSearchCriteria criteria) throws SiteWhereException { ModifiableSolrParams params = new ModifiableSolrParams(); try { QueryResponse response = getSolrConnection().getSolrClient().query(params); SolrDocumentList docs = response.getResults(); while (docs.iterator().hasNext()) { SolrDocument doc = docs.iterator().next(); doc.getFieldNames(); } List<IDeviceLocation> results = new ArrayList<IDeviceLocation>(); return results; } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute 'getLocationsNear' query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }
public void open() throws IOException { if(cache != null) { cloudSolrClient = cache.getCloudSolrClient(zkHost); } else { final List<String> hosts = new ArrayList<>(); hosts.add(zkHost); cloudSolrClient = new CloudSolrClient.Builder(hosts, Optional.empty()).build(); } ModifiableSolrParams params = getParams(this.props); params.remove(SORT); //Override any sort. Random rand = new Random(); int seed = rand.nextInt(); String sortField = "random_"+seed; params.add(SORT, sortField+" asc"); QueryRequest request = new QueryRequest(params); try { QueryResponse response = request.process(cloudSolrClient, collection); SolrDocumentList docs = response.getResults(); documentIterator = docs.iterator(); } catch (Exception e) { throw new IOException(e); } }
public String topSuggestion(String spelling) throws SolrServerException { query.setQuery("wordNGram:"+spelling); //<co id="co.dym.field"/> QueryResponse response = solr.query(query); SolrDocumentList dl = response.getResults(); Iterator<SolrDocument> di = dl.iterator(); float maxDistance = 0; String suggestion = null; while (di.hasNext()) { SolrDocument doc = di.next(); String word = (String) doc.getFieldValue("word"); float distance = sd.getDistance(word, spelling); //<co id="co.dym.edit"/> if (distance > maxDistance) { maxDistance = distance; suggestion = word; //<co id="co.dym.max"/> } } if (maxDistance > threshold) { //<co id="co.dym.threshold"/> return suggestion; } return null; } }
private OntologyNames extractNamesAndSynonymsFrom(QueryResponse response) { if (response.getResults().getNumFound() > 0) { final SolrDocument solrDocument = response.getResults().iterator().next(); String childName = (String) solrDocument.getFieldValue(OntologyFieldNames.CHILD_NAME); OntologyNames ontologyNames = new OntologyNames(childName, (String) solrDocument.getFieldValue(OntologyFieldNames.CHILD_ID)); Collection<Object> fieldValues = solrDocument.getFieldValues(OntologyFieldNames.CHILDREN_SYNONYMS); Set<String> synonymsStr = ontologyNames.getSynonyms(); if(fieldValues != null){ for (Object fieldValue : fieldValues) { synonymsStr.add(fieldValue.toString()); } } return ontologyNames; } return null; }
this.solrDataStore.getLogger().log(Level.FINE, solrQuery.toString()); this.solrDocIterator = rsp.getResults().iterator(); nextCursorMark = rsp.getNextCursorMark(); next = this.solrDocIterator.hasNext();
SolrDocumentList docs = rsp.getResults(); Iterator iter = docs.iterator(); List<DSpaceObject> result = new ArrayList<DSpaceObject>(); while (iter.hasNext()) {
public void open() throws IOException { cloudSolrClient = cache.getCloudSolrClient(zkHost); ModifiableSolrParams params = getParams(this.props); StringBuilder builder = new StringBuilder(); for(String key : mltParams) { if(params.get(key) != null) { builder.append(" " + key + "=" + params.get(key)); params.remove(key); } } String k = params.get("k"); if(k != null) { params.add(ROWS, k); params.remove(k); } params.add(Q, "{!mlt"+builder.toString()+"}"+id); QueryRequest request = new QueryRequest(params); try { QueryResponse response = request.process(cloudSolrClient, collection); SolrDocumentList docs = response.getResults(); documentIterator = docs.iterator(); } catch (Exception e) { throw new IOException(e); } }
new AdaptingIterator<SolrDocument,String>(response.getResults().iterator(),
new AdaptingIterator<SolrDocument,String>(response.getResults().iterator(),
SolrDocumentList docs = rsp.getResults(); Iterator iter = docs.iterator(); List<DSpaceObject> result = new ArrayList<DSpaceObject>(); while (iter.hasNext()) {
int numFound = 0; List<SolrDocument> slice = new ArrayList<SolrDocument>(); for (Iterator<SolrDocument> it = results.iterator(); it.hasNext(); ) { SolrDocument sdoc = it.next(); Float score = (Float) sdoc.getFieldValue("score");
/** * Map solr query response to search results. * * @param queryResponse * the query response * @return the search results * */ public FulltextSearchResults mapSolrToSearchResults(final QueryResponse queryResponse) { if (queryResponse == null) { throw new GeneralServiceException("Null QueryResponse given."); } final SolrDocumentList responseDocumentList = queryResponse.getResults(); final Float maxScore = getMaxScoreToNormalize(responseDocumentList); if (LOG.isTraceEnabled()) { LOG.trace("Mapping response: {}", queryResponse); } final Map<String, Map<String, List<String>>> highlighting = queryResponse.getHighlighting(); final Iterator<SolrDocument> i = responseDocumentList.iterator(); // collect results final List<FulltextSearchResult> results = collectSearchResults(i, highlighting, maxScore); // create search results object String cursorMark = queryResponse.getNextCursorMark(); final FulltextSearchResults searchResults = new FulltextSearchResultsImpl(results, (int) responseDocumentList.getStart(), (int) responseDocumentList.getNumFound(), cursorMark); // add facet info searchResults.setFacetResult(FacetBuilder.mapFacetResult(queryResponse)); return searchResults; }