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

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

Introduction

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

Prototype

public static FuzzySet createSetBasedOnMaxMemory(int maxNumBytes) 

Source Link

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  ww.  ja  v  a  2s.  c o  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 + "]");
}