当前位置: 首页>>代码示例>>Java>>正文


Java ReaderUtil类代码示例

本文整理汇总了Java中org.apache.lucene.index.ReaderUtil的典型用法代码示例。如果您正苦于以下问题:Java ReaderUtil类的具体用法?Java ReaderUtil怎么用?Java ReaderUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReaderUtil类属于org.apache.lucene.index包,在下文中一共展示了ReaderUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
@Nullable
@Override
public Row apply(@Nullable ScoreDoc input) {
    if (input == null) {
        return null;
    }
    FieldDoc fieldDoc = (FieldDoc) input;
    scorer.score(fieldDoc.score);
    for (OrderByCollectorExpression orderByCollectorExpression : orderByCollectorExpressions) {
        orderByCollectorExpression.setNextFieldDoc(fieldDoc);
    }
    List<LeafReaderContext> leaves = indexReader.leaves();
    int readerIndex = ReaderUtil.subIndex(fieldDoc.doc, leaves);
    LeafReaderContext subReaderContext = leaves.get(readerIndex);
    int subDoc = fieldDoc.doc - subReaderContext.docBase;
    for (LuceneCollectorExpression<?> expression : expressions) {
        expression.setNextReader(subReaderContext);
        expression.setNextDocId(subDoc);
    }
    return inputRow;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:ScoreDocRowFunction.java

示例2: getValues

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
  final IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
  final AtomicReader r = SlowCompositeReaderWrapper.wrap(topReader);
  final int off = readerContext.docBase;

  final SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
  final int end = sindex.getValueCount();

  return new IntDocValues(this) {
   @Override
    public int intVal(int doc) {
      return (end - sindex.getOrd(doc+off) - 1);
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:ReverseOrdFieldSource.java

示例3: QueryDocValues

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
public QueryDocValues(QueryValueSource vs, AtomicReaderContext readerContext, Map fcontext) throws IOException {
  super(vs);

  this.readerContext = readerContext;
  this.acceptDocs = readerContext.reader().getLiveDocs();
  this.defVal = vs.defVal;
  this.q = vs.q;
  this.fcontext = fcontext;

  Weight w = fcontext==null ? null : (Weight)fcontext.get(vs);
  if (w == null) {
    IndexSearcher weightSearcher;
    if(fcontext == null) {
      weightSearcher = new IndexSearcher(ReaderUtil.getTopLevelContext(readerContext));
    } else {
      weightSearcher = (IndexSearcher)fcontext.get("searcher");
      if (weightSearcher == null) {
        weightSearcher = new IndexSearcher(ReaderUtil.getTopLevelContext(readerContext));
      }
    }
    vs.createWeight(fcontext, weightSearcher);
    w = (Weight)fcontext.get(vs);
  }
  weight = w;
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:QueryValueSource.java

示例4: explain

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
@Override
public Explanation explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID) throws IOException {
  Explanation result = super.explain(searcher, firstPassExplanation, docID);

  List<AtomicReaderContext> leaves = searcher.getIndexReader().leaves();
  int subReader = ReaderUtil.subIndex(docID, leaves);
  AtomicReaderContext readerContext = leaves.get(subReader);
  int docIDInSegment = docID - readerContext.docBase;
  Map<String,Object> context = new HashMap<>();

  FakeScorer fakeScorer = new FakeScorer();
  fakeScorer.score = firstPassExplanation.getValue();
  fakeScorer.doc = docIDInSegment;

  context.put("scorer", fakeScorer);

  for(String variable : expression.variables) {
    result.addDetail(new Explanation((float) bindings.getValueSource(variable).getValues(context, readerContext).doubleVal(docIDInSegment),
                                     "variable \"" + variable + "\""));
  }

  return result;
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:ExpressionRescorer.java

示例5: getWeight

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
/** 
 * Returns the weight for the current <code>docId</code> as computed 
 * by the <code>weightsValueSource</code>
 * */
@Override
protected long getWeight(Document doc, int docId) {    
  if (currentWeightValues == null) {
    return 0;
  }
  int subIndex = ReaderUtil.subIndex(docId, starts);
  if (subIndex != currentLeafIndex) {
    currentLeafIndex = subIndex;
    try {
      currentWeightValues = weightsValueSource.getValues(new HashMap<String, Object>(), leaves.get(currentLeafIndex));
    } catch (IOException e) {
      throw new RuntimeException();
    }
  }
  return currentWeightValues.longVal(docId - starts[subIndex]);
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:DocumentValueSourceDictionary.java

示例6: transform

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
@Override
public void transform(SolrDocument doc, int docid) {
  // This is only good for random-access functions

  try {

    // TODO: calculate this stuff just once across diff functions
    int idx = ReaderUtil.subIndex(docid, readerContexts);
    AtomicReaderContext rcontext = readerContexts.get(idx);
    FunctionValues values = docValuesArr[idx];
    if (values == null) {
      docValuesArr[idx] = values = valueSource.getValues(fcontext, rcontext);
    }

    int localId = docid - rcontext.docBase;
    Object val = values.objectVal(localId);
    if (val != null) {
      doc.setField( name, val );
    }
  } catch (IOException e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "exception at docid " + docid + " for valuesource " + valueSource, e);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:ValueSourceAugmenter.java

示例7: getValues

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
  final IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
  final AtomicReader r = topReader instanceof CompositeReader 
      ? new SlowCompositeReaderWrapper((CompositeReader)topReader) 
      : (AtomicReader) topReader;
  final int off = readerContext.docBase;

  final SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
  final int end = sindex.getValueCount();

  return new IntDocValues(this) {
   @Override
    public int intVal(int doc) {
      return (end - sindex.getOrd(doc+off) - 1);
    }
  };
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:19,代码来源:ReverseOrdFieldSource.java

示例8: objectVal

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
Object objectVal(int topDocId) throws IOException {
  // lookup segment level stuff:
  int segIdx = ReaderUtil.subIndex(topDocId, readerContexts);
  LeafReaderContext rcontext = readerContexts.get(segIdx);
  int segDocId = topDocId - rcontext.docBase;
  // unfortunately Lucene 7.0 requires forward only traversal (with no reset method).
  //   So we need to track our last docId (per segment) and re-fetch the FunctionValues. :-(
  FunctionValues functionValues = functionValuesPerSeg[segIdx];
  if (functionValues == null || segDocId < functionValuesDocIdPerSeg[segIdx]) {
    functionValues = functionValuesPerSeg[segIdx] = valueSource.getValues(fContext, rcontext);
  }
  functionValuesDocIdPerSeg[segIdx] = segDocId;

  // get value:
  return functionValues.objectVal(segDocId);
}
 
开发者ID:OpenSextant,项目名称:SolrTextTagger,代码行数:17,代码来源:TaggerRequestHandler.java

示例9: getLeafCollector

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(final LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
    IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(ctx);
    IndexSearcher searcher = new IndexSearcher(topLevelContext);
    searcher.setQueryCache(null);
    Weight weight = searcher.createNormalizedWeight(childFilter, false);
    Scorer childDocsScorer = weight.scorer(ctx);

    final BitSet parentDocs = parentFilter.getBitSet(ctx);
    final DocIdSetIterator childDocs = childDocsScorer != null ? childDocsScorer.iterator() : null;
    return new LeafBucketCollectorBase(sub, null) {
        @Override
        public void collect(int parentDoc, long bucket) throws IOException {
            // if parentDoc is 0 then this means that this parent doesn't have child docs (b/c these appear always before the parent
            // doc), so we can skip:
            if (parentDoc == 0 || parentDocs == null || childDocs == null) {
                return;
            }

            final int prevParentDoc = parentDocs.prevSetBit(parentDoc - 1);
            int childDocId = childDocs.docID();
            if (childDocId <= prevParentDoc) {
                childDocId = childDocs.advance(prevParentDoc + 1);
            }

            for (; childDocId < parentDoc; childDocId = childDocs.nextDoc()) {
                collectBucket(sub, childDocId, bucket);
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:NestedAggregator.java

示例10: innerDocs

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
/**
 * Get a {@link DocIdSet} that matches the inner documents.
 */
public DocIdSetIterator innerDocs(LeafReaderContext ctx) throws IOException {
    final IndexReaderContext topLevelCtx = ReaderUtil.getTopLevelContext(ctx);
    IndexSearcher indexSearcher = new IndexSearcher(topLevelCtx);
    Weight weight = indexSearcher.createNormalizedWeight(innerQuery, false);
    Scorer s = weight.scorer(ctx);
    return s == null ? null : s.iterator();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:IndexFieldData.java

示例11: getAndLoadIfNotPresent

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
private BitSet getAndLoadIfNotPresent(final Query query, final LeafReaderContext context) throws IOException, ExecutionException {
    final Object coreCacheReader = context.reader().getCoreCacheKey();
    final ShardId shardId = ShardUtils.extractShardId(context.reader());
    if (shardId != null // can't require it because of the percolator
            && indexSettings.getIndex().equals(shardId.getIndex()) == false) {
        // insanity
        throw new IllegalStateException("Trying to load bit set for index " + shardId.getIndex()
                + " with cache of index " + indexSettings.getIndex());
    }
    Cache<Query, Value> filterToFbs = loadedFilters.computeIfAbsent(coreCacheReader, key -> {
        context.reader().addCoreClosedListener(BitsetFilterCache.this);
        return CacheBuilder.<Query, Value>builder().build();
    });

    return filterToFbs.computeIfAbsent(query, key -> {
        final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
        final IndexSearcher searcher = new IndexSearcher(topLevelContext);
        searcher.setQueryCache(null);
        final Weight weight = searcher.createNormalizedWeight(query, false);
        Scorer s = weight.scorer(context);
        final BitSet bitSet;
        if (s == null) {
            bitSet = null;
        } else {
            bitSet = BitSet.of(s.iterator(), context.reader().maxDoc());
        }

        Value value = new Value(bitSet, shardId);
        listener.onCache(shardId, value.bitset);
        return value;
    }).bitset;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:BitsetFilterCache.java

示例12: collect

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
public void collect(IntContainer docIds, StreamBucket.Builder builder) throws IOException {
    for (IntCursor cursor : docIds) {
        final int docId = cursor.value;
        int readerIndex = ReaderUtil.subIndex(docId, readerContexts);
        LeafReaderContext subReaderContext = readerContexts.get(readerIndex);
        setNextReader(subReaderContext);
        setNextDocId(docId - subReaderContext.docBase);
        builder.add(row);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:FetchCollector.java

示例13: getAndLoadIfNotPresent

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
private BitSet getAndLoadIfNotPresent(final Query query, final LeafReaderContext context) throws IOException, ExecutionException {
    final Object coreCacheReader = context.reader().getCoreCacheKey();
    final ShardId shardId = ShardUtils.extractShardId(context.reader());
    if (shardId != null // can't require it because of the percolator
            && index.getName().equals(shardId.getIndex()) == false) {
        // insanity
        throw new IllegalStateException("Trying to load bit set for index [" + shardId.getIndex()
                + "] with cache of index [" + index.getName() + "]");
    }
    Cache<Query, Value> filterToFbs = loadedFilters.get(coreCacheReader, new Callable<Cache<Query, Value>>() {
        @Override
        public Cache<Query, Value> call() throws Exception {
            context.reader().addCoreClosedListener(BitsetFilterCache.this);
            return CacheBuilder.newBuilder().build();
        }
    });
    return filterToFbs.get(query,new Callable<Value>() {
        @Override
        public Value call() throws Exception {
            final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
            final IndexSearcher searcher = new IndexSearcher(topLevelContext);
            searcher.setQueryCache(null);
            final Weight weight = searcher.createNormalizedWeight(query, false);
            final Scorer s = weight.scorer(context);
            final BitSet bitSet;
            if (s == null) {
                bitSet = null;
            } else {
                bitSet = BitSet.of(s.iterator(), context.reader().maxDoc());
            }

            Value value = new Value(bitSet, shardId);
            listener.onCache(shardId, value.bitset);
            return value;
        }
    }).bitset;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:38,代码来源:BitsetFilterCache.java

示例14: getValues

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException
{
  final BinaryDocValues terms = cache.getTerms(readerContext.reader(), field, false, PackedInts.FAST);
  final IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader();
  Terms t = MultiFields.getTerms(top, qfield);
  final TermsEnum termsEnum = t == null ? TermsEnum.EMPTY : t.iterator(null);
  
  return new IntDocValues(this) {

    @Override
    public int intVal(int doc) 
    {
      try {
        final BytesRef term = terms.get(doc);
        if (termsEnum.seekExact(term)) {
          return termsEnum.docFreq();
        } else {
          return 0;
        }
      } 
      catch (IOException e) {
        throw new RuntimeException("caught exception in function "+description()+" : doc="+doc, e);
      }
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:28,代码来源:JoinDocFreqValueSource.java

示例15: createScaleInfo

import org.apache.lucene.index.ReaderUtil; //导入依赖的package包/类
private ScaleInfo createScaleInfo(Map context, AtomicReaderContext readerContext) throws IOException {
  final List<AtomicReaderContext> leaves = ReaderUtil.getTopLevelContext(readerContext).leaves();

  float minVal = Float.POSITIVE_INFINITY;
  float maxVal = Float.NEGATIVE_INFINITY;

  for (AtomicReaderContext leaf : leaves) {
    int maxDoc = leaf.reader().maxDoc();
    FunctionValues vals =  source.getValues(context, leaf);
    for (int i=0; i<maxDoc; i++) {

    float val = vals.floatVal(i);
    if ((Float.floatToRawIntBits(val) & (0xff<<23)) == 0xff<<23) {
      // if the exponent in the float is all ones, then this is +Inf, -Inf or NaN
      // which don't make sense to factor into the scale function
      continue;
    }
    if (val < minVal) {
      minVal = val;
    }
    if (val > maxVal) {
      maxVal = val;
    }
  }
  }

  if (minVal == Float.POSITIVE_INFINITY) {
  // must have been an empty index
    minVal = maxVal = 0;
  }

  ScaleInfo scaleInfo = new ScaleInfo();
  scaleInfo.minVal = minVal;
  scaleInfo.maxVal = maxVal;
  context.put(ScaleFloatFunction.this, scaleInfo);
  return scaleInfo;
}
 
开发者ID:europeana,项目名称:search,代码行数:38,代码来源:ScaleFloatFunction.java


注:本文中的org.apache.lucene.index.ReaderUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。