當前位置: 首頁>>代碼示例>>Java>>正文


Java Bits類代碼示例

本文整理匯總了Java中org.apache.lucene.util.Bits的典型用法代碼示例。如果您正苦於以下問題:Java Bits類的具體用法?Java Bits怎麽用?Java Bits使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Bits類屬於org.apache.lucene.util包,在下文中一共展示了Bits類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLeafCollector

import org.apache.lucene.util.Bits; //導入依賴的package包/類
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {

    final Bits docsWithValue;
    if (valuesSource != null) {
        docsWithValue = valuesSource.docsWithValue(ctx);
    } else {
        docsWithValue = new Bits.MatchNoBits(ctx.reader().maxDoc());
    }
    return new LeafBucketCollectorBase(sub, docsWithValue) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (docsWithValue != null && !docsWithValue.get(doc)) {
                collectBucket(sub, doc, bucket);
            }
        }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:MissingAggregator.java

示例2: getLeafCollector

import org.apache.lucene.util.Bits; //導入依賴的package包/類
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    // no need to provide deleted docs to the filter
    final Bits[] bits = new Bits[filters.length];
    for (int i = 0; i < filters.length; ++i) {
        bits[i] = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), filters[i].scorer(ctx));
    }
    return new LeafBucketCollectorBase(sub, null) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            boolean matched = false;
            for (int i = 0; i < bits.length; i++) {
                if (bits[i].get(doc)) {
                    collectBucket(sub, doc, bucketOrd(bucket, i));
                    matched = true;
                }
            }
            if (showOtherBucket && !matched) {
                collectBucket(sub, doc, bucketOrd(bucket, bits.length));
            }
        }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:FiltersAggregator.java

示例3: NearSpansOrdered

