org.compass.core.engine.subindex
Class ModuloSubIndexHash

java.lang.Object
  extended by org.compass.core.engine.subindex.ModuloSubIndexHash
All Implemented Interfaces:
CompassConfigurable, SubIndexHash

public class ModuloSubIndexHash
extends Object
implements SubIndexHash, CompassConfigurable

Uses a hash function based on hash code computation of alias and ids, and using the modulo operation against the configured size.

The sub index name is prefix_(hashCode % size).

If using configuration, expects prefix as the setting name, and size as the modulo right hand side operation.

Author:
kimchy

Constructor Summary
ModuloSubIndexHash()
          Constructs a new instance, will have to be configured.
ModuloSubIndexHash(String prefix, int size)
          Constructs a new instance, using the given prefix and size.
 
Method Summary
 void configure(CompassSettings settings)
          Using configuration, expects prefix as the setting name, and size as the modulo right hand side operation.
 String[] getSubIndexes()
          Returns all the sub indexes possible, basically in the form of prefix_(0..size) (not including size).
 String mapSubIndex(String alias, Property[] ids)
          Computes the hash code of alias and all the ids, and then modulo it by size.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModuloSubIndexHash

public ModuloSubIndexHash()
Constructs a new instance, will have to be configured.


ModuloSubIndexHash

public ModuloSubIndexHash(String prefix,
                          int size)
Constructs a new instance, using the given prefix and size.

Parameters:
prefix - The prefix sed for the sub index prefix name
size - The size the modulo will be used
Method Detail

configure

public void configure(CompassSettings settings)
               throws CompassException
Using configuration, expects prefix as the setting name, and size as the modulo right hand side operation.

Specified by:
configure in interface CompassConfigurable
Parameters:
settings - The setting to configure by
Throws:
CompassException

getSubIndexes

public String[] getSubIndexes()
Returns all the sub indexes possible, basically in the form of prefix_(0..size) (not including size).

Specified by:
getSubIndexes in interface SubIndexHash

mapSubIndex

public String mapSubIndex(String alias,
                          Property[] ids)
                   throws SearchEngineException
Computes the hash code of alias and all the ids, and then modulo it by size. The prefix is prepended (with an underscore), and the sub index is constructed. The formula is: prefix_(hashCode % size).

Specified by:
mapSubIndex in interface SubIndexHash
Parameters:
alias - The alias to compute the sub index by (optional)
ids - The set of ids to compute the sub index by (optional)
Returns:
The hashed sub index
Throws:
SearchEngineException

toString

public String toString()
Overrides:
toString in class Object


Copyright (c) 2004-2009 The Compass Project.