/** * Retrieve the {@link Document} instance corresponding to the document id. */ public Document doc(int i) throws IOException { return doc(i, (Set<String>)null); }
/** * 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); } }
protected NamedList getCollapseGroupResult(int docId, NamedList result) { String uniqueIdFieldname = searcher.getSchema().getUniqueKeyField().getName(); try { String schemaId = searcher.doc(docId).get(uniqueIdFieldname); NamedList collapseGroupResult = (NamedList) result.get(schemaId); if (collapseGroupResult == null) { collapseGroupResult = new NamedList(); result.add(schemaId, collapseGroupResult); } return collapseGroupResult; } catch (IOException e) { throw new RuntimeException(e); } } }
private Map<String, Set<String>> findParentIdsForNodes(SolrIndexSearcher searcher, Collection<String> nodeIds) throws IOException { Map<String, Set<String>> parentIds = new HashMap<>(); LOGGER.debug("Looking up parents for {} nodes", nodeIds.size()); Query filter = buildFilterQuery(getNodeField(), nodeIds); LOGGER.trace("Filter query: {}", filter); DocSet docs = searcher.getDocSet(filter); for (DocIterator it = docs.iterator(); it.hasNext(); ) { Document doc = searcher.doc(it.nextDoc(), docFields); String nodeId = doc.get(getNodeField()); Set<String> parentIdValues = new HashSet<>(Arrays.asList(doc.getValues(parentField))); parentIds.put(nodeId, parentIdValues); // Record the label, if required if (isLabelRequired(nodeId)) { recordLabel(nodeId, doc.getValues(getLabelField())); } } return parentIds; }
Document doc = searcher.doc(it.nextDoc(), docFields); String nodeId = doc.get(getNodeField());
@Override public void write(Writer w, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { SolrIndexSearcher searcher = req.getSearcher(); NamedList nl = rsp.getValues(); int sz = nl.size(); for (int li = 0; li < sz; li++) { Object val = nl.getVal(li); if (val instanceof DocList) { //<co id="co.fuzzy.type-ahead.doclist"/> DocList dl = (DocList) val; DocIterator iterator = dl.iterator(); w.append("<ul>\n"); while (iterator.hasNext()) { int id = iterator.nextDoc(); Document doc = searcher.doc(id, fields); //<co id="co.fuzzy.type-ahead.search"/> String name = doc.get("word"); w.append("<li>" + name + "</li>\n"); } w.append("</ul>\n"); } } } }
@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 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 );
/** * 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); } }
org.apache.lucene.document.Document doc = searcher.doc(id, fieldSelector); String snippet = getValue(doc, snippetField);
SolrDocumentList documentList = new SolrDocumentList(); for (DocIdSetIterator iterator = bitSet.iterator(); iterator.nextDoc() != DocIdSetIterator.NO_MORE_DOCS;) { Document luceneDocument = searcher.doc(iterator.docID(), includeCollapsedDocumentsFields);
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); } }
/** * 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; }
searcher.doc(iter.nextDoc(), fieldFilter);
DocList docs = (DocList)o; for (DocIterator iter = docs.iterator(); iter.hasNext();) { newSearcher.doc(iter.nextDoc());
for (int i=0; i<sz; i++) { int id = iterator.nextDoc(); Document doc = searcher.doc(id, fields); writeKey(i, false); writeDoc(null, doc, fields, (includeScore ? iterator.score() : 0.0f), includeScore);
int docid = dit.nextDoc(); Document luceneDoc = searcher.doc(docid, fields); SolrDocument doc = new SolrDocument();
int docid = dit.nextDoc(); Document luceneDoc = searcher.doc(docid, fields); SolrDocument doc = new SolrDocument(); db.loadStoredFields(doc, luceneDoc);
for (int i=0; i<sz; i++) { int id = iterator.nextDoc(); Document doc = searcher.doc(id, fields);
Document doc = searcher.doc( top.scoreDocs[0].doc ); Fieldable fld = doc.getFieldable( fieldName ); if( fld != null ) {