Indexing annotations

The HST has added some annotations for making Solr indexing on beans possible. The annotations are:

  1. IndexField : Annotation that can be added to getter methods of ContentBeans which return values (objects) that should be indexed

  2. Indexable : Annotation that can be added to a class to indicate it should not be indexed if ignore = true. For example a HippoFacetNavigation is not desirable to index

IndexField

It can be applied to public getter methods ('getFoo()' and 'isFoo()'). It can have two parameters, name and ignoreInCompound. If name is specified, the value is used as the index field in Solr (schema.xml). If missing, the index field is taken from the getter method by stripping the 'get' or 'is' part and lowercase the first next letter. A very basic example of a IdentifiableContentBean with an indexable title field is as follows:


public class MyContentBean implements IdentifiableContentBean {

    private String identifier;
    private String title;

    public TestContentBean(String identifier, String title) {
        this.identifier = identifier;
        this.title = title;
    }

    @Override
    public String getIdentifier() {
        return identifier;
    }

    @Override
    public void setIdentifier(final String identifier) {
        this.identifier = identifier;
    }

    @IndexField
    public String getTitle() {
        return title;
    }

    public void setTitle(final String title) {
        this.title = title;
    }
}

Note above that #getIdentifier() does not need an @IndexField annotation. This is because IdentifiableContentBean already contains:

public interface IdentifiableContentBean extends ContentBean {

    @IndexField(name="id", ignoreInCompound = true)
    String getIdentifier();

    void setIdentifier(String identifier);
}

Indexing the title as a different field

In an @IndexField annotation you can also specifiy what Solr field to use for indexing the property. This is done through the name attribute. For example:

@IndexField(name="titleField")
public String getTitle() {
  return title;
}

public void setTitle(final String title) {
  this.title = title;
} 

Expert: Ignore a field in case the bean is part of a compound

Typically, when you have a IdentifiableContentBean, you want some getters to be indexed. Also compound beans that are exposed through a getter can be indexed, for example:

public class MyContentBean implements IdentifiableContentBean {

    ....

    private Address address

    @IndexField
    public Address getAddress() {
        return address;
    }

    public void setAddress(final Address address) {
        this.address = address;
    }
}

Since Address itself might be an IdentifiableContentBean as well, you do not want the identifier to be indexed again. Hence, the IdentifiableContentBean contains ignoreInCompound

@IndexField(name="id", ignoreInCompound = true)
String getIdentifier(); 

Indexable

The indexable annotation can be used to mark some (Identifiable)ContentBean unsuited for indexing at all, and is always ignored. For example a bean that exposes faceted navigation is never needed to be index. This can be achieved as follows:

@Indexable(ignore = true)
@Node(jcrType="hippofacnav:facetnavigation")
public class HippoFacetNavigation extends HippoFolder
                         implements HippoFacetNavigationBean {
        ......
}

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?