private Set<Integer> getDocidsFromQuery(Query query, SolrIndexSearcher searcher, int maxRows) throws SyntaxError, IOException { DocList match = searcher.getDocList(query, null, null, 0, maxRows, 0); // only get the first one... Set<Integer> docsIds = new HashSet<Integer>(); DocIterator iterator = match.iterator(); while (iterator.hasNext()) { docsIds.add(iterator.nextDoc()); } return docsIds; }
/** * Takes a list of docs (the doc ids actually) and a set of fields to load, * and reads them into an array of Documents. */ public void readDocs(Document[] docs, DocList ids, Set<String> fields) throws IOException { DocIterator iter = ids.iterator(); for (int i=0; i<docs.length; i++) { docs[i] = doc(iter.nextDoc(), fields); } }
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() { if (iterator().hasNext()) { return true; } else { iterator = null; currentState = checkForConsumptionCompleteness; return currentState.hasNext(); } }
@Override public Triple next() { try { final int nextDocId = iterator().nextDoc(); Triple triple = null; if (consumer.requireTripleBuild()) { final Document document = searcher.doc(nextDocId, TRIPLE_FIELDS); triple = Triple.create( NTriples.asURIorBlankNode((String) document.get(Field.S)), NTriples.asURI((String) document.get(Field.P)), NTriples.asNode((String) document.get(Field.O))); } else { triple = DUMMY_TRIPLE; } consumer.afterTripleHasBeenBuilt(triple, nextDocId); return triple; } catch (final IOException exception) { throw new RuntimeException(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); } }
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; }
public void getResult(NamedList result, DocList docs, CollapseContext collapseContext) { for (DocIterator i = docs.iterator(); i.hasNext();) { int id = i.nextDoc(); Counter counter = documentHeadCount.get(id); if (counter == null) { continue; } NamedList collapsedGroupResult = getCollapseGroupResult(id, result); collapsedGroupResult.add("collapseCount", counter.getCount()); } } }
try { for (int i=0; i<docList.size(); ++i) { int docId = iter.nextDoc(); docIDsHits[i] = docId; Document doc = indexReader.document(docId);
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; }
public boolean equals(Object obj) { if (!(obj instanceof DocSet)) return false; DocSet other = (DocSet)obj; if (this.size() != other.size()) return false; if (this instanceof DocList && other instanceof DocList) { // compare ordering DocIterator i1=this.iterator(); DocIterator i2=other.iterator(); while(i1.hasNext() && i2.hasNext()) { if (i1.nextDoc() != i2.nextDoc()) return false; } return true; // don't compare matches } // if (this.size() != other.size()) return false; return this.getBits().equals(other.getBits()); }
try { for (int i=0; i<docList.size(); ++i) { int docId = iter.nextDoc(); docIDsHits[i] = docId; Document doc = indexReader.document(docId);
@Override public DocSet andNot(DocSet other) { OpenBitSet newbits = (OpenBitSet)(bits.clone()); if (other instanceof BitDocSet) { newbits.andNot(((BitDocSet)other).bits); } else { DocIterator iter = other.iterator(); while (iter.hasNext()) newbits.clear(iter.nextDoc()); } return new BitDocSet(newbits); }