org.apache.lucene.facet.enhancements.association
Class AssociationEnhancement

java.lang.Object
  extended by org.apache.lucene.facet.enhancements.association.AssociationEnhancement
All Implemented Interfaces:
CategoryEnhancement

public class AssociationEnhancement
extends Object
implements CategoryEnhancement

A CategoryEnhancement for adding associations data to the index (categories with AssociationPropertys).

WARNING: This API is experimental and might change in incompatible ways in the next release.

Constructor Summary
AssociationEnhancement()
           
 
Method Summary
 boolean equals(Object o)
          Category enhancements must override Object.equals(Object), as it is used in EnhancementsPayloadIterator.getCategoryData(CategoryEnhancement).
 Object extractCategoryTokenData(byte[] buffer, int offset, int length)
          Get the data of this enhancement from a category token payload.
 boolean generatesCategoryList()
          Declarative method to indicate whether this enhancement generates separate category list.
static AssociationProperty getAssociationProperty(CategoryAttribute categoryAttribute)
           
 String getCategoryListTermText()
          Returns the text of this enhancement's category list term.
 CategoryListTokenizer getCategoryListTokenizer(TokenStream tokenizer, EnhancementsIndexingParams indexingParams, TaxonomyWriter taxonomyWriter)
          Get the CategoryListTokenizer which generates the category list for this enhancement.
 byte[] getCategoryTokenBytes(CategoryAttribute categoryAttribute)
          Get the bytes to be added to the category token payload for this enhancement.
 Class<? extends CategoryProperty> getRetainableProperty()
          Get a CategoryProperty class to be retained when creating CategoryParentsStream.
 int hashCode()
           
static boolean isAssociationProperty(Class<? extends CategoryProperty> clazz)
          For a given class which extends a CategoryProperty, answers whether it is an instance of AssociationProperty (AP) or not.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssociationEnhancement

public AssociationEnhancement()
Method Detail

isAssociationProperty

public static boolean isAssociationProperty(Class<? extends CategoryProperty> clazz)
For a given class which extends a CategoryProperty, answers whether it is an instance of AssociationProperty (AP) or not.
This method is a cheaper replacement for a call to instanceof. It has two HashSets - one for classes which are an extension to AP and one for the classes which are not. Whenever a property class is introduced: NOTE: 'instanceof' is only called once per a Class (not instance) of a property. And as there are few properties (currently 4 concrete implementations) the two sets would be rather small


generatesCategoryList

public boolean generatesCategoryList()
Description copied from interface: CategoryEnhancement
Declarative method to indicate whether this enhancement generates separate category list.

Specified by:
generatesCategoryList in interface CategoryEnhancement
Returns:
true if generates category list, else false.

getCategoryListTermText

public String getCategoryListTermText()
Description copied from interface: CategoryEnhancement
Returns the text of this enhancement's category list term.

Specified by:
getCategoryListTermText in interface CategoryEnhancement
Returns:
The text of this enhancement's category list term.

getCategoryListTokenizer

public CategoryListTokenizer getCategoryListTokenizer(TokenStream tokenizer,
                                                      EnhancementsIndexingParams indexingParams,
                                                      TaxonomyWriter taxonomyWriter)
Description copied from interface: CategoryEnhancement
Get the CategoryListTokenizer which generates the category list for this enhancement. If CategoryEnhancement.generatesCategoryList() returns false this method will not be called.

Specified by:
getCategoryListTokenizer in interface CategoryEnhancement
Parameters:
tokenizer - The input stream containing categories.
indexingParams - The indexing params to use.
taxonomyWriter - The taxonomy to add categories and get their ordinals.
Returns:
A CategoryListTokenizer generating the category list for this enhancement, with tokenizer as it's input.

getCategoryTokenBytes

public byte[] getCategoryTokenBytes(CategoryAttribute categoryAttribute)
Description copied from interface: CategoryEnhancement
Get the bytes to be added to the category token payload for this enhancement.

NOTE: The returned array is copied, it is recommended to allocate a new one each time.

The bytes generated by this method are the input of CategoryEnhancement.extractCategoryTokenData(byte[], int, int).

Specified by:
getCategoryTokenBytes in interface CategoryEnhancement
Parameters:
categoryAttribute - The attribute of the category.
Returns:
The bytes to be added to the category token payload for this enhancement.

getAssociationProperty

public static AssociationProperty getAssociationProperty(CategoryAttribute categoryAttribute)

extractCategoryTokenData

public Object extractCategoryTokenData(byte[] buffer,
                                       int offset,
                                       int length)
Description copied from interface: CategoryEnhancement
Get the data of this enhancement from a category token payload.

The input bytes for this method are generated in CategoryEnhancement.getCategoryTokenBytes(CategoryAttribute).

Specified by:
extractCategoryTokenData in interface CategoryEnhancement
Parameters:
buffer - The payload buffer.
offset - The offset of this enhancement's data in the buffer.
length - The length of this enhancement's data (bytes).
Returns:
An Object containing the data.

getRetainableProperty

public Class<? extends CategoryProperty> getRetainableProperty()
Description copied from interface: CategoryEnhancement
Get a CategoryProperty class to be retained when creating CategoryParentsStream.

Specified by:
getRetainableProperty in interface CategoryEnhancement
Returns:
the CategoryProperty class to be retained when creating CategoryParentsStream, or null if there is no such property.

equals

public boolean equals(Object o)
Description copied from interface: CategoryEnhancement
Category enhancements must override Object.equals(Object), as it is used in EnhancementsPayloadIterator.getCategoryData(CategoryEnhancement).

Specified by:
equals in interface CategoryEnhancement
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object