Example usage for org.apache.lucene.util StringHelper murmurhash3_x86_32

List of usage examples for org.apache.lucene.util StringHelper murmurhash3_x86_32

Introduction

In this page you can find the example usage for org.apache.lucene.util StringHelper murmurhash3_x86_32.

Prototype

public static int murmurhash3_x86_32(BytesRef bytes, int seed) 

Source Link

Usage

From source file:io.crate.execution.engine.distribution.ModuloBucketBuilder.java

License:Apache License

private static int hashCode(@Nullable Object value) {
    if (value == null) {
        return 0;
    }/*  w w  w . j  ava  2 s .c o m*/
    if (value instanceof BytesRef) {
        // since lucene 4.8
        // BytesRef.hashCode() uses a random seed across different jvm
        // which causes the hashCode / routing to be different on each node
        // this breaks the group by redistribution logic - need to use a fixed seed here
        // to be consistent.
        return StringHelper.murmurhash3_x86_32(((BytesRef) value), 1);
    }
    return value.hashCode();
}

From source file:io.crate.operation.collect.ModuloBucketingIterator.java

License:Apache License

private static int hashCode(Object value) {
    if (value instanceof BytesRef) {
        // since lucene 4.8
        // BytesRef.hashCode() uses a random seed across different jvm
        // which causes the hashCode / routing to be different on each node
        // this breaks the group by redistribution logic - need to use a fixed seed here
        // to be consistent.
        return StringHelper.murmurhash3_x86_32(((BytesRef) value), 1);
    }// ww w.  ja v  a2 s  .co  m
    return value.hashCode();
}

From source file:org.codelibs.elasticsearch.common.lucene.search.function.RandomScoreFunction.java

License:Apache License

@Override
public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) {
    AtomicFieldData leafData = uidFieldData.load(ctx);
    final SortedBinaryDocValues uidByteData = leafData.getBytesValues();
    if (uidByteData == null) {
        throw new NullPointerException("failed to get uid byte data");
    }//from w  w  w .  ja va  2  s . c o m

    return new LeafScoreFunction() {

        @Override
        public double score(int docId, float subQueryScore) {
            uidByteData.setDocument(docId);
            int hash = StringHelper.murmurhash3_x86_32(uidByteData.valueAt(0), saltedSeed);
            return (hash & 0x00FFFFFF) / (float) (1 << 24); // only use the lower 24 bits to construct a float from 0.0-1.0
        }

        @Override
        public Explanation explainScore(int docId, Explanation subQueryScore) {
            return Explanation.match(CombineFunction.toFloat(score(docId, subQueryScore.getValue())),
                    "random score function (seed: " + originalSeed + ")");
        }
    };
}