下面列出了org.apache.lucene.index.AtomicReader#fields ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void runOldMergeSortRowIdCheckAndDelete(boolean emitDeletes, IndexReader currentIndexReader,
BlurPartitioner blurPartitioner, Text key, int numberOfShards, int shardId, Action action,
AtomicReader atomicReader) throws IOException {
MergeSortRowIdLookup lookup = new MergeSortRowIdLookup(currentIndexReader);
Fields fields = atomicReader.fields();
Terms terms = fields.terms(BlurConstants.ROW_ID);
if (terms != null) {
TermsEnum termsEnum = terms.iterator(null);
BytesRef ref = null;
while ((ref = termsEnum.next()) != null) {
key.set(ref.bytes, ref.offset, ref.length);
int partition = blurPartitioner.getPartition(key, null, numberOfShards);
if (shardId != partition) {
throw new IOException("Index is corrupted, RowIds are found in wrong shard, partition [" + partition
+ "] does not shard [" + shardId + "], this can happen when rows are not hashed correctly.");
}
if (emitDeletes) {
lookup.lookup(ref, action);
}
}
}
}
private IterableRow getIterableRow(String rowId, IndexSearcherCloseable searcher) throws IOException {
IndexReader indexReader = searcher.getIndexReader();
BytesRef rowIdRef = new BytesRef(rowId);
List<AtomicReaderTermsEnum> possibleRowIds = new ArrayList<AtomicReaderTermsEnum>();
for (AtomicReaderContext atomicReaderContext : indexReader.leaves()) {
AtomicReader atomicReader = atomicReaderContext.reader();
Fields fields = atomicReader.fields();
if (fields == null) {
continue;
}
Terms terms = fields.terms(BlurConstants.ROW_ID);
if (terms == null) {
continue;
}
TermsEnum termsEnum = terms.iterator(null);
if (!termsEnum.seekExact(rowIdRef, true)) {
continue;
}
// need atomic read as well...
possibleRowIds.add(new AtomicReaderTermsEnum(atomicReader, termsEnum));
}
if (possibleRowIds.isEmpty()) {
return null;
}
return new IterableRow(rowId, getRecords(possibleRowIds));
}
private static void applyFamily(OpenBitSet bits, String family, AtomicReader atomicReader, int primeDocRowId,
int numberOfDocsInRow, Bits liveDocs) throws IOException {
Fields fields = atomicReader.fields();
Terms terms = fields.terms(BlurConstants.FAMILY);
TermsEnum iterator = terms.iterator(null);
BytesRef text = new BytesRef(family);
int lastDocId = primeDocRowId + numberOfDocsInRow;
if (iterator.seekExact(text, true)) {
DocsEnum docs = iterator.docs(liveDocs, null, DocsEnum.FLAG_NONE);
int doc = primeDocRowId;
while ((doc = docs.advance(doc)) < lastDocId) {
bits.set(doc - primeDocRowId);
}
}
}
@Override
public Boolean execute(IndexContext context) throws IOException, InterruptedException {
try {
IndexReader indexReader = context.getIndexReader();
while (true) {
long hash = 0;
for (AtomicReaderContext atomicReaderContext : indexReader.leaves()) {
AtomicReader reader = atomicReaderContext.reader();
for (String field : reader.fields()) {
Terms terms = reader.terms(field);
BytesRef bytesRef;
TermsEnum iterator = terms.iterator(null);
while ((bytesRef = iterator.next()) != null) {
hash += bytesRef.hashCode();
}
}
}
System.out.println("hashcode = " + hash);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
} catch (Throwable t) {
t.printStackTrace();
if (t instanceof InterruptedException) {
throw t;
} else if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
throw new RuntimeException(t);
}
}
@Override
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
AtomicReader reader = context.reader();
List<DocIdSet> list = new ArrayList<DocIdSet>();
Fields fields = reader.fields();
Terms terms = fields.terms(_fieldName);
if (terms == null) {
// if field is not present then show nothing.
return DocIdSet.EMPTY_DOCIDSET;
}
TermsEnum iterator = terms.iterator(null);
BytesRef bytesRef;
DocumentVisibilityEvaluator visibilityEvaluator = new DocumentVisibilityEvaluator(_authorizations);
while ((bytesRef = iterator.next()) != null) {
if (isVisible(visibilityEvaluator, bytesRef)) {
DocIdSet docIdSet = _filterCacheStrategy.getDocIdSet(_fieldName, bytesRef, reader);
if (docIdSet != null) {
list.add(docIdSet);
} else {
// Do not use acceptDocs because we want the acl cache to be version
// agnostic.
DocsEnum docsEnum = iterator.docs(null, null);
list.add(buildCache(reader, docsEnum, bytesRef));
}
}
}
return getLogicalOr(list);
}
private void checkTerms(IndexSearcher searcher, String fieldName) throws IOException {
IndexReader reader = searcher.getIndexReader();
for (AtomicReaderContext context : reader.leaves()) {
AtomicReader atomicReader = context.reader();
Fields fields = atomicReader.fields();
Terms terms = fields.terms(fieldName);
TermsEnum iterator = terms.iterator(null);
BytesRef bytesRef = iterator.next();
if (bytesRef != null) {
System.out.println(bytesRef.utf8ToString());
fail("There are only restricted terms for this field [" + fieldName + "]");
}
}
}