public long getNumFound() { return ids.matches(); }
/** * Debugs the given query command. * * @param cmd the query command. */ public void debugQuery(final QueryCommand cmd, final SolrIndexSearcher.QueryResult result) { if (logger.isDebugEnabled()) { final StringBuilder builder = new StringBuilder("*:*"); for (final Query filter : cmd.getFilterList()) { builder.append(" & ").append(filter); } logger.debug(createMessage( MessageCatalog._00109_SOLR_QUERY, builder.toString(), result.getDocList().size(), result.getDocList().matches())); } } }
private long getResultNumFound (SolrQueryResponse rsp) { Object docs = response.getValues().get("response"); if (docs != null) { if (docs instanceof DocList) { return ((DocList)docs).matches(); } else if (docs instanceof SolrDocumentList) { return ((SolrDocumentList)docs).getNumFound(); } } return 0; }
@Override protected boolean _containsGraph(final Node graphNode) { final SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand(); cmd.setQuery(new MatchAllDocsQuery()); cmd.setLen(0); cmd.setFilterList(new TermQuery(new Term(Field.C, asNtURI(graphNode)))); final SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult(); try { request.getSearcher().search(result, cmd); return result.getDocListAndSet().docList.matches() > 0; } catch (final Exception exception) { LOGGER.error(MessageCatalog._00113_NWS_FAILURE, exception); throw new SolrException(ErrorCode.SERVER_ERROR, exception); } } }
@Override protected int graphBaseSize() { final SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult(); try { return searcher.search(result, graphSizeQueryCommand()).getDocListAndSet().docList.matches(); } catch (final Exception exception) { LOGGER.error(MessageCatalog._00113_NWS_FAILURE, exception); throw new SolrException(ErrorCode.SERVER_ERROR, exception); } }
public PageTool(SolrQueryRequest request, SolrQueryResponse response) { String rows = request.getParams().get("rows"); if (rows != null) { results_per_page = Integer.parseInt(rows); } //TODO: Handle group by results Object docs = response.getResponse(); if (docs != null) { if (docs instanceof DocSlice) { results_found = ((DocSlice) docs).matches(); start = ((DocSlice) docs).offset(); } else if(docs instanceof ResultContext) { DocList dl = ((ResultContext) docs).getDocList(); results_found = dl.matches(); start = dl.offset(); } else if(docs instanceof SolrDocumentList) { SolrDocumentList doc_list = (SolrDocumentList) docs; results_found = doc_list.getNumFound(); start = doc_list.getStart(); } else { throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Unknown response type "+docs+". Expected one of DocSlice, ResultContext or SolrDocumentList"); } } page_count = (int) Math.ceil(results_found / (double) results_per_page); current_page_number = (int) Math.ceil(start / (double) results_per_page) + (page_count > 0 ? 1 : 0); }
private MLTResult expandQueryAndReExecute(SolrQueryResponse rsp, SolrParams params, int maxDocumentsToMatch, int flags, String q, Query seedQuery, SortSpec sortSpec, List<Query> targetFqFilters, List<Query> mltFqFilters, SolrIndexSearcher searcher, UnsupervisedFeedbackHelper uff, int start, int rows) throws IOException, SyntaxError { boolean includeMatch = params.getBool(UnsupervisedFeedbackParams.MATCH_INCLUDE, true); int matchOffset = params.getInt(UnsupervisedFeedbackParams.MATCH_OFFSET, 0); // Find the base match DocList match = searcher.getDocList(seedQuery, targetFqFilters, null, matchOffset, maxDocumentsToMatch, flags); // only get the first one... if(match.matches() == 0){ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, String.format("Unsupervised feedback handler was unable to find any documents matching the seed query: '%s'.", q)); } if (includeMatch) { rsp.add("match", match); } // This is an iterator, but we only handle the first match DocIterator iterator = match.iterator(); MLTResult mltResult = null; if (iterator.hasNext()) { // do a MoreLikeThis query for each document in results mltResult = uff.expandQueryAndReExecute(iterator, seedQuery, start, rows, mltFqFilters, flags, sortSpec.getSort()); } return mltResult; }
private MLTResult getMoreLikeTheseFromQuery(SolrQueryResponse rsp, SolrParams params, int flags, String q, Query query, SortSpec sortSpec, List<Query> targetFqFilters, List<Query> mltFqFilters, SolrIndexSearcher searcher, MoreLikeThisHelper mlt, int start, int rows) throws IOException, SyntaxError { boolean includeMatch = params.getBool(MoreLikeThisParams.MATCH_INCLUDE, true); int matchOffset = params.getInt(MoreLikeThisParams.MATCH_OFFSET, 0); // Find the base match DocList match = searcher.getDocList(query, targetFqFilters, null, matchOffset, 10000, flags); // only get the first one... if(match.matches() == 0){ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, String.format("MoreLikeThis was unable to find any documents matching the query: '%s'.", q)); } if (includeMatch) { rsp.add("match", match); } // This is an iterator, but we only handle the first match DocIterator iterator = match.iterator(); if (iterator.hasNext()) { // do a MoreLikeThis query for each document in results return mlt.getMoreLikeTheseFromDocs(iterator, start, rows, mltFqFilters, flags, sortSpec.getSort()); } return null; }
@Override public long getStatistic(final Node s, final Node p, final Node o) { final SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult(); try { return searcher.search( result, queryCommand(Triple.create(s, p, o), sortSpec())).getDocListAndSet().docList.matches(); } catch (final Exception exception) { LOGGER.error(MessageCatalog._00113_NWS_FAILURE, exception); throw new SolrException(ErrorCode.SERVER_ERROR, exception); } } }
public void writeDocList(DocList ids, JavaBinCodec codec) throws IOException { codec.writeTag(JavaBinCodec.SOLRDOCLST); List l = new ArrayList(3); l.add((long) ids.matches()); l.add((long) ids.offset()); Float maxScore = null; if (includeScore && ids.hasScores()) { maxScore = ids.maxScore(); } l.add(maxScore); codec.writeArray(l); int sz = ids.size(); codec.writeTag(JavaBinCodec.ARR, sz); if(searcher == null) searcher = solrQueryRequest.getSearcher(); if(schema == null) schema = solrQueryRequest.getSchema(); DocIterator iterator = ids.iterator(); for (int i = 0; i < sz; i++) { int id = iterator.nextDoc(); Document doc = searcher.doc(id, returnFields); SolrDocument sdoc = getDoc(doc); if (includeScore && ids.hasScores()) { sdoc.addField("score", iterator.score()); } codec.writeSolrDocument(sdoc); } }
test(results.size() <= results.matches()); test((start==0 && limit>=results.matches()) ? results.size()==results.matches() : true ); test(hits.length() == results.matches()); test(results2.size()==results.size() && results2.matches()==results.matches()); DocList results3 = req.getSearcher().getDocList(query,query,null,start,limit); test(results3.size()==results.size() && results3.matches()==results.matches()); test( both.docList.matches() == both.docSet.size() ); test( (start==0 && both.docSet.size() <= limit) ? both.docSet.equals(both.docList) : true); test( both2.docList.matches() == 0 ); test( both2.docSet.size() == 0 );
writeInt(null,ids.matches()); writeKey("start",false); writeInt(null,ids.offset());
nl.add("numFound", rb.getResults().docList.matches()); nl.add("maxScore", rb.getResults().docList.maxScore());
rsp.getToLog().add("hits", rb.getResults().docList.matches());
list.setNumFound(docs.matches()); list.setMaxScore(docs.maxScore()); list.setStart(docs.offset());
list.setNumFound(docs.matches()); list.setMaxScore(docs.maxScore()); list.setStart(docs.offset());
incLevel(); writeKey("numFound",false); writeInt(null,ids.matches()); writeMapSeparator(); writeKey("start",false);