Search in sources :

Example 6 with BitSetIterator

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

the class TestDocSet method getHashDocSet.

public DocSet getHashDocSet(FixedBitSet bs) {
    int[] docs = new int[bs.cardinality()];
    BitSetIterator iter = new BitSetIterator(bs, 0);
    for (int i = 0; i < docs.length; i++) {
        docs[i] = iter.nextDoc();
    }
    return new HashDocSet(docs, 0, docs.length);
}
Also used : BitSetIterator(org.apache.lucene.util.BitSetIterator)

Example 7 with BitSetIterator

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

the class ExportWriter method writeDocs.

protected void writeDocs(SolrQueryRequest req, IteratorWriter.ItemWriter writer, Sort sort) throws IOException {
    //Write the data.
    List<LeafReaderContext> leaves = req.getSearcher().getTopReaderContext().leaves();
    SortDoc sortDoc = getSortDoc(req.getSearcher(), sort.getSort());
    int count = 0;
    int queueSize = 30000;
    SortQueue queue = new SortQueue(queueSize, sortDoc);
    SortDoc[] outDocs = new SortDoc[queueSize];
    while (count < totalHits) {
        //long begin = System.nanoTime();
        queue.reset();
        SortDoc top = queue.top();
        for (int i = 0; i < leaves.size(); i++) {
            sortDoc.setNextReader(leaves.get(i));
            // cost is not useful here
            DocIdSetIterator it = new BitSetIterator(sets[i], 0);
            int docId = -1;
            while ((docId = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
                sortDoc.setValues(docId);
                if (top.lessThan(sortDoc)) {
                    top.setValues(sortDoc);
                    top = queue.updateTop();
                }
            }
        }
        int outDocsIndex = -1;
        for (int i = 0; i < queueSize; i++) {
            SortDoc s = queue.pop();
            if (s.docId > -1) {
                outDocs[++outDocsIndex] = s;
            }
        }
        //long end = System.nanoTime();
        count += (outDocsIndex + 1);
        try {
            for (int i = outDocsIndex; i >= 0; --i) {
                SortDoc s = outDocs[i];
                writer.add((MapWriter) ew -> {
                    writeDoc(s, leaves, ew);
                    s.reset();
                });
            }
        } catch (Throwable e) {
            Throwable ex = e;
            while (ex != null) {
                String m = ex.getMessage();
                if (m != null && m.contains("Broken pipe")) {
                    throw new IgnoreException();
                }
                ex = ex.getCause();
            }
            if (e instanceof IOException) {
                throw ((IOException) e);
            } else {
                throw new IOException(e);
            }
        }
    }
}
Also used : BitSetIterator(org.apache.lucene.util.BitSetIterator) Date(java.util.Date) EntryWriter(org.apache.solr.common.MapWriter.EntryWriter) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) IndexableField(org.apache.lucene.index.IndexableField) JSONResponseWriter(org.apache.solr.response.JSONResponseWriter) BoolField(org.apache.solr.schema.BoolField) StrField(org.apache.solr.schema.StrField) LoggerFactory(org.slf4j.LoggerFactory) LongValues(org.apache.lucene.util.LongValues) SolrParams(org.apache.solr.common.params.SolrParams) Collections.singletonList(java.util.Collections.singletonList) SolrException(org.apache.solr.common.SolrException) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SortField(org.apache.lucene.search.SortField) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) PrintWriter(java.io.PrintWriter) MapWriter(org.apache.solr.common.MapWriter) Sort(org.apache.lucene.search.Sort) BytesRef(org.apache.lucene.util.BytesRef) SolrCore(org.apache.solr.core.SolrCore) MethodHandles(java.lang.invoke.MethodHandles) StandardCharsets(java.nio.charset.StandardCharsets) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap) List(java.util.List) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LeafReader(org.apache.lucene.index.LeafReader) IteratorWriter(org.apache.solr.common.IteratorWriter) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec) TrieDateField(org.apache.solr.schema.TrieDateField) PushWriter(org.apache.solr.common.PushWriter) NumericDocValues(org.apache.lucene.index.NumericDocValues) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) FieldType(org.apache.solr.schema.FieldType) FixedBitSet(org.apache.lucene.util.FixedBitSet) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) SortSpec(org.apache.solr.search.SortSpec) BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) SchemaField(org.apache.solr.schema.SchemaField) TrieFloatField(org.apache.solr.schema.TrieFloatField) TrieLongField(org.apache.solr.schema.TrieLongField) SyntaxError(org.apache.solr.search.SyntaxError) SortedSetDocValues(org.apache.lucene.index.SortedSetDocValues) TrieIntField(org.apache.solr.schema.TrieIntField) OutputStreamWriter(java.io.OutputStreamWriter) Collections.singletonMap(java.util.Collections.singletonMap) SortedDocValues(org.apache.lucene.index.SortedDocValues) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) OutputStream(java.io.OutputStream) ArrayUtil(org.apache.lucene.util.ArrayUtil) Logger(org.slf4j.Logger) MultiDocValues(org.apache.lucene.index.MultiDocValues) BinaryResponseWriter(org.apache.solr.response.BinaryResponseWriter) IOException(java.io.IOException) TrieDoubleField(org.apache.solr.schema.TrieDoubleField) IndexSchema(org.apache.solr.schema.IndexSchema) DocValues(org.apache.lucene.index.DocValues) Closeable(java.io.Closeable) BitSetIterator(org.apache.lucene.util.BitSetIterator) IOException(java.io.IOException) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Example 8 with BitSetIterator

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

the class TestJoinUtil method assertBitSet.

private void assertBitSet(BitSet expectedResult, BitSet actualResult, IndexSearcher indexSearcher) throws IOException {
    if (VERBOSE) {
        System.out.println("expected cardinality:" + expectedResult.cardinality());
        DocIdSetIterator iterator = new BitSetIterator(expectedResult, expectedResult.cardinality());
        for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
            System.out.println(String.format(Locale.ROOT, "Expected doc[%d] with id value %s", doc, indexSearcher.doc(doc).get("id")));
        }
        System.out.println("actual cardinality:" + actualResult.cardinality());
        iterator = new BitSetIterator(actualResult, actualResult.cardinality());
        for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
            System.out.println(String.format(Locale.ROOT, "Actual doc[%d] with id value %s", doc, indexSearcher.doc(doc).get("id")));
        }
    }
    assertEquals(expectedResult, actualResult);
}
Also used : BitSetIterator(org.apache.lucene.util.BitSetIterator) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) DoublePoint(org.apache.lucene.document.DoublePoint) LongPoint(org.apache.lucene.document.LongPoint) IntPoint(org.apache.lucene.document.IntPoint) FloatPoint(org.apache.lucene.document.FloatPoint)

Example 9 with BitSetIterator

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

the class BitDocSet method iterator.

/* DocIterator using nextSetBit()
  public DocIterator iterator() {
    return new DocIterator() {
      int pos=bits.nextSetBit(0);
      public boolean hasNext() {
        return pos>=0;
      }

      public Integer next() {
        return nextDoc();
      }

      public void remove() {
        bits.clear(pos);
      }

      public int nextDoc() {
        int old=pos;
        pos=bits.nextSetBit(old+1);
        return old;
      }

      public float score() {
        return 0.0f;
      }
    };
  }
  ***/
@Override
public DocIterator iterator() {
    return new DocIterator() {

        // cost is not useful here
        private final BitSetIterator iter = new BitSetIterator(bits, 0L);

        private int pos = iter.nextDoc();

        @Override
        public boolean hasNext() {
            return pos != DocIdSetIterator.NO_MORE_DOCS;
        }

        @Override
        public Integer next() {
            return nextDoc();
        }

        @Override
        public void remove() {
            bits.clear(pos);
        }

        @Override
        public int nextDoc() {
            int old = pos;
            pos = iter.nextDoc();
            return old;
        }

        @Override
        public float score() {
            return 0.0f;
        }
    };
}
Also used : BitSetIterator(org.apache.lucene.util.BitSetIterator)

Example 10 with BitSetIterator

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

the class MultiValueModeTests method verify.

private void verify(RandomAccessOrds values, int maxDoc, FixedBitSet rootDocs, FixedBitSet innerDocs) throws IOException {
    for (MultiValueMode mode : new MultiValueMode[] { MultiValueMode.MIN, MultiValueMode.MAX }) {
        final SortedDocValues selected = mode.select(values, rootDocs, new BitSetIterator(innerDocs, 0L));
        int prevRoot = -1;
        for (int root = rootDocs.nextSetBit(0); root != -1; root = root + 1 < maxDoc ? rootDocs.nextSetBit(root + 1) : -1) {
            final int actual = selected.getOrd(root);
            int expected = -1;
            for (int child = innerDocs.nextSetBit(prevRoot + 1); child != -1 && child < root; child = innerDocs.nextSetBit(child + 1)) {
                values.setDocument(child);
                for (int j = 0; j < values.cardinality(); ++j) {
                    if (expected == -1) {
                        expected = (int) values.ordAt(j);
                    } else {
                        if (mode == MultiValueMode.MIN) {
                            expected = Math.min(expected, (int) values.ordAt(j));
                        } else if (mode == MultiValueMode.MAX) {
                            expected = Math.max(expected, (int) values.ordAt(j));
                        }
                    }
                }
            }
            assertEquals(mode.toString() + " docId=" + root, expected, actual);
            prevRoot = root;
        }
    }
}
Also used : BitSetIterator(org.apache.lucene.util.BitSetIterator) SortedDocValues(org.apache.lucene.index.SortedDocValues)

Aggregations

BitSetIterator (org.apache.lucene.util.BitSetIterator)17 FixedBitSet (org.apache.lucene.util.FixedBitSet)5 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)4 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)4 IntPoint (org.apache.lucene.document.IntPoint)3 LeafReader (org.apache.lucene.index.LeafReader)3 DoublePoint (org.apache.lucene.document.DoublePoint)2 FloatPoint (org.apache.lucene.document.FloatPoint)2 LongPoint (org.apache.lucene.document.LongPoint)2 NumericDocValues (org.apache.lucene.index.NumericDocValues)2 PointValues (org.apache.lucene.index.PointValues)2 SortedDocValues (org.apache.lucene.index.SortedDocValues)2 IndexInput (org.apache.lucene.store.IndexInput)2 IndexOutput (org.apache.lucene.store.IndexOutput)2 BytesRef (org.apache.lucene.util.BytesRef)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1