Example usage for org.apache.lucene.codecs.bloom FuzzySet addValue

List of usage examples for org.apache.lucene.codecs.bloom FuzzySet addValue

Introduction

In this page you can find the example usage for org.apache.lucene.codecs.bloom FuzzySet addValue.

Prototype

public void addValue(BytesRef value) throws IOException 

Source Link

Document

Records a value in the set.

Usage

From source file:org.elasticsearch.benchmark.bloom.BloomBench.java

License:Apache License

public static void main(String[] args) throws Exception {
    SecureRandom random = new SecureRandom();
    final int ELEMENTS = (int) SizeValue.parseSizeValue("1m").singles();
    final double fpp = 0.01;
    BloomFilter gFilter = BloomFilter.create(ELEMENTS, fpp);
    System.out.println("G SIZE: " + new ByteSizeValue(gFilter.getSizeInBytes()));

    FuzzySet lFilter = FuzzySet.createSetBasedOnMaxMemory((int) gFilter.getSizeInBytes());
    //FuzzySet lFilter = FuzzySet.createSetBasedOnQuality(ELEMENTS, 0.97f);

    for (int i = 0; i < ELEMENTS; i++) {
        BytesRef bytesRef = new BytesRef(Strings.randomBase64UUID(random));
        gFilter.put(bytesRef);/*from w  w  w. j a v  a2 s . co m*/
        lFilter.addValue(bytesRef);
    }

    int lFalse = 0;
    int gFalse = 0;
    for (int i = 0; i < ELEMENTS; i++) {
        BytesRef bytesRef = new BytesRef(Strings.randomBase64UUID(random));
        if (gFilter.mightContain(bytesRef)) {
            gFalse++;
        }
        if (lFilter.contains(bytesRef) == FuzzySet.ContainsResult.MAYBE) {
            lFalse++;
        }
    }
    System.out.println("Failed positives, g[" + gFalse + "], l[" + lFalse + "]");
}