Solr HippoQueryResult

Once you have bootstrapped the HippoQuery and added all constraints you want to SolrQuery, you execute the query as follows :

HippoSolrClient solrClient = HstServices.getComponentManager().
                               getComponent(HippoSolrClient.class.getName(),
                                            "org.hippoecm.hst.solr");
// Below creates a bootstrapped HippoQuery, which,
// under the hood, also bootstraps the SolrQuery
HippoQuery hippoQuery = solrClient.createQuery(query);
HippoQueryResult result = hippoQuery.execute();

The HippoQueryResult is a wrapper object around the plain org.apache.solr.client.solrj.response.QueryResponse, adding some extra facility methods. The Solrj QueryResponse is a simple to use object, with many getter methods that can be directly used in your renderer. Also see the examples at Testsuite example. What the Solrj QueryResponse does not provide, is a seamless integration with your IdentifiableContentBean's. This is added by the HippoQueryResult through

HitIterator hits =  result.getHits();

The HitIterator gives access to the hits in the result through:

HitIterator hits =  result.getHits();
Hit hit = hits.next();

and finally the Hit has provides access to the plain SolrDocument, the IdentifiableContentBean, and, if the query was executed to include score or highlights, these are also available :

public interface Hit extends Serializable {

    SolrDocument getDoc();

    /**
     * @return the {@link IdentifiableContentBean}
     * @throws BindingException when the {@link SolrDocument} cannot
     * be binded to the {@link IdentifiableContentBean}
     */
    IdentifiableContentBean getBean() throws BindingException;

    /**
     * @return the score for this hit and -1
     * if there is no score available
     */
    float getScore();

    /**
     * @return the {@link List} of {@link Highlight}s and
     * empty List if there are no highlights
     */
    public List<Highlight> getHighlights();
}

Bind the IdentifiableContentBean in the HippoQueryResult to their backing providers

By default, when you call hippoQuery.execute(), the IdentifiableContentBean in the Hit objects are only populated by calling the setter methods for the properties that have stored Solr fields.

When you want to bind your hits to their original data providers, you have to call this explicitly

This means, that only those fields are populated that

  1. are part of the IdentifiableContentBean and not of one of its Compound beans

  2. where stored in the Solr index

  3. have a setter method for the getter methods that have @IndexField

The reason for not binding the results by default to their original data provider is performance : No jcr nodes or no external sources need to be fetched.

For optimal performance, you do not bind the hits to their original data providers

However, you can have many reason why you need the backing data providers, for example because in your search results you need the compound beans to be accessible as well. There are two methods through which you can bind your hits to their original providers:

void setContentBeanBinders();
void setContentBeanBinders(List<ContentBeanBinder> binders);

See HippoQueryResult javadocs or ContentBeanBinder for more about this.

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?