本文整理汇总了Java中org.apache.solr.search.DocIterator类的典型用法代码示例。如果您正苦于以下问题:Java DocIterator类的具体用法?Java DocIterator怎么用?Java DocIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DocIterator类属于org.apache.solr.search包,在下文中一共展示了DocIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: for
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
/**
* Generates an NamedList 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<Explanation> getExplanations
(Query query,
DocList docs,
SolrIndexSearcher searcher,
IndexSchema schema) throws IOException {
NamedList<Explanation> explainList = new SimpleOrderedMap<>();
DocIterator iterator = docs.iterator();
for (int i=0; i<docs.size(); i++) {
int id = iterator.nextDoc();
Document doc = searcher.doc(id);
String strid = schema.printableUniqueKey(doc);
explainList.add(strid, searcher.explain(query, id) );
}
return explainList;
}
示例2: printDocIDs
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@SuppressWarnings("unused")
private void printDocIDs(DocSet fromSet) throws IOException {
// Only used in debugging.
System.out.println("---------------------------");
DocIterator iter = fromSet.iterator();
while (iter.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
Integer docId = iter.next();
Document d = fromSearcher.doc(docId);
String id = d.getValues("id")[0];
// TODO :log message (this is too verbose?)
if (debug) {
System.out.println("INTERNAL ID : " + docId + " DOC : " + id);
}
}
System.out.println("---------------------------");
}
示例3: AbstractSolrCachingScorer
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
AbstractSolrCachingScorer(Weight weight, DocSet in, AtomicReaderContext context, Bits acceptDocs, SolrIndexSearcher searcher)
{
super(weight);
this.context = context;
this.acceptDocs = acceptDocs;
if (in instanceof BitDocSet)
{
matches = (BitDocSet) in;
}
else
{
this.matches = new BitDocSet(new FixedBitSet(searcher.maxDoc()));
for (DocIterator it = in.iterator(); it.hasNext(); /* */)
{
matches.addUnique(it.nextDoc());
}
}
bitSet = matches.getBits();
doc = getBase() - 1;
}
示例4: AbstractSolrCachingScorer
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
AbstractSolrCachingScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
super(similarity);
if (in instanceof BitDocSet)
{
matches = (BitDocSet) in;
}
else
{
this.matches = new BitDocSet(new OpenBitSet(solrIndexReader.maxDoc()));
for (DocIterator it = in.iterator(); it.hasNext(); /* */)
{
matches.addUnique(it.nextDoc());
}
}
openBitSet = matches.getBits();
this.solrIndexReader = solrIndexReader;
doc = solrIndexReader.getBase() - 1;
}
示例5: testUngrouped
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testUngrouped() {
ModifiableSolrParams params = new ModifiableSolrParams();
NamedList results = test(params, "xjoin");
testXJoinResults(results, "xjoin");
ResultContext response = (ResultContext)results.get("response");
DocList docs = response.getDocList();
assertEquals(2, docs.size());
DocIterator it = docs.iterator();
assertTrue(it.hasNext());
assertEquals(1, it.nextDoc());
assertTrue(it.hasNext());
assertEquals(3, it.nextDoc());
assertFalse(it.hasNext());
}
示例6: testGroupedSimple
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testGroupedSimple() {
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("group", "true");
params.add("group.field", "colour");
params.add("group.format", "simple");
NamedList results = test(params, "xjoin");
testXJoinResults(results, "xjoin");
NamedList grouped = (NamedList)results.get("grouped");
NamedList colours = (NamedList)grouped.get("colour");
assertEquals(2, colours.get("matches"));
DocList docs = (DocList)colours.get("doclist");
assertEquals(docs.size(), 2);
DocIterator it = docs.iterator();
assertTrue(it.hasNext());
assertEquals(1, it.nextDoc());
assertTrue(it.hasNext());
assertEquals(3, it.nextDoc());
assertFalse(it.hasNext());
}
示例7: testMultiValued
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Test
public void testMultiValued() throws Exception {
Query q = parse(COMPONENT_NAME_4);
DocSet docs = searcher.getDocSet(q);
assertEquals(4, docs.size());
DocIterator it = docs.iterator();
assertTrue(it.hasNext());
assertEquals(0, it.nextDoc());
assertTrue(it.hasNext());
assertEquals(1, it.nextDoc());
assertTrue(it.hasNext());
assertEquals(2, it.nextDoc());
assertTrue(it.hasNext());
assertEquals(3, it.nextDoc());
assertFalse(it.hasNext());
}
示例8: testUngrouped
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testUngrouped() {
ModifiableSolrParams params = new ModifiableSolrParams();
NamedList results = test(params, "xjoin");
testXJoinResults(results, "xjoin");
ResultContext response = (ResultContext)results.get("response");
DocList docs = response.docs;
assertEquals(2, docs.size());
DocIterator it = docs.iterator();
assertTrue(it.hasNext());
assertEquals(1, it.nextDoc());
assertTrue(it.hasNext());
assertEquals(3, it.nextDoc());
assertFalse(it.hasNext());
}
示例9: findParentIdsForNodes
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
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;
}
示例10: for
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
/**
* Generates an NamedList 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<Explanation> getExplanations
(Query query,
DocList docs,
SolrIndexSearcher searcher,
IndexSchema schema) throws IOException {
NamedList<Explanation> explainList = new SimpleOrderedMap<Explanation>();
DocIterator iterator = docs.iterator();
for (int i=0; i<docs.size(); i++) {
int id = iterator.nextDoc();
Document doc = searcher.doc(id);
String strid = schema.printableUniqueKey(doc);
explainList.add(strid, searcher.explain(query, id) );
}
return explainList;
}
示例11: process
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
/**
* Here we define the component core logic.
* For each document belonging to search results, we call an external service
* for gathering a corresponding up-to-date price.
*
* @param rb The {@link org.apache.solr.handler.component.ResponseBuilder}
* @throws IOException If there is a low-level I/O error.
*/
@Override
public void process(final ResponseBuilder builder) throws IOException {
// Sanity check: if the component hasn't been properly initialised
// then it must immediately return.
// A more ideal approach could retry the initialisation (in the prepare method).
if (!hasBeenCorrectlyInitialised) {
return;
}
// Get a SolrIndexSearcher reference
final SolrIndexSearcher searcher = builder.req.getSearcher();
// This NamediLis will hold the component contribution (i.e. the component result).
final NamedList<Double> contribution = new SimpleOrderedMap<Double>();
for (final DocIterator it = builder.getResults().docList.iterator(); it.hasNext();) {
// This is NOT the Solr ID of our records, but instead the Lucene internal document id
// which is different
int docId = it.nextDoc();
final Document luceneDocument = searcher.doc(docId);
// This is the Solr document Id
String id = luceneDocument.get("id");
// Get the price of the item
final Double itemPrice = getPrice(id);
// Add the price of the item to the component contribution
contribution.add(id, itemPrice);
}
// Add the component contribution to the response builder
builder.rsp.add("prices", contribution);
}
示例12: transform
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Override
public void transform(SolrDocument doc, int docid) {
FieldType idFt = idField.getType();
Object parentIdField = doc.getFirstValue(idField.getName());
String parentIdExt = parentIdField instanceof IndexableField
? idFt.toExternal((IndexableField)parentIdField)
: parentIdField.toString();
try {
Query parentQuery = idFt.getFieldQuery(null, idField, parentIdExt);
Query query = new ToChildBlockJoinQuery(parentQuery, parentsFilter, false);
DocList children = context.searcher.getDocList(query, childFilterQuery, new Sort(), 0, limit);
if(children.matches() > 0) {
DocIterator i = children.iterator();
while(i.hasNext()) {
Integer childDocNum = i.next();
Document childDoc = context.searcher.doc(childDocNum);
SolrDocument solrChildDoc = ResponseWriterUtil.toSolrDocument(childDoc, schema);
// TODO: future enhancement...
// support an fl local param in the transformer, which is used to build
// a private ReturnFields instance that we use to prune unwanted field
// names from solrChildDoc
doc.addChildDocument(solrChildDoc);
}
}
} catch (IOException e) {
doc.put(name, "Could not fetch child Documents");
}
}
示例13: processIds
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
protected void processIds(ResponseBuilder rb, DocList dl, IndexSchema schema,
SolrIndexSearcher searcher) throws IOException {
StringBuilder sb = new StringBuilder();
Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName());
for(DocIterator iter = dl.iterator(); iter.hasNext();) {
sb.append(schema.printableUniqueKey(searcher.doc(iter.nextDoc(), fields)))
.append(',');
}
if (sb.length() > 0) {
rb.rsp.addToLog("responseLog", sb.substring(0, sb.length() - 1));
}
}
示例14: processScores
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
protected void processScores(ResponseBuilder rb, DocList dl, IndexSchema schema,
SolrIndexSearcher searcher) throws IOException {
StringBuilder sb = new StringBuilder();
Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName());
for(DocIterator iter = dl.iterator(); iter.hasNext();) {
sb.append(schema.printableUniqueKey(searcher.doc(iter.nextDoc(), fields)))
.append(':')
.append(iter.score())
.append(',');
}
if (sb.length() > 0) {
rb.rsp.addToLog("responseLog", sb.substring(0, sb.length() - 1));
}
}
示例15: optimizePreFetchDocs
import org.apache.solr.search.DocIterator; //导入依赖的package包/类
/**
* Pre-fetch documents into the index searcher's document cache.
*
* This is an entirely optional step which you might want to perform for
* the following reasons:
*
* <ul>
* <li>Locates the document-retrieval costs in one spot, which helps
* detailed performance measurement</li>
*
* <li>Determines a priori what fields will be needed to be fetched by
* various subtasks, like response writing and highlighting. This
* minimizes the chance that many needed fields will be loaded lazily.
* (it is more efficient to load all the field we require normally).</li>
* </ul>
*
* If lazy field loading is disabled, this method does nothing.
*/
public static void optimizePreFetchDocs(ResponseBuilder rb,
DocList docs,
Query query,
SolrQueryRequest req,
SolrQueryResponse res) throws IOException {
SolrIndexSearcher searcher = req.getSearcher();
if(!searcher.enableLazyFieldLoading) {
// nothing to do
return;
}
ReturnFields returnFields = res.getReturnFields();
if(returnFields.getLuceneFieldNames() != null) {
Set<String> fieldFilter = returnFields.getLuceneFieldNames();
if (rb.doHighlights) {
// copy return fields list
fieldFilter = new HashSet<>(fieldFilter);
// add highlight fields
SolrHighlighter highlighter = HighlightComponent.getHighlighter(req.getCore());
for (String field: highlighter.getHighlightFields(query, req, null))
fieldFilter.add(field);
// fetch unique key if one exists.
SchemaField keyField = searcher.getSchema().getUniqueKeyField();
if(null != keyField)
fieldFilter.add(keyField.getName());
}
// get documents
DocIterator iter = docs.iterator();
for (int i=0; i<docs.size(); i++) {
searcher.doc(iter.nextDoc(), fieldFilter);
}
}
}