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 :
-
Address getMainAddress()
-
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:
-
First part is the getter method name after get in the main bean and appended by _. Thus for the Contact this will be
-
getMainAddress() --> mainAddress_
-
getAllAddresses() --> allAddresses_
-
-
The name of the getter in the compound appended with _. Thus for getStreet() --> street_
-
If the method that returns a compound returns an Array or Collection of Compounds, the third part of the Solr field is multiple_
-
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
-
compound_t for String return type
-
compound_i for int or Integer return type
-
compound_l for long or Long
-
compound_b for boolean or Boolean
-
compound_f for float or Float
-
compound_d for double or Double
-
compound_dt for Date or Calendar
-
compound_mt for Array or Collection String return type
-
compound_mi for Array or Collection Integer return type (note no support for int)
-
compound_ml for Array or Collection Long (note no support for long)
-
compound_mb for Array or Collection Boolean (note no support for boolean)
-
compound_mf for Array or Collection Float (note no support for float)
-
compound_md for Array or Collection Double (note no support for double)
-
compound_mdt for Array or Collection Date or Calendar
-
-
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:
-
node_name_compound_t
-
node_node_name_compound_t
-
node_node_node_name_compound_t
-
etc depending on how deep the composite is