Parse a query input to valid Solr syntax - 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

Parse a query input to valid Solr syntax

Through the HippoSolrClient you can access the HippoQueryParser, which is a utility to escape all chars that Solr/Lucene QueryParser expects to be escaped (for example '+', '-', ':', '~' etc)

Code snippet how to escape a user input query:

@Overridepublic void doBeforeRender(final HstRequest request,
                           final HstResponse response)
                                         throws HstComponentException {
  HippoSolrClient solrClient =
      HstServices.getComponentManager()
      .getComponent(HippoSolrClient.class.getName(), "org.hippoecm.hst.solr");
  String escapedQuery = solrManager.getQueryParser().escape(query);
  HippoQuery hippoQuery = solrClient.createQuery(escapedQuery);
  HippoQueryResult result = hippoQuery.execute();
  request.setAttribute("result", result);
}  


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?