SolrQuery

Once you have bootstrapped a HippoQuery through the HippoSolrClient, you have access to the SolrQuery and its entire API, also see http://lucene.apache.org/solr/api/org/apache/solr/client/solrj/SolrQuery.html. If you are familiar with Solrj, you'll be able to use whatever you were used to. If you are not familiar with it, you should easily find your way with the solrj documentation, see http://wiki.apache.org/solr/Solrj.

Getting the SolrQuery

SolrQuery:

HippoSolrClient solrClient = HstServices.getComponentManager().getComponent(
                     HippoSolrClient.class.getName(), "org.hippoecm.hst.solr");
HippoQueryParser parser = solrClient.getQueryParser();
HippoQuery hippoQuery = solrClient.createQuery(parser.escape(query));
SolrQuery solrQuery = hippoQuery.getSolrQuery();

A simple example: Add sorting on date

SolrQuery solrQuery = hippoQuery.getSolrQuery();
solrQuery.addSortField("date", SolrQuery.ORDER.desc);

A simple example: Add highlighting for title and summary in the search results

SolrQuery solrQuery = hippoQuery.getSolrQuery();
solrQuery.setHighlight(true);
solrQuery.setHighlightFragsize(150);
solrQuery.setHighlightSimplePre("<b style=\"color:blue\">");
solrQuery.setHighlightSimplePost("</b>");
solrQuery.addHighlightField("title");
solrQuery.addHighlightField("summary");

A simple example: Add highlighting in all fields

solrQuery.addHighlightField("*");

A simple example: Add spellcheck / did you mean

SolrQuery solrQuery = hippoQuery.getSolrQuery();
solrQuery.add("spellcheck", "true");
solrQuery.add("spellcheck.q", query);
solrQuery.add("spellcheck.extendedResults", "true");
solrQuery.add("spellcheck.collateExtendedResults", "true");
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?