Package org.apache.solr.common.cloud

# Class CompositeIdRouter

java.lang.Object
org.apache.solr.common.cloud.DocRouter
org.apache.solr.common.cloud.HashBasedRouter
org.apache.solr.common.cloud.CompositeIdRouter

public class CompositeIdRouter extends HashBasedRouter
CompositeIdRouter partitions ids based on a `SEPARATOR`, hashes each partition and merges the hashes together to map the id to a slice. This allows bucketing of like groups of ids.

Allows basic separation split between 32 bits as example given below, or using `bitsSeparator` can specify exact bits

     Example inputs:
     user!uniqueid
     app!user!uniqueid
     user/4!uniqueid
     app/2!user/4!uniqueid

Let's say you had a set of records you want to index together such as a contact in a database, using a prefix of contact!contactid would allow all contact ids to be bucketed together.

     An Example:
     If the id "contact!0000000KISS is passed 😘
     Take "contact"" and hash it with murmurhash3_x86_32
     result: -541354036
     bits: 11011111101110111001011111001100

     Take 0000000KISS and hash it with murmurhash3_x86_32
     result: 2099700320
     bits: 01111101001001101110001001100000

     Now we take the bits and apply a mask, since this is 32 bits the mask is the first 16 bits or the last 16 bits
     So uppermask = 0xFFFF0000  11111111111111110000000000000000
     So we bitwise AND to get half the original hash and only the upper 16 bits for 00T
     11011111101110111001011111001100
     11111111111111110000000000000000
     ________________________________
     11011111101110110000000000000000

     lowermask = 0x0000FFFF 00000000000000001111111111111111
     So we bitwise AND and get the lower 16 bits of the original hash for 0000000KISS
     01111101001001101110001001100000
     00000000000000001111111111111111
     ________________________________
     00000000000000001110001001100000

     Now we combine the hashes with a bitwise OR
     11011111101110110000000000000000
     00000000000000001110001001100000
     ________________________________
     11011111101110111110001001100000

     11011111101110111110001001100000 is the hash we return, bucketing the suffixed by prefix type prefix!suffix

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected static class`
`CompositeIdRouter.KeyParser`
Helper class to calculate parts, masks etc.

## Nested classes/interfaces inherited from class org.apache.solr.common.cloud.DocRouter

`DocRouter.Range`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`bitsSeparator`
`static final String`
`NAME`
`static final char`
`SEPARATOR`
This character separates a composite ID into a leading route key and the rest.

### Fields inherited from class org.apache.solr.common.cloud.DocRouter

`DEFAULT, DEFAULT_NAME`

## Constructor Summary

Constructors
Constructor
Description
`CompositeIdRouter()`

## Method Summary

Modifier and Type
Method
Description
`String`
`getName()`
`String`
`getRouteKeyNoSuffix(String id)`
Parse out the route key from `id`.
`int`
`getRouteKeyWithSeparator(byte[] id, int idOffset, int idLength)`
Parse out the route key from `id` up to and including the `SEPARATOR`, returning its length.
`DocRouter.Range`
`getSearchRangeSingle(String shardKey, SolrParams params, DocCollection collection)`
This method is consulted to determine what search range (the part of the hash ring) should be queried for a request when an explicit shards' parameter was not used.
`Collection<Slice>`
`getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection)`
This method is consulted to determine what slices should be queried for a request when an explicit shards' parameter was not used.
`Slice`
`getTargetSlice(String id, SolrInputDocument sdoc, String route, SolrParams params, DocCollection collection)`
Returns the Slice that the document should reside on, or null if there is not enough information
`DocRouter.Range`
`keyHashRange(String routeKey)`
Get Range for a given CompositeId based route key
`List<DocRouter.Range>`
`partitionRange(int partitions, DocRouter.Range range)`
Split the range into partitions.
`List<DocRouter.Range>`
`partitionRangeByKey(String key, DocRouter.Range range)`
`protected String`
`preprocessRouteKey(String shardKey)`
Methods accepting a route key (shard key) can have this input preprocessed by a subclass before further analysis.
`int`
`sliceHash(String id, SolrInputDocument doc, SolrParams params, DocCollection collection)`

### Methods inherited from class org.apache.solr.common.cloud.HashBasedRouter

`getId, hashToSlice, isTargetSlice`

### Methods inherited from class org.apache.solr.common.cloud.DocRouter

`fromString, fullRange, getDocRouter, getRouteField, getRouterSpec, getSearchSlices, partitionRange`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### NAME

public static final String NAME

See Also:
  - Constant Field Values

### SEPARATOR

public static final char SEPARATOR
This character separates a composite ID into a leading route key and the rest.

Importantly, it's also used at the end of a provided route key parameter (which appears in many places) to designate a hash range which translates to a list of slices. If a route key does not end with this character, then semantically the key points to a single slice that holds a doc with that ID.

See Also:
  - Constant Field Values

### bitsSeparator

public static final int bitsSeparator

See Also:
  - Constant Field Values

## Constructor Details

### CompositeIdRouter

public CompositeIdRouter()

## Method Details

### getRouteKeyWithSeparator

public int getRouteKeyWithSeparator(byte[] id, int idOffset, int idLength)
Parse out the route key from `id` up to and including the `SEPARATOR`, returning its length. If no route key is detected then 0 is returned.

### getRouteKeyNoSuffix

public String getRouteKeyNoSuffix(String id)
Parse out the route key from `id`. It will not have the "bits" suffix or separator, if present. If there is no route key found then null is returned.

### sliceHash

public int sliceHash(String id, SolrInputDocument doc, SolrParams params, DocCollection collection)

Overrides:
  `sliceHash` in class `HashBasedRouter`

### getTargetSlice

public Slice getTargetSlice(String id, SolrInputDocument sdoc, String route, SolrParams params, DocCollection collection)
Description copied from class: `DocRouter`
Returns the Slice that the document should reside on, or null if there is not enough information

Overrides:
  `getTargetSlice` in class `HashBasedRouter`

### keyHashRange

public DocRouter.Range keyHashRange(String routeKey)
Get Range for a given CompositeId based route key

Parameters:
  `routeKey` - to return Range for
Returns:
  Range for given routeKey

### getSearchRangeSingle

public DocRouter.Range getSearchRangeSingle(String shardKey, SolrParams params, DocCollection collection)
Description copied from class: `DocRouter`
This method is consulted to determine what search range (the part of the hash ring) should be queried for a request when an explicit shards' parameter was not used. This method only accepts a single shard key (or null).

Overrides:
  `getSearchRangeSingle` in class `DocRouter`

### getSearchSlicesSingle

public Collection<Slice> getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection)
Description copied from class: `DocRouter`
This method is consulted to determine what slices should be queried for a request when an explicit shards' parameter was not used. This method only accepts a single shard key (or null). If you have a comma separated list of shard keys, call getSearchSlices

Overrides:
  `getSearchSlicesSingle` in class `HashBasedRouter`

### preprocessRouteKey

protected String preprocessRouteKey(String shardKey)
Methods accepting a route key (shard key) can have this input preprocessed by a subclass before further analysis.

### getName

public String getName()

Specified by:
  `getName` in class `DocRouter`

### partitionRangeByKey

public List<DocRouter.Range> partitionRangeByKey(String key, DocRouter.Range range)

### partitionRange

public List<DocRouter.Range> partitionRange(int partitions, DocRouter.Range range)
Description copied from class: `DocRouter`
Split the range into partitions.

Overrides:
  `partitionRange` in class `DocRouter`
Parameters:
  `partitions` - number of partitions
  `range` - range to split