Search in sources :

Example 6 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project elasticsearch by elastic.

the class MultiValueModeTests method testMultiValuedOrds.

public void testMultiValuedOrds() throws Exception {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final long[][] array = new long[numDocs][];
    for (int i = 0; i < numDocs; ++i) {
        final long[] values = new long[randomInt(4)];
        for (int j = 0; j < values.length; ++j) {
            values[j] = j == 0 ? randomInt(1000) : values[j - 1] + 1 + randomInt(1000);
        }
        array[i] = values;
    }
    final RandomAccessOrds multiValues = new RandomAccessOrds() {

        int doc;

        @Override
        public long ordAt(int index) {
            return array[doc][index];
        }

        @Override
        public int cardinality() {
            return array[doc].length;
        }

        @Override
        public long nextOrd() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setDocument(int docID) {
            this.doc = docID;
        }

        @Override
        public BytesRef lookupOrd(long ord) {
            throw new UnsupportedOperationException();
        }

        @Override
        public long getValueCount() {
            return 1 << 20;
        }
    };
    verify(multiValues, numDocs);
    final FixedBitSet rootDocs = randomRootDocs(numDocs);
    final FixedBitSet innerDocs = randomInnerDocs(rootDocs);
    verify(multiValues, numDocs, rootDocs, innerDocs);
}
Also used : RandomAccessOrds(org.apache.lucene.index.RandomAccessOrds) FixedBitSet(org.apache.lucene.util.FixedBitSet)

Example 7 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project elasticsearch by elastic.

the class MultiValueModeTests method testSingleValuedStrings.

public void testSingleValuedStrings() throws Exception {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final BytesRef[] array = new BytesRef[numDocs];
    final FixedBitSet docsWithValue = randomBoolean() ? null : new FixedBitSet(numDocs);
    for (int i = 0; i < array.length; ++i) {
        if (randomBoolean()) {
            array[i] = new BytesRef(RandomStrings.randomAsciiOfLength(random(), 8));
            if (docsWithValue != null) {
                docsWithValue.set(i);
            }
        } else {
            array[i] = new BytesRef();
            if (docsWithValue != null && randomBoolean()) {
                docsWithValue.set(i);
            }
        }
    }
    final BinaryDocValues singleValues = new BinaryDocValues() {

        @Override
        public BytesRef get(int docID) {
            return BytesRef.deepCopyOf(array[docID]);
        }
    };
    final SortedBinaryDocValues multiValues = FieldData.singleton(singleValues, docsWithValue);
    verify(multiValues, numDocs);
    final FixedBitSet rootDocs = randomRootDocs(numDocs);
    final FixedBitSet innerDocs = randomInnerDocs(rootDocs);
    verify(multiValues, numDocs, rootDocs, innerDocs);
}
Also used : FixedBitSet(org.apache.lucene.util.FixedBitSet) BytesRef(org.apache.lucene.util.BytesRef) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues) BinaryDocValues(org.apache.lucene.index.BinaryDocValues) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues)

Example 8 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project elasticsearch by elastic.

the class MultiValueModeTests method testMultiValuedLongs.

public void testMultiValuedLongs() throws Exception {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final long[][] array = new long[numDocs][];
    for (int i = 0; i < numDocs; ++i) {
        final long[] values = new long[randomInt(4)];
        for (int j = 0; j < values.length; ++j) {
            values[j] = randomLong();
        }
        Arrays.sort(values);
        array[i] = values;
    }
    final SortedNumericDocValues multiValues = new SortedNumericDocValues() {

        int doc;

        @Override
        public long valueAt(int index) {
            return array[doc][index];
        }

        @Override
        public void setDocument(int doc) {
            this.doc = doc;
        }

        @Override
        public int count() {
            return array[doc].length;
        }
    };
    verify(multiValues, numDocs);
    final FixedBitSet rootDocs = randomRootDocs(numDocs);
    final FixedBitSet innerDocs = randomInnerDocs(rootDocs);
    verify(multiValues, numDocs, rootDocs, innerDocs);
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) FixedBitSet(org.apache.lucene.util.FixedBitSet)

Example 9 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.

the class BitDocSet method getTopFilter.

@Override
public Filter getTopFilter() {
    return new Filter() {

        final FixedBitSet bs = bits;

        @Override
        public DocIdSet getDocIdSet(final LeafReaderContext context, final Bits acceptDocs) {
            LeafReader reader = context.reader();
            // all Solr DocSets that are used as filters only include live docs
            final Bits acceptDocs2 = acceptDocs == null ? null : (reader.getLiveDocs() == acceptDocs ? null : acceptDocs);
            if (context.isTopLevel) {
                return BitsFilteredDocIdSet.wrap(new BitDocIdSet(bs), acceptDocs);
            }
            final int base = context.docBase;
            // one past the max doc in this segment.
            final int max = base + reader.maxDoc();
            return BitsFilteredDocIdSet.wrap(new DocIdSet() {

                @Override
                public DocIdSetIterator iterator() {
                    return new DocIdSetIterator() {

                        int pos = base - 1;

                        int adjustedDoc = -1;

                        @Override
                        public int docID() {
                            return adjustedDoc;
                        }

                        @Override
                        public int nextDoc() {
                            int next = pos + 1;
                            if (next >= max) {
                                return adjustedDoc = NO_MORE_DOCS;
                            } else {
                                pos = bs.nextSetBit(next);
                                return adjustedDoc = pos < max ? pos - base : NO_MORE_DOCS;
                            }
                        }

                        @Override
                        public int advance(int target) {
                            if (target == NO_MORE_DOCS)
                                return adjustedDoc = NO_MORE_DOCS;
                            int adjusted = target + base;
                            if (adjusted >= max) {
                                return adjustedDoc = NO_MORE_DOCS;
                            } else {
                                pos = bs.nextSetBit(adjusted);
                                return adjustedDoc = pos < max ? pos - base : NO_MORE_DOCS;
                            }
                        }

                        @Override
                        public long cost() {
                            // we don't want to actually compute cardinality, but
                            // if it's already been computed, we use it (pro-rated for the segment)
                            int maxDoc = max - base;
                            if (size != -1) {
                                return (long) (size * ((FixedBitSet.bits2words(maxDoc) << 6) / (float) bs.length()));
                            } else {
                                return maxDoc;
                            }
                        }
                    };
                }

                @Override
                public long ramBytesUsed() {
                    return bs.ramBytesUsed();
                }

                @Override
                public Bits bits() {
                    return new Bits() {

                        @Override
                        public boolean get(int index) {
                            return bs.get(index + base);
                        }

                        @Override
                        public int length() {
                            return max - base;
                        }
                    };
                }
            }, acceptDocs2);
        }

        @Override
        public String toString(String field) {
            return "BitSetDocTopFilter";
        }

        @Override
        public boolean equals(Object other) {
            return sameClassAs(other) && Objects.equals(bs, getClass().cast(other).bs);
        }

        @Override
        public int hashCode() {
            return classHash() * 31 + bs.hashCode();
        }
    };
}
Also used : BitDocIdSet(org.apache.lucene.util.BitDocIdSet) LeafReader(org.apache.lucene.index.LeafReader) FixedBitSet(org.apache.lucene.util.FixedBitSet) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Bits(org.apache.lucene.util.Bits) DocIdSet(org.apache.lucene.search.DocIdSet) BitDocIdSet(org.apache.lucene.util.BitDocIdSet) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Example 10 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.

the class DocSetBase method getTopFilter.

@Override
public Filter getTopFilter() {
    return new Filter() {

        final FixedBitSet bs = getBits();

        @Override
        public DocIdSet getDocIdSet(final LeafReaderContext context, Bits acceptDocs) {
            LeafReader reader = context.reader();
            // all Solr DocSets that are used as filters only include live docs
            final Bits acceptDocs2 = acceptDocs == null ? null : (reader.getLiveDocs() == acceptDocs ? null : acceptDocs);
            if (context.isTopLevel) {
                return BitsFilteredDocIdSet.wrap(new BitDocIdSet(bs), acceptDocs);
            }
            final int base = context.docBase;
            final int maxDoc = reader.maxDoc();
            // one past the max doc in this segment.
            final int max = base + maxDoc;
            return BitsFilteredDocIdSet.wrap(new DocIdSet() {

                @Override
                public DocIdSetIterator iterator() {
                    return new DocIdSetIterator() {

                        int pos = base - 1;

                        int adjustedDoc = -1;

                        @Override
                        public int docID() {
                            return adjustedDoc;
                        }

                        @Override
                        public int nextDoc() {
                            // TODO: this is buggy if getBits() returns a bitset that does not have a capacity of maxDoc
                            pos = bs.nextSetBit(pos + 1);
                            return adjustedDoc = pos < max ? pos - base : NO_MORE_DOCS;
                        }

                        @Override
                        public int advance(int target) {
                            if (target == NO_MORE_DOCS)
                                return adjustedDoc = NO_MORE_DOCS;
                            pos = bs.nextSetBit(target + base);
                            return adjustedDoc = pos < max ? pos - base : NO_MORE_DOCS;
                        }

                        @Override
                        public long cost() {
                            return bs.length();
                        }
                    };
                }

                @Override
                public long ramBytesUsed() {
                    return bs.ramBytesUsed();
                }

                @Override
                public Bits bits() {
                    // sparse filters should not use random access
                    return null;
                }
            }, acceptDocs2);
        }

        @Override
        public String toString(String field) {
            return "DocSetTopFilter";
        }

        @Override
        public boolean equals(Object other) {
            return sameClassAs(other) && Objects.equals(bs, getClass().cast(other).bs);
        }

        @Override
        public int hashCode() {
            return classHash() ^ bs.hashCode();
        }
    };
}
Also used : BitDocIdSet(org.apache.lucene.util.BitDocIdSet) LeafReader(org.apache.lucene.index.LeafReader) FixedBitSet(org.apache.lucene.util.FixedBitSet) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Bits(org.apache.lucene.util.Bits) DocIdSet(org.apache.lucene.search.DocIdSet) BitDocIdSet(org.apache.lucene.util.BitDocIdSet) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Aggregations

FixedBitSet (org.apache.lucene.util.FixedBitSet)162 Term (org.apache.lucene.index.Term)27 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)26 Directory (org.apache.lucene.store.Directory)25 BytesRef (org.apache.lucene.util.BytesRef)22 IOException (java.io.IOException)19 Document (org.apache.lucene.document.Document)17 ArrayList (java.util.ArrayList)15 Query (org.apache.lucene.search.Query)15 NumericDocValues (org.apache.lucene.index.NumericDocValues)14 BitDocIdSet (org.apache.lucene.util.BitDocIdSet)13 Bits (org.apache.lucene.util.Bits)13 LeafReader (org.apache.lucene.index.LeafReader)12 IndexSearcher (org.apache.lucene.search.IndexSearcher)12 TermQuery (org.apache.lucene.search.TermQuery)12 IndexReader (org.apache.lucene.index.IndexReader)11 HashSet (java.util.HashSet)10 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)10 DocIterator (org.apache.solr.search.DocIterator)10 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)9