Example usage for org.apache.solr.common.util Hash murmurhash3_x86_32

List of usage examples for org.apache.solr.common.util Hash murmurhash3_x86_32

Introduction

In this page you can find the example usage for org.apache.solr.common.util Hash murmurhash3_x86_32.

Prototype

public static int murmurhash3_x86_32(CharSequence data, int offset, int len, int seed) 

Source Link

Document

Returns the MurmurHash3_x86_32 hash of the UTF-8 bytes of the String without actually encoding the string to a temporary buffer.

Usage

From source file:org.alfresco.solr.tracker.ACLIDMurmurRouter.java

License:Open Source License

private boolean route(long id, int numShards, int shardInstance) {
    String value = Long.toString(id);
    return (Math.abs(Hash.murmurhash3_x86_32(value, 0, value.length(), 77)) % numShards) == shardInstance;
}

From source file:org.alfresco.solr.tracker.DBIDRouter.java

License:Open Source License

@Override
public Boolean routeNode(int shardCount, int shardInstance, Node node) {
    if (shardCount <= 1) {
        return true;
    }/*  w ww . ja  va 2 s.  c  o  m*/

    String dbid = Long.toString(node.getId());
    return (Math.abs(Hash.murmurhash3_x86_32(dbid, 0, dbid.length(), 77)) % shardCount) == shardInstance;
}

From source file:org.alfresco.solr.tracker.PropertyRouter.java

License:Open Source License

@Override
public Boolean routeNode(int shardCount, int shardInstance, Node node) {
    if (shardCount <= 1) {
        return true;
    }/*from  www .  j av  a2 s .  co m*/

    String shardBy = node.getShardPropertyValue();
    if (shardBy != null && pattern != null) {
        try {
            Matcher matcher = pattern.matcher(shardBy);
            if (matcher.find() && !matcher.group(1).isEmpty()) {
                shardBy = matcher.group(1);
            } else {
                //If a reqex is specified but it doesn't match, then use the fallback
                shardBy = null;
            }
        } catch (IndexOutOfBoundsException | NullPointerException exc) {
            LOGGER.debug("Regex matched, but group 1 not found, so falling back to DBID sharding.");
            shardBy = null;
        }
    }

    if (shardBy == null || shardBy.isEmpty()) {
        LOGGER.debug("Property not found or regex not matched, so falling back to DBID sharding.");
        return fallback.routeNode(shardCount, shardInstance, node);
    }

    return (Math.abs(Hash.murmurhash3_x86_32(shardBy, 0, shardBy.length(), 66)) % shardCount) == shardInstance;
}