mirror of https://github.com/apache/lucene.git
SOLR-5258 compute full composite hash on router.field
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1528113 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
86d5dd6529
commit
d36147eca7
|
@ -414,6 +414,12 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
|
||||||
//TODO debug the following case
|
//TODO debug the following case
|
||||||
assertEquals(3, collectionClient.query(new SolrQuery("*:*").setParam(_ROUTE_, "a")).getResults().getNumFound());
|
assertEquals(3, collectionClient.query(new SolrQuery("*:*").setParam(_ROUTE_, "a")).getResults().getNumFound());
|
||||||
|
|
||||||
|
collectionClient.deleteByQuery("*:*");
|
||||||
|
collectionClient.commit();
|
||||||
|
|
||||||
|
collectionClient.add (getDoc( id,100,shard_fld, "b!doc1"));
|
||||||
|
collectionClient.commit();
|
||||||
|
assertEquals(1, collectionClient.query(new SolrQuery("*:*").setParam(_ROUTE_, "b!")).getResults().getNumFound());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,10 @@ import java.util.List;
|
||||||
public class CompositeIdRouter extends HashBasedRouter {
|
public class CompositeIdRouter extends HashBasedRouter {
|
||||||
public static final String NAME = "compositeId";
|
public static final String NAME = "compositeId";
|
||||||
|
|
||||||
private int separator = '!';
|
private static final int separator = '!';
|
||||||
|
|
||||||
// separator used to optionally specify number of bits to allocate toward first part.
|
// separator used to optionally specify number of bits to allocate toward first part.
|
||||||
private int bitsSeparator = '/';
|
private static final int bitsSeparator = '/';
|
||||||
private int bits = 16;
|
private int bits = 16;
|
||||||
private int mask1 = 0xffff0000;
|
private int mask1 = 0xffff0000;
|
||||||
private int mask2 = 0x0000ffff;
|
private int mask2 = 0x0000ffff;
|
||||||
|
@ -62,28 +62,18 @@ public class CompositeIdRouter extends HashBasedRouter {
|
||||||
@Override
|
@Override
|
||||||
public int sliceHash(String id, SolrInputDocument doc, SolrParams params, DocCollection collection) {
|
public int sliceHash(String id, SolrInputDocument doc, SolrParams params, DocCollection collection) {
|
||||||
String shardFieldName = getRouteField(collection);
|
String shardFieldName = getRouteField(collection);
|
||||||
String part1 = null;
|
if (shardFieldName != null && doc != null) {
|
||||||
int idx = 0;
|
|
||||||
int commaIdx = 0;
|
|
||||||
|
|
||||||
if(shardFieldName == null || doc == null) {
|
|
||||||
idx = id.indexOf(separator);
|
|
||||||
if (idx < 0) {
|
|
||||||
return Hash.murmurhash3_x86_32(id, 0, id.length(), 0);
|
|
||||||
}
|
|
||||||
part1 = id.substring(0, idx);
|
|
||||||
commaIdx = part1.indexOf(bitsSeparator);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Object o = doc.getFieldValue(shardFieldName);
|
Object o = doc.getFieldValue(shardFieldName);
|
||||||
if (o != null) {
|
if (o == null)
|
||||||
part1 = o.toString();
|
|
||||||
return Hash.murmurhash3_x86_32(part1, 0, part1.length(), 0);
|
|
||||||
} else {
|
|
||||||
throw new SolrException (SolrException.ErrorCode.BAD_REQUEST, "No value for :"+shardFieldName + ". Unable to identify shard");
|
throw new SolrException (SolrException.ErrorCode.BAD_REQUEST, "No value for :"+shardFieldName + ". Unable to identify shard");
|
||||||
}
|
id = o.toString();
|
||||||
}
|
}
|
||||||
|
int idx = id.indexOf(separator);
|
||||||
|
if (idx < 0) {
|
||||||
|
return Hash.murmurhash3_x86_32(id, 0, id.length(), 0);
|
||||||
|
}
|
||||||
|
String part1 = id.substring(0, idx);
|
||||||
|
int commaIdx = part1.indexOf(bitsSeparator);
|
||||||
int m1 = mask1;
|
int m1 = mask1;
|
||||||
int m2 = mask2;
|
int m2 = mask2;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue