Search for specific ContentBean's only - BloomReach Experience - Open Source CMS

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

Search for specific ContentBean's only

Frequently, you want to search for example only for NewsDocuments, or documents that extend your BaseDocument type. This is possible out of the box through the hippo_content_bean_fqn_clazz_hierarchy, see ContentBean and IdentifiableContentBean indexing. You can even search for beans that implement some interface, for example the NodeAware interface. Thus, you can search for supertypes of the entire class hierarchy including interfaces of your beans objects (except the class Object, that one is skipped)

If you only want to search for NewsDocuments, you can do this through:

HippoSolrClient solrClient =
      HstServices.getComponentManager().getComponent(
                    HippoSolrClient.class.getName(), "org.hippoecm.hst.solr");
HippoQuery hippoQuery = solrClient.createQuery(query);
hippoQuery.setIncludedClasses(false, NewsDocument.class);

If you want to search for NewsDocuments and AgendaDocuments only, you can use

HippoSolrClient solrClient =
      HstServices.getComponentManager().getComponent(
                   HippoSolrClient.class.getName(), "org.hippoecm.hst.solr");
HippoQuery hippoQuery = solrClient.createQuery(query);
// the arguments after the first boolean is a varargs class argument
hippoQuery.setIncludedClasses(false, NewsDocument.class,
                              AgendaDocument.class);

If you want to search for all BaseDocuments including subtypes, except for NewsDocuments and AgendaDocuments including subtypes, you use

HippoSolrClient solrClient =
      HstServices.getComponentManager().getComponent(
                    HippoSolrClient.class.getName(), "org.hippoecm.hst.solr");
HippoQuery hippoQuery = solrClient.createQuery(query);
// set subtypes to TRUE
hippoQuery.setIncludedClasses(true, BaseDocument.class);
// exclude
hippoQuery.setExcludedClasses(true, NewsDocument.class, AgendaDocument.class);

If you want to search for all documents that implement the interface NodeAware, you use

HippoSolrClient solrClient =
      HstServices.getComponentManager().getComponent(
                    HippoSolrClient.class.getName(), "org.hippoecm.hst.solr");
HippoQuery hippoQuery = solrClient.createQuery(query);
// set subtypes to TRUE
hippoQuery.setIncludedClasses(true, NodeAware.class);
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?