Compound ContentBean indexing - BloomReach Experience - Open Source CMS

This article covers a Hippo CMS version 10. There's an updated version available that covers our most recent release.

12-05-2015

Compound ContentBean indexing

We've seen ContentBean and IdentifiableContentBean indexing. When a ContentBean is part the return method of an IdentifiableContentBean, this ContentBean (Compound) can be indexed as well with the @IndexField annotation. Even composite patterns can be indexed.

Compound indexing example

public class Contact implements IdentifiableContentBean {
    private String identifier;
    private Address main;
    private List<Address> all;

    public TestBaseContentBean(String identifier, Address main,
                               List<Address> all) {
        this.identifier = identifier;
        this.main = main;
        this.all = all;
    }

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

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

    @IndexField
    public Address getMainAddress() {
        return main;
    }

    @IndexField
    public List<Address> getAllAddresses() {
        return all;
    }
}

Above, the Contact bean contains Compound beans :

  1. Address getMainAddress()

  2. List<Address> getAllAddresses()

Since there is an @IndexField on the getMainAddress() and getAllAddresses() these will also be indexed. Now, assume the Address bean looks like :

public class Address implements ContentBean {
    private String street;
    private int number;
    public TestAddress(String street, int number) {
        this.street = street;
        this.number = number;
    }

    @IndexField
    public String getStreet() {
        return street;
    }

    @IndexField
    public int getNumber() {
        return number;
    }
}

Now, when the Contact gets indexed, also the compounds get indexed. The Compound beans need to get indexed in some Solr field. The Solr field that is used is constructed as follows:

  1. First part is the getter method name after get in the main bean and appended by _. Thus for the Contact this will be

    1. getMainAddress() --> mainAddress_

    2. getAllAddresses() --> allAddresses_

  2. The name of the getter in the compound appended with _. Thus for getStreet() --> street_

  3. If the method that returns a compound returns an Array or Collection of Compounds, the third part of the Solr field is multiple_

  4. If the @IndexField does not contain a name that ends with _xxx (where xxx is any text), the last part of the Solr field is

    1. compound_t for String return type

    2. compound_i for int or Integer return type

    3. compound_l for long or Long

    4. compound_b for boolean or Boolean

    5. compound_f for float or Float

    6. compound_d for double or Double

    7. compound_dt for Date or Calendar

    8. compound_mt for Array or Collection String return type

    9. compound_mi for Array or Collection Integer return type (note no support for int)

    10. compound_ml for Array or Collection Long (note no support for long)

    11. compound_mb for Array or Collection Boolean (note no support for boolean)

    12. compound_mf for Array or Collection Float (note no support for float)

    13. compound_md for Array or Collection Double (note no support for double)

    14. compound_mdt for Array or Collection Date or Calendar

  5. If the @IndexField contains a name that ends with _xxx, then this part is appended as _xxx

Populated beans from a search result will not have their Compounds repopulated

Composite Compound indexing

Composite patterns can also be indexed. For example:

public class Tree implements IdentifiableContentBean {
    Node node;
    public Tree(String identifier, Node node) {
        this.identifier = identifier;
        this.node = node;
    }
    @Override
    public String getIdentifier() {
        return identifier;
    }

    @IndexField
    public Node getNode() {
        return node;
    }
}

Tree with composite node structure:

public class Node implements ContentBean {
    String name;
    Node child;
    public Node(String name, Node child) {
        this.name = name;
        this.child = child;
    }
    @IndexField
    public String getName() {
        return name;
    }

    @IndexField
    public Node getNode() {
        return child;
    }
}

Now, the Tree wil get indexed containing fields:

  1. node_name_compound_t

  2. node_node_name_compound_t

  3. node_node_node_name_compound_t

  4. etc depending on how deep the composite is

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?