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


Java AtomicReader类代码示例

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


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

示例1: merge

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
/** Merges in the stored fields from the readers in 
 *  <code>mergeState</code>. The default implementation skips
 *  over deleted documents, and uses {@link #startDocument()},
 *  {@link #writeField(FieldInfo, IndexableField)}, and {@link #finish(FieldInfos, int)},
 *  returning the number of documents that were written.
 *  Implementations can override this method for more sophisticated
 *  merging (bulk-byte copying, etc). */
public int merge(MergeState mergeState) throws IOException {
  int docCount = 0;
  for (AtomicReader reader : mergeState.readers) {
    final int maxDoc = reader.maxDoc();
    final Bits liveDocs = reader.getLiveDocs();
    for (int i = 0; i < maxDoc; i++) {
      if (liveDocs != null && !liveDocs.get(i)) {
        // skip deleted docs
        continue;
      }
      // TODO: this could be more efficient using
      // FieldVisitor instead of loading/writing entire
      // doc; ie we just have to renumber the field number
      // on the fly?
      // NOTE: it's very important to first assign to doc then pass it to
      // fieldsWriter.addDocument; see LUCENE-1282
      Document doc = reader.document(i);
      addDocument(doc, mergeState.fieldInfos);
      docCount++;
      mergeState.checkAbort.work(300);
    }
  }
  finish(mergeState.fieldInfos, docCount);
  return docCount;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:StoredFieldsWriter.java

示例2: copyFieldsNoDeletions

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
private int copyFieldsNoDeletions(MergeState mergeState, final AtomicReader reader,
                                  final Lucene40StoredFieldsReader matchingFieldsReader, int rawDocLengths[])
  throws IOException {
  final int maxDoc = reader.maxDoc();
  int docCount = 0;
  if (matchingFieldsReader != null) {
    // We can bulk-copy because the fieldInfos are "congruent"
    while (docCount < maxDoc) {
      int len = Math.min(MAX_RAW_MERGE_DOCS, maxDoc - docCount);
      IndexInput stream = matchingFieldsReader.rawDocs(rawDocLengths, docCount, len);
      addRawDocuments(stream, rawDocLengths, len);
      docCount += len;
      mergeState.checkAbort.work(300 * len);
    }
  } else {
    for (; docCount < maxDoc; docCount++) {
      // NOTE: it's very important to first assign to doc then pass it to
      // fieldsWriter.addDocument; see LUCENE-1282
      Document doc = reader.document(docCount);
      addDocument(doc, mergeState.fieldInfos);
      mergeState.checkAbort.work(300);
    }
  }
  return docCount;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:Lucene40StoredFieldsWriter.java

示例3: merge

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
/** Merges in the term vectors from the readers in 
 *  <code>mergeState</code>. The default implementation skips
 *  over deleted documents, and uses {@link #startDocument(int)},
 *  {@link #startField(FieldInfo, int, boolean, boolean, boolean)}, 
 *  {@link #startTerm(BytesRef, int)}, {@link #addPosition(int, int, int, BytesRef)},
 *  and {@link #finish(FieldInfos, int)},
 *  returning the number of documents that were written.
 *  Implementations can override this method for more sophisticated
 *  merging (bulk-byte copying, etc). */
public int merge(MergeState mergeState) throws IOException {
  int docCount = 0;
  for (int i = 0; i < mergeState.readers.size(); i++) {
    final AtomicReader reader = mergeState.readers.get(i);
    final int maxDoc = reader.maxDoc();
    final Bits liveDocs = reader.getLiveDocs();

    for (int docID = 0; docID < maxDoc; docID++) {
      if (liveDocs != null && !liveDocs.get(docID)) {
        // skip deleted docs
        continue;
      }
      // NOTE: it's very important to first assign to vectors then pass it to
      // termVectorsWriter.addAllDocVectors; see LUCENE-1282
      Fields vectors = reader.getTermVectors(docID);
      addAllDocVectors(vectors, mergeState);
      docCount++;
      mergeState.checkAbort.work(300);
    }
  }
  finish(mergeState.fieldInfos, docCount);
  return docCount;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:TermVectorsWriter.java

示例4: put

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
/** Sets the key to the value for the provided reader;
 *  if the key is already set then this doesn't change it. */
public void put(AtomicReader reader, CacheKey key, Accountable value) {
  final Object readerKey = reader.getCoreCacheKey();
  synchronized (readerCache) {
    Map<CacheKey,Accountable> innerCache = readerCache.get(readerKey);
    if (innerCache == null) {
      // First time this reader is using FieldCache
      innerCache = new HashMap<>();
      readerCache.put(readerKey, innerCache);
      wrapper.initReader(reader);
    }
    if (innerCache.get(key) == null) {
      innerCache.put(key, value);
    } else {
      // Another thread beat us to it; leave the current
      // value
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:FieldCacheImpl.java

示例5: setDocsWithField

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
void setDocsWithField(AtomicReader reader, String field, Bits docsWithField) {
  final int maxDoc = reader.maxDoc();
  final Bits bits;
  if (docsWithField == null) {
    bits = new Bits.MatchNoBits(maxDoc);
  } else if (docsWithField instanceof FixedBitSet) {
    final int numSet = ((FixedBitSet) docsWithField).cardinality();
    if (numSet >= maxDoc) {
      // The cardinality of the BitSet is maxDoc if all documents have a value.
      assert numSet == maxDoc;
      bits = new Bits.MatchAllBits(maxDoc);
    } else {
      bits = docsWithField;
    }
  } else {
    bits = docsWithField;
  }
  caches.get(DocsWithFieldCache.class).put(reader, new CacheKey(field, null), new BitsEntry(bits));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:FieldCacheImpl.java

示例6: getBytes

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
@Override
public Bytes getBytes(AtomicReader reader, String field, ByteParser parser, boolean setDocsWithField)
    throws IOException {
  final NumericDocValues valuesIn = reader.getNumericDocValues(field);
  if (valuesIn != null) {
    // Not cached here by FieldCacheImpl (cached instead
    // per-thread by SegmentReader):
    return new Bytes() {
      @Override
      public byte get(int docID) {
        return (byte) valuesIn.get(docID);
      }
    };
  } else {
    final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
    if (info == null) {
      return Bytes.EMPTY;
    } else if (info.hasDocValues()) {
      throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
    } else if (!info.isIndexed()) {
      return Bytes.EMPTY;
    }
    return (Bytes) caches.get(Byte.TYPE).get(reader, new CacheKey(field, parser), setDocsWithField);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:FieldCacheImpl.java

示例7: getShorts

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
public Shorts getShorts(AtomicReader reader, String field, ShortParser parser, boolean setDocsWithField)
    throws IOException {
  final NumericDocValues valuesIn = reader.getNumericDocValues(field);
  if (valuesIn != null) {
    // Not cached here by FieldCacheImpl (cached instead
    // per-thread by SegmentReader):
    return new Shorts() {
      @Override
      public short get(int docID) {
        return (short) valuesIn.get(docID);
      }
    };
  } else {
    final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
    if (info == null) {
      return Shorts.EMPTY;
    } else if (info.hasDocValues()) {
      throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
    } else if (!info.isIndexed()) {
      return Shorts.EMPTY;
    }
    return (Shorts) caches.get(Short.TYPE).get(reader, new CacheKey(field, parser), setDocsWithField);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:FieldCacheImpl.java

示例8: getInts

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
@Override
public Ints getInts(AtomicReader reader, String field, IntParser parser, boolean setDocsWithField)
    throws IOException {
  final NumericDocValues valuesIn = reader.getNumericDocValues(field);
  if (valuesIn != null) {
    // Not cached here by FieldCacheImpl (cached instead
    // per-thread by SegmentReader):
    return new Ints() {
      @Override
      public int get(int docID) {
        return (int) valuesIn.get(docID);
      }
    };
  } else {
    final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
    if (info == null) {
      return Ints.EMPTY;
    } else if (info.hasDocValues()) {
      throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
    } else if (!info.isIndexed()) {
      return Ints.EMPTY;
    }
    return (Ints) caches.get(Integer.TYPE).get(reader, new CacheKey(field, parser), setDocsWithField);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:FieldCacheImpl.java

示例9: getFloats

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
@Override
public Floats getFloats(AtomicReader reader, String field, FloatParser parser, boolean setDocsWithField)
  throws IOException {
  final NumericDocValues valuesIn = reader.getNumericDocValues(field);
  if (valuesIn != null) {
    // Not cached here by FieldCacheImpl (cached instead
    // per-thread by SegmentReader):
    return new Floats() {
      @Override
      public float get(int docID) {
        return Float.intBitsToFloat((int) valuesIn.get(docID));
      }
    };
  } else {
    final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
    if (info == null) {
      return Floats.EMPTY;
    } else if (info.hasDocValues()) {
      throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
    } else if (!info.isIndexed()) {
      return Floats.EMPTY;
    }
    return (Floats) caches.get(Float.TYPE).get(reader, new CacheKey(field, parser), setDocsWithField);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:FieldCacheImpl.java

示例10: getLongs

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
@Override
public Longs getLongs(AtomicReader reader, String field, FieldCache.LongParser parser, boolean setDocsWithField)
    throws IOException {
  final NumericDocValues valuesIn = reader.getNumericDocValues(field);
  if (valuesIn != null) {
    // Not cached here by FieldCacheImpl (cached instead
    // per-thread by SegmentReader):
    return new Longs() {
      @Override
      public long get(int docID) {
        return valuesIn.get(docID);
      }
    };
  } else {
    final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
    if (info == null) {
      return Longs.EMPTY;
    } else if (info.hasDocValues()) {
      throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
    } else if (!info.isIndexed()) {
      return Longs.EMPTY;
    }
    return (Longs) caches.get(Long.TYPE).get(reader, new CacheKey(field, parser), setDocsWithField);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:FieldCacheImpl.java

示例11: getDoubles

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
@Override
public Doubles getDoubles(AtomicReader reader, String field, FieldCache.DoubleParser parser, boolean setDocsWithField)
    throws IOException {
  final NumericDocValues valuesIn = reader.getNumericDocValues(field);
  if (valuesIn != null) {
    // Not cached here by FieldCacheImpl (cached instead
    // per-thread by SegmentReader):
    return new Doubles() {
      @Override
      public double get(int docID) {
        return Double.longBitsToDouble(valuesIn.get(docID));
      }
    };
  } else {
    final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
    if (info == null) {
      return Doubles.EMPTY;
    } else if (info.hasDocValues()) {
      throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
    } else if (!info.isIndexed()) {
      return Doubles.EMPTY;
    }
    return (Doubles) caches.get(Double.TYPE).get(reader, new CacheKey(field, parser), setDocsWithField);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:FieldCacheImpl.java

示例12: getTermsIndex

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
public SortedDocValues getTermsIndex(AtomicReader reader, String field, float acceptableOverheadRatio) throws IOException {
  SortedDocValues valuesIn = reader.getSortedDocValues(field);
  if (valuesIn != null) {
    // Not cached here by FieldCacheImpl (cached instead
    // per-thread by SegmentReader):
    return valuesIn;
  } else {
    final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
    if (info == null) {
      return DocValues.emptySorted();
    } else if (info.hasDocValues()) {
      // we don't try to build a sorted instance from numeric/binary doc
      // values because dedup can be very costly
      throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
    } else if (!info.isIndexed()) {
      return DocValues.emptySorted();
    }
    SortedDocValuesImpl impl = (SortedDocValuesImpl) caches.get(SortedDocValues.class).get(reader, new CacheKey(field, acceptableOverheadRatio), false);
    return impl.iterator();
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:FieldCacheImpl.java

示例13: getTerms

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
public BinaryDocValues getTerms(AtomicReader reader, String field, boolean setDocsWithField, float acceptableOverheadRatio) throws IOException {
  BinaryDocValues valuesIn = reader.getBinaryDocValues(field);
  if (valuesIn == null) {
    valuesIn = reader.getSortedDocValues(field);
  }

  if (valuesIn != null) {
    // Not cached here by FieldCacheImpl (cached instead
    // per-thread by SegmentReader):
    return valuesIn;
  }

  final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
  if (info == null) {
    return DocValues.emptyBinary();
  } else if (info.hasDocValues()) {
    throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
  } else if (!info.isIndexed()) {
    return DocValues.emptyBinary();
  }

  BinaryDocValuesImpl impl = (BinaryDocValuesImpl) caches.get(BinaryDocValues.class).get(reader, new CacheKey(field, acceptableOverheadRatio), setDocsWithField);
  return impl.iterator();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:FieldCacheImpl.java

示例14: getDocTermOrds

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
public SortedSetDocValues getDocTermOrds(AtomicReader reader, String field) throws IOException {
  SortedSetDocValues dv = reader.getSortedSetDocValues(field);
  if (dv != null) {
    return dv;
  }
  
  SortedDocValues sdv = reader.getSortedDocValues(field);
  if (sdv != null) {
    return DocValues.singleton(sdv);
  }
  
  final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
  if (info == null) {
    return DocValues.emptySortedSet();
  } else if (info.hasDocValues()) {
    throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
  } else if (!info.isIndexed()) {
    return DocValues.emptySortedSet();
  }
  
  DocTermOrds dto = (DocTermOrds) caches.get(DocTermOrds.class).get(reader, new CacheKey(field, null), false);
  return dto.iterator(reader);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:FieldCacheImpl.java

示例15: docIdSetToCache

import org.apache.lucene.index.AtomicReader; //导入依赖的package包/类
/** 
 *  Provide the DocIdSet to be cached, using the DocIdSet provided
 *  by the wrapped Filter. <p>This implementation returns the given {@link DocIdSet},
 *  if {@link DocIdSet#isCacheable} returns <code>true</code>, else it calls
 *  {@link #cacheImpl(DocIdSetIterator,AtomicReader)}
 *  <p>Note: This method returns {@linkplain DocIdSet#EMPTY} if the given docIdSet
 *  is <code>null</code> or if {@link DocIdSet#iterator()} return <code>null</code>. The empty
 *  instance is use as a placeholder in the cache instead of the <code>null</code> value.
 */
protected DocIdSet docIdSetToCache(DocIdSet docIdSet, AtomicReader reader) throws IOException {
  if (docIdSet == null) {
    // this is better than returning null, as the nonnull result can be cached
    return EMPTY;
  } else if (docIdSet.isCacheable()) {
    return docIdSet;
  } else {
    final DocIdSetIterator it = docIdSet.iterator();
    // null is allowed to be returned by iterator(),
    // in this case we wrap with the sentinel set,
    // which is cacheable.
    if (it == null) {
      return EMPTY;
    } else {
      return cacheImpl(it, reader);
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:CachingWrapperFilter.java


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