import org.apache.lucene.util.Bits; //導入依賴的package包/類
public NearSpansOrdered(SpanNearQuery spanNearQuery, AtomicReaderContext context, Bits acceptDocs, Map<Term,TermContext> termContexts, boolean collectPayloads)
throws IOException {
  if (spanNearQuery.getClauses().length < 2) {
    throw new IllegalArgumentException("Less than 2 clauses: "
                                       + spanNearQuery);
  }
  this.collectPayloads = collectPayloads;
  allowedSlop = spanNearQuery.getSlop();
  SpanQuery[] clauses = spanNearQuery.getClauses();
  subSpans = new Spans[clauses.length];
  matchPayload = new LinkedList<>();
  subSpansByDoc = new Spans[clauses.length];
  for (int i = 0; i < clauses.length; i++) {
    subSpans[i] = clauses[i].getSpans(context, acceptDocs, termContexts);
    subSpansByDoc[i] = subSpans[i]; // used in toSameDoc()
  }
  query = spanNearQuery; // kept for toString() only.
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:NearSpansOrdered.java

示例4: exists

import org.apache.lucene.util.Bits; //導入依賴的package包/類
/**
 * Check whether there is one or more documents matching the provided query.
 */
public static boolean exists(IndexSearcher searcher, Query query) throws IOException {
    final Weight weight = searcher.createNormalizedWeight(query, false);
    // the scorer API should be more efficient at stopping after the first
    // match than the bulk scorer API
    for (LeafReaderContext context : searcher.getIndexReader().leaves()) {
        final Scorer scorer = weight.scorer(context);
        if (scorer == null) {
            continue;
        }
        final Bits liveDocs = context.reader().getLiveDocs();
        final DocIdSetIterator iterator = scorer.iterator();
        for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
            if (liveDocs == null || liveDocs.get(doc)) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:Lucene.java

示例5: getMissingBits

import org.apache.lucene.util.Bits; //導入依賴的package包/類
private Bits getMissingBits(final long offset) throws IOException {
  if (offset == -1) {
    return new Bits.MatchAllBits(maxDoc);
  } else {
    final IndexInput in = data.clone();
    return new Bits() {

      @Override
      public boolean get(int index) {
        try {
          in.seek(offset + (index >> 3));
          return (in.readByte() & (1 << (index & 7))) != 0;
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      @Override
      public int length() {
        return maxDoc;
      }
    };
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:Lucene45DocValuesProducer.java

示例6: getDocsWithField

import org.apache.lucene.util.Bits; //導入依賴的package包/類
@Override
public Bits getDocsWithField(FieldInfo field) throws IOException {
  switch(field.getDocValuesType()) {
    case SORTED_SET:
      return DocValues.docsWithValue(getSortedSet(field), maxDoc);
    case SORTED:
      return DocValues.docsWithValue(getSorted(field), maxDoc);
    case BINARY:
      BinaryEntry be = binaries.get(field.number);
      return getMissingBits(be.missingOffset);
    case NUMERIC:
      NumericEntry ne = numerics.get(field.number);
      return getMissingBits(ne.missingOffset);
    default:
      throw new AssertionError();
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:Lucene45DocValuesProducer.java

示例7: getMissingBits

import org.apache.lucene.util.Bits; //導入依賴的package包/類
private Bits getMissingBits(final long offset) throws IOException {
  if (offset == -1) {
    return new Bits.MatchAllBits(maxDoc);
  } else {
    int length = (int) ((maxDoc + 7L) >>> 3);
    final RandomAccessInput in = data.randomAccessSlice(offset, length);
    return new Bits() {
      @Override
      public boolean get(int index) {
        try {
          return (in.readByte(index >> 3) & (1 << (index & 7))) != 0;
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      @Override
      public int length() {
        return maxDoc;
      }
    };
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:Lucene49DocValuesProducer.java

示例8: getDocsWithField

import org.apache.lucene.util.Bits; //導入依賴的package包/類
@Override
public Bits getDocsWithField(FieldInfo field) throws IOException {
  switch(field.getDocValuesType()) {
    case SORTED_SET:
      return DocValues.docsWithValue(getSortedSet(field), maxDoc);
    case SORTED_NUMERIC:
      return DocValues.docsWithValue(getSortedNumeric(field), maxDoc);
    case SORTED:
      return DocValues.docsWithValue(getSorted(field), maxDoc);
    case BINARY:
      BinaryEntry be = binaries.get(field.number);
      return getMissingBits(be.missingOffset);
    case NUMERIC:
      NumericEntry ne = numerics.get(field.number);
      return getMissingBits(ne.missingOffset);
    default:
      throw new AssertionError();
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:Lucene49DocValuesProducer.java

示例9: UnionDocsAndPositionsEnum

import org.apache.lucene.util.Bits; //導入依賴的package包/類
public UnionDocsAndPositionsEnum(Bits liveDocs, AtomicReaderContext context, Term[] terms, Map<Term,TermContext> termContexts, TermsEnum termsEnum) throws IOException {
  List<DocsAndPositionsEnum> docsEnums = new LinkedList<>();
  for (int i = 0; i < terms.length; i++) {
    final Term term = terms[i];
    TermState termState = termContexts.get(term).get(context.ord);
    if (termState == null) {
      // Term doesn't exist in reader
      continue;
    }
    termsEnum.seekExact(term.bytes(), termState);
    DocsAndPositionsEnum postings = termsEnum.docsAndPositions(liveDocs, null, DocsEnum.FLAG_NONE);
    if (postings == null) {
      // term does exist, but has no positions
      throw new IllegalStateException("field \"" + term.field() + "\" was indexed without position data; cannot run PhraseQuery (term=" + term.text() + ")");
    }
    cost += postings.cost();
    docsEnums.add(postings);
  }

  _queue = new DocsQueue(docsEnums);
  _posList = new IntQueue();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:MultiPhraseQuery.java

示例10: merge

import org.apache.lucene.util.Bits; //導入依賴的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

示例11: docsWithValue

import org.apache.lucene.util.Bits; //導入依賴的package包/類
@Override
public Bits docsWithValue(LeafReaderContext context) throws IOException {
    final SortedBinaryDocValues bytes = bytesValues(context);
    if (org.elasticsearch.index.fielddata.FieldData.unwrapSingleton(bytes) != null) {
        return org.elasticsearch.index.fielddata.FieldData.unwrapSingletonBits(bytes);
    } else {
        return org.elasticsearch.index.fielddata.FieldData.docsWithValue(bytes, context.reader().maxDoc());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:ValuesSource.java

示例12: bulkScorer

import org.apache.lucene.util.Bits; //導入依賴的package包/類
@Override
public BulkScorer bulkScorer(AtomicReaderContext context, boolean scoreDocsInOrder, Bits acceptDocs) throws IOException {
  final DocIdSetIterator disi;
  if (filter != null) {
    assert query == null;
    return super.bulkScorer(context, scoreDocsInOrder, acceptDocs);
  } else {
    assert query != null && innerWeight != null;
    BulkScorer bulkScorer = innerWeight.bulkScorer(context, scoreDocsInOrder, acceptDocs);
    if (bulkScorer == null) {
      return null;
    }
    return new ConstantBulkScorer(bulkScorer, this, queryWeight);
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:ConstantScoreQuery.java

示例13: docsWithValue

import org.apache.lucene.util.Bits; //導入依賴的package包/類
@Override
public Bits docsWithValue(LeafReaderContext context) {
    final MultiGeoPointValues geoPoints = geoPointValues(context);
    if (org.elasticsearch.index.fielddata.FieldData.unwrapSingleton(geoPoints) != null) {
        return org.elasticsearch.index.fielddata.FieldData.unwrapSingletonBits(geoPoints);
    } else {
        return org.elasticsearch.index.fielddata.FieldData.docsWithValue(geoPoints, context.reader().maxDoc());
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:10,代碼來源:ValuesSource.java

示例14: createWeight

import org.apache.lucene.util.Bits; //導入依賴的package包/類
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    return new RandomAccessWeight(this) {
        @Override
        protected Bits getMatchingDocs(final LeafReaderContext context) throws IOException {
            final LeafSearchScript leafScript = searchScript.getLeafSearchScript(context);
            return new Bits() {

                @Override
                public boolean get(int doc) {
                    leafScript.setDocument(doc);
                    Object val = leafScript.run();
                    if (val == null) {
                        return false;
                    }
                    if (val instanceof Boolean) {
                        return (Boolean) val;
                    }
                    if (val instanceof Number) {
                        return ((Number) val).longValue() != 0;
                    }
                    throw new IllegalArgumentException("Can't handle type [" + val + "] in script filter");
                }

                @Override
                public int length() {
                    return context.reader().maxDoc();
                }

            };
        }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:34,代碼來源:ScriptQueryBuilder.java

示例15: getReadOnlyLiveDocs

import org.apache.lucene.util.Bits; //導入依賴的package包/類
public synchronized Bits getReadOnlyLiveDocs() {
  //System.out.println("getROLiveDocs seg=" + info);
  assert Thread.holdsLock(writer);
  liveDocsShared = true;
  //if (liveDocs != null) {
  //System.out.println("  liveCount=" + liveDocs.count());
  //}
  return liveDocs;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:ReadersAndUpdates.java


注:本文中的org.apache.lucene.util.Bits類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。