List<Integer> docIds = new ArrayList<Integer>(list.size());
public int getCount() { return ids.size(); }
/** * Takes a list of docs (the doc ids actually), and returns an array * of Documents containing all of the stored fields. */ public Document[] readDocs(DocList ids) throws IOException { Document[] docs = new Document[ids.size()]; readDocs(docs,ids); return docs; }
@Override public boolean hasNext() { final boolean hasNext = (page.size() == queryCommand.getLen() && !sentCursorMark.equals(nextCursorMark)); if (hasNext) { queryCommand.setCursorMark(nextCursorMark); currentState = executeQuery; return currentState.hasNext(); } return false; }
/** * 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())); } } }
/** * Returns a random set of documents from the index. Mainly for testing purposes. * * @param req * @param rsp * @throws IOException */ private void handleRandomSearch(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { SolrIndexSearcher searcher = req.getSearcher(); Query query = new MatchAllDocsQuery(); DocList docList = searcher.getDocList(query, getFilterQueries(req), Sort.RELEVANCE, 0, numberOfCandidateResults, 0); int paramRows = Math.min(req.getParams().getInt("rows", defaultNumberOfResults), docList.size()); if (docList.size() < 1) { rsp.add("Error", "No documents in index"); } else { LinkedList list = new LinkedList(); while (list.size() < paramRows) { DocList auxList = docList.subset((int) (Math.random() * docList.size()), 1); Document doc = null; for (DocIterator it = auxList.iterator(); it.hasNext(); ) { doc = searcher.doc(it.nextDoc()); } if (!list.contains(doc)) { list.add(doc); } } rsp.addResponse(list); } }
@Override public boolean hasNext() { try { final SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult(); searcher.search(result, queryCommand); LOGGER.debugQuery(queryCommand, result); sentCursorMark = queryCommand.getCursorMark(); nextCursorMark = result.getNextCursorMark(); page = result.getDocListAndSet().docList; return page.size() > 0; } catch (final Exception exception) { throw new RuntimeException(exception); } }
protected void doPrefetch(ResponseBuilder rb) throws IOException { SolrQueryRequest req = rb.req; SolrQueryResponse rsp = rb.rsp; //pre-fetch returned documents if (!req.getParams().getBool(ShardParams.IS_SHARD,false) && rb.getResults().docList != null && rb.getResults().docList.size()<=50) { // TODO: this may depend on the highlighter component (or other components?) SolrPluginUtils.optimizePreFetchDocs(rb.getResults().docList, rb.getQuery(), req, rsp); } }
public void writeDocs(boolean includeScore, Set<String> fields) throws IOException { SolrIndexSearcher searcher = request.getSearcher(); DocIterator iterator = ids.iterator(); int sz = ids.size(); includeScore = includeScore && ids.hasScores(); for (int i=0; i<sz; i++) { int id = iterator.nextDoc(); Document doc = searcher.doc(id, fields); writeDoc(null, doc, fields, (includeScore ? iterator.score() : 0.0f), includeScore); } } }, fields );
@Override public boolean hasNext() { try { final SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult(); searcher.search(result, queryCommand); LOGGER.debugQuery(queryCommand, result); consumer.onDocSet(result.getDocListAndSet().docSet); queryCommand.clearFlags(SolrIndexSearcher.GET_DOCSET); sentCursorMark = queryCommand.getCursorMark(); nextCursorMark = result.getNextCursorMark(); page = result.getDocListAndSet().docList; return page.size() > 0; } catch (final Exception exception) { throw new RuntimeException(exception); } }
List<Document> result = new ArrayList<Document>(docList.size()); FieldSelector fieldSelector = new SetBasedFieldSelector(fieldsToLoad, Collections.emptySet());
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); } }
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException { QueryResultKey key = (QueryResultKey)oldKey; int nDocs=1; // request 1 doc and let caching round up to the next window size... // unless the window size is <=1, in which case we will pick // the minimum of the number of documents requested last time and // a reasonable number such as 40. // TODO: make more configurable later... if (queryResultWindowSize<=1) { DocList oldList = (DocList)oldVal; int oldnDocs = oldList.offset() + oldList.size(); // 40 has factors of 2,4,5,10,20 nDocs = Math.min(oldnDocs,40); } int flags=NO_CHECK_QCACHE | key.nc_flags; QueryCommand qc = new QueryCommand(); qc.setQuery(key.query) .setFilterList(key.filters) .setSort(key.sort) .setLen(nDocs) .setSupersetMaxDoc(nDocs) .setFlags(flags); QueryResult qr = new QueryResult(); newSearcher.getDocListC(qr,qc); return true; } }
checkAvailable(name, engine); DocListAndSet results = rb.getResults(); Map<SolrDocument,Integer> docIds = new HashMap<>(results.docList.size()); SolrDocumentList solrDocList = docListToSolrDocumentList( results.docList, rb.req.getSearcher(), engine.getFieldsToLoad(rb.req), docIds);
/** * Generates an list of Explanations for each item in a list of docs. * * @param query The Query you want explanations in the context of * @param docs The Documents you want explained relative that query */ public static NamedList getExplainList(Query query, DocList docs, SolrIndexSearcher searcher, IndexSchema schema) throws IOException { NamedList explainList = new SimpleOrderedMap(); DocIterator iterator = docs.iterator(); for (int i=0; i<docs.size(); i++) { int id = iterator.nextDoc(); Explanation explain = searcher.explain(query, id); Document doc = searcher.doc(id); String strid = schema.printableUniqueKey(doc); // String docname = ""; // if (strid != null) docname="id="+strid+","; // docname = docname + "internal_docid="+id; explainList.add(strid, "\n" +explain.toString()); } return explainList; }
for (int i=0; i<docs.size(); i++) { searcher.doc(iter.nextDoc(), fieldFilter);
if (c!=null){ DocList dList = c.docs; if (dList.size()<1){ nameValuePairs.remove("response"); rb.rsp.setAllValues(nameValuePairs);