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?

    We rely on cookies

    to optimize our communication and to enhance your customer experience. By clicking on the Accept and Close button, you agree to the collection of cookies. You can also adjust your preferences by clicking on Manage Preferences. For more information please see our Privacy policy.

    Manage cookies
    Accept & close

    Cookies preferences

    Accept & close
    Back