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:
-
id = /foo/bar/lux: Note, getIdentifier() is translated to solr field id through the @IndexField on the IdentifiableContentBean#getIdentifier() interface method
-
title = The title
-
authors = Collection that contains mike and john
Plus the following internal (auto) fields
-
hippo_path = /foo/bar/lux
-
hippo_path_hierarchy = {/foo, /foo/bar, /foo/bar/lux }
-
hippo_path_depth = 3
-
hippo_content_bean_fqn_clazz_name = org.example.beans.ExampleBean
-
hippo_content_bean_fqn_clazz_hierarchy = {org.example.beans.ExampleBean, org.hippoecm.hst.content.beans.standard.IdentifiableContentBean, org.hippoecm.hst.content.beans.standard.ContentBean}
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
-
Collection : the toString for all elements (unless elements are of type ContentBean) is taken and the Solr field must be multiValued
-
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
-
Calendar : DateUtils converted String representation suited for indexing
-
Date : DateUtils converted String representation suited for indexing
-
ContentBean : create an index of the ContentBean object and append to current, see
-
Collection with elements of type ContentBean : create an index of the ContentBean objects and append to current, see Compound ContentBean indexing
-
Array with elements of type ContentBean : create an index of the ContentBean objects and append to current, see Compound ContentBean indexing
-
Primitive : the toString of their auto-boxed variant
-
Object (including String) : the toString representation