List of usage examples for org.apache.lucene.util SparseFixedBitSet SparseFixedBitSet
public SparseFixedBitSet(int length)
0 included and length excluded. From source file:com.boundlessgeo.elasticsearch.geoheatmap.GeoHeatmapAggregator.java
License:Apache License
@Override public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException { if (parentReaderContext == null) { parentReaderContext = ctx.parent; } else {//from w w w. jav a2 s . c om assert ctx.parent == parentReaderContext; } return new LeafBucketCollectorBase(sub, null) { @Override public void collect(int doc, long bucket) throws IOException { SparseFixedBitSet bits = buckets.get(bucket); if (bits == null) { bits = new SparseFixedBitSet(parentReaderContext.reader().maxDoc()); buckets.put(bucket, bits); } bits.set(ctx.docBase + doc); } }; }
From source file:de.unihildesheim.iw.lucene.search.EmptyFieldFilter.java
License:Open Source License
@Override public DocIdSet getDocIdSet(@NotNull final LeafReaderContext context, @Nullable final Bits acceptDocs) throws IOException { FixedBitSet checkBits;/*from w w w. j av a 2 s. c o m*/ final LeafReader reader = context.reader(); final int maxDoc = reader.maxDoc(); BitSet finalBits = new SparseFixedBitSet(maxDoc); if (acceptDocs == null) { checkBits = BitsUtils.bits2FixedBitSet(reader.getLiveDocs()); if (checkBits == null) { // all live checkBits = new FixedBitSet(maxDoc); checkBits.set(0, checkBits.length()); } } else { checkBits = BitsUtils.bits2FixedBitSet(acceptDocs); } @Nullable final Terms terms = reader.terms(this.field); if (terms != null) { final int termsDocCount = terms.getDocCount(); if (termsDocCount != 0) { if (termsDocCount == maxDoc) { // all matching finalBits = checkBits; } else { @Nullable final Terms t = reader.terms(this.field); if (t != null) { PostingsEnum pe = null; final TermsEnum te = t.iterator(null); int docId; while (te.next() != null) { pe = te.postings(checkBits, pe, (int) PostingsEnum.NONE); while ((docId = pe.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (checkBits.getAndClear(docId)) { finalBits.set(docId); } } } } } } } return new BitDocIdSet(finalBits); }
From source file:de.unihildesheim.iw.lucene.search.IPCFieldFilter.java
License:Open Source License
@Override public DocIdSet getDocIdSet(@NotNull final LeafReaderContext context, @Nullable final Bits acceptDocs) throws IOException { final LeafReader reader = context.reader(); final int maxDoc = reader.maxDoc(); final BitSet finalBits = new SparseFixedBitSet(maxDoc); if (acceptDocs == null) { // check all for (int i = 0; i < maxDoc; i++) { if (this.filterFunc.isAccepted(reader, i, this.ipcParser)) { finalBits.set(i);/* w w w . j ava2s. co m*/ } } } else { final BitSet checkBits = BitsUtils.bits2BitSet(acceptDocs); final DocIdSetIterator disi = new BitDocIdSet(checkBits).iterator(); int docId; while ((docId = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (this.filterFunc.isAccepted(reader, docId, this.ipcParser)) { finalBits.set(docId); } } } return new BitDocIdSet(finalBits); }
From source file:de.unihildesheim.iw.lucene.util.DocIdSetUtils.java
License:Open Source License
/** * Get a bits instance from a DocIdSet./*from w w w .j a v a 2 s . c om*/ * * @param dis Set whose bits to get * @return Bits or null, if no bits are set * @throws IOException Thrown on low-level I/O-errors */ @Nullable public static BitSet bits(@NotNull final DocIdSet dis) throws IOException { @Nullable final DocIdSetIterator disi = dis.iterator(); if (disi == null) { return null; } else { @Nullable BitSet bitSet; bitSet = BitSetIterator.getFixedBitSetOrNull(disi); if (bitSet == null) { bitSet = BitSetIterator.getSparseFixedBitSetOrNull(disi); } if (bitSet == null) { bitSet = BitsUtils.bits2BitSet(dis.bits()); } if (bitSet == null) { bitSet = new SparseFixedBitSet(maxDoc(dis) + 1); StreamUtils.stream(disi).forEach(bitSet::set); } return bitSet; } }
From source file:org.elasticsearch.xpack.core.security.authz.accesscontrol.SecurityIndexSearcherWrapperUnitTests.java
License:Open Source License
private SparseFixedBitSet query(LeafReaderContext leaf, String field, String value) throws IOException { SparseFixedBitSet sparseFixedBitSet = new SparseFixedBitSet(leaf.reader().maxDoc()); TermsEnum tenum = leaf.reader().terms(field).iterator(); while (tenum.next().utf8ToString().equals(value) == false) { }/*from w w w. j a v a 2s. c o m*/ PostingsEnum penum = tenum.postings(null); sparseFixedBitSet.or(penum); return sparseFixedBitSet; }
From source file:org.voyanttools.trombone.lucene.CorpusMapper.java
License:Open Source License
/** * This should not be called, except from the private build() method. * @throws IOException/*from w w w. j a va 2 s . c o m*/ */ private void buildFromTermsEnum() throws IOException { LeafReader reader = SlowCompositeReaderWrapper .wrap(storage.getLuceneManager().getDirectoryReader(corpus.getId())); Terms terms = reader.terms("id"); TermsEnum termsEnum = terms.iterator(); BytesRef bytesRef = termsEnum.next(); int doc; String id; Set<String> ids = new HashSet<String>(getCorpusDocumentIds()); bitSet = new SparseFixedBitSet(reader.numDocs()); Bits liveBits = reader.getLiveDocs(); while (bytesRef != null) { PostingsEnum postingsEnum = termsEnum.postings(null, PostingsEnum.NONE); doc = postingsEnum.nextDoc(); if (doc != PostingsEnum.NO_MORE_DOCS) { id = bytesRef.utf8ToString(); if (ids.contains(id)) { bitSet.set(doc); luceneIds.add(doc); documentIdToLuceneIdMap.put(id, doc); luceneIdToDocumentIdMap.put(doc, id); } } bytesRef = termsEnum.next(); } this.reader = new FilteredCorpusReader(reader, bitSet); }
From source file:org.voyanttools.trombone.lucene.CorpusMapper.java
License:Open Source License
public BitSet getBitSetFromDocumentIds(Collection<String> documentIds) throws IOException { BitSet subBitSet = new SparseFixedBitSet(getLeafReader().numDocs()); for (String id : documentIds) { subBitSet.set(getLuceneIdFromDocumentId(id)); }//from w ww .ja va2s .c o m return subBitSet; }