ContentBean and IdentifiableContentBean indexing

As mentioned at ContentBean and IdentifiableContentBean, objects that implement either ContentBean or IdentifiableContentBean are suited for indexing, with the only difference that IdentifiableContentBean can be used as Solr index document and ContentBean implementations for compounds : See Compound ContentBean indexing for this.

The HST DocumentObjectBinder takes care of creating a Solr index document from an object (bean/pojo). From a bean, all super classes (including interfaces) are scanned for the presence of the @IndexField annotation on getters. For all these getters, the return value is indexed. If a getter returns a ContentBean instance, this ContentBean is indexed as part of the IdentifiableContentBean.

Example of IdentifiableContentBean object and the resulting Solr index document:

import org.hippoecm.hst.content.beans.index.IndexField;
import org.hippoecm.hst.content.beans.standard.IdentifiableContentBean;

package org.example.beans
public class ExampleBean implements IdentifiableContentBean {

    private String path;
    private String title;
    private String[] authors;

    public ExampleBean() {
    }

    public ExampleBean(String identifier, String title, String[] authors) {
        this.identifier = identifier;
        this.title = title;
        this.authors = authors;
    }

    @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;
    }

    @IndexField
    public String[] getAuthors() {
        return authors;
    }

    public void setAuthors(final String[] authors) {
        this.authors = authors;
    }
}

Assume the following ExampleBean instance:

ExampleBean bean = new ExampleBean("/foo/bar/lux",
                                   "The title",
                                    new String[] {"mike", "john"});

This would result in a Solr index document containing:

  1. id = /foo/bar/lux: Note, getIdentifier() is translated to solr field id through the @IndexField on the IdentifiableContentBean#getIdentifier() interface method

  2. title = The title

  3. authors = Collection that contains mike and john

Plus the following internal (auto) fields

  1. hippo_path = /foo/bar/lux

  2. hippo_path_hierarchy = {/foo, /foo/bar, /foo/bar/lux }

  3. hippo_path_depth = 3

  4. hippo_content_bean_fqn_clazz_name = org.example.beans.ExampleBean

  5. hippo_content_bean_fqn_clazz_hierarchy = {org.example.beans.ExampleBean, org.hippoecm.hst.content.beans.standard.IdentifiableContentBean, org.hippoecm.hst.content.beans.standard.ContentBean}

When the bean is a HippoBean, the #getPath() method will be used for hippo_path and hippo_path_hierarchy. Otherwise, #getIdentifier() will be used

The internal fields and id are mandatory in the Solr schema.xml. The fields title and authors must be added to the schema.xml by the developer. Since author is multiple, the schema must account for this:

<field name="title" type="text_general" indexed="true" stored="true" />
<field name="authors" type="text_general" indexed="true" stored="true"
       multiValued="true"/>

Most likely, you'd also like the default free text search to search in title and authors field as well, hence, you most likely also want to add:

<copyField source="title" dest="text"/>
<copyField source="authors" dest="text"/>

If for example you'd also like the authors to be used for, say faceted navigation, you'd also want to index the names as string (no tokenization) in Solr . In that case, you need to add something like:

<field name="authorsstring" type="string" indexed="true" stored="false"
       multiValued="true"/>
<copyField source="authors" dest="authorsstring"/>

This is plain Solr schema.xml configuration though, which can be found at the Solr documentation

Method return types for indexing

When creating a Solr index field for an annotated @IndexField getter method we index as follows: For return type

  1. Collection : the toString for all elements (unless elements are of type ContentBean) is taken and the Solr field must be multiValued

  2. Array : the toString for all elements (unless elements are of type ContentBean) is taken and the Solr field must be multiValued. If the elements are primitive, the toString of their auto-boxed equivalent are used

  3. Calendar : DateUtils converted String representation suited for indexing

  4. Date : DateUtils converted String representation suited for indexing

  5. ContentBean : create an index of the ContentBean object and append to current, see

  6. Collection with elements of type ContentBean : create an index of the ContentBean objects and append to current, see Compound ContentBean indexing

  7. Array with elements of type ContentBean : create an index of the ContentBean objects and append to current, see Compound ContentBean indexing

  8. Primitive : the toString of their auto-boxed variant

  9. Object (including String) : the toString representation

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?