Skip to content

Commit

Permalink
Use DocIdSetBuilder instead of RoaringDocIdSet.Builder for DocIdSet c…
Browse files Browse the repository at this point in the history
…onstruction.

Switch to simpler DocIdSetBuilder that use much less memory in common case.
Benchmarks show that in common case it aslo brings increase of throughput.
  • Loading branch information
MishaDemianenko committed Feb 3, 2016
1 parent 9f775de commit 83a15ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -39,7 +39,7 @@
import org.apache.lucene.search.TopFieldCollector;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.RoaringDocIdSet;
import org.apache.lucene.util.DocIdSetBuilder;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -511,11 +511,11 @@ public NumericDocValues readDocValues( String field )
*/
private static final class Docs
{
private final RoaringDocIdSet.Builder bits;
private final DocIdSetBuilder bits;

public Docs( int maxDoc )
{
bits = new RoaringDocIdSet.Builder( maxDoc );
bits = new DocIdSetBuilder( maxDoc );
}

/** Record the given document. */
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.kernel.api.impl.index;

import org.apache.commons.lang3.math.NumberUtils;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocValuesType;
Expand All @@ -36,10 +37,13 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.function.Function;

import static com.sun.corba.se.spi.activation.IIOP_CLEAR_TEXT.value;

public class IndexReaderStub extends LeafReader
{

Expand Down Expand Up @@ -201,7 +205,7 @@ public int numDocs()
@Override
public int maxDoc()
{
return elements.length;
return Math.max( maxValue(), elements.length) + 1;
}

@Override
Expand All @@ -214,4 +218,10 @@ public void document( int docID, StoredFieldVisitor visitor ) throws IOException
protected void doClose() throws IOException
{
}

private int maxValue()
{
return Arrays.stream( elements )
.mapToInt( value -> NumberUtils.toInt( value, 0 )).max().getAsInt();
}
}

0 comments on commit 83a15ac

Please sign in to comment.