Skip to content

Toro Cloud Dev Center

Searching documents from a custom search index

There are three ways you can search for a Solr document in Martini: using functions, using a SolrClient object, or using the Solr Search API.

Get the code!

The scripts mentioned in this guide are available in the examples package. As bonus, you can find other services in the examples package that demonstrate the use of functions from the SolrMethods class, as well as other Solr-related functionality.

Using functions

True to its purpose, using the function is the easiest way to update an existing document. Functions from SolrMethods in particular can help. For example:

SolrMethods.query(coreName, packageName, [q:"*:*"]).getResults()
SolrMethods.query(coreName, packageName, [q:"movieTitle:*${titleSubstring}*"]).getResults()
SolrMethods.query(coreName, packageName, [q:"id:${id}"]).getResults()

Using SolrClient

A call to the function method SolrMethods.solr(String) returns a SolrClient object which you can use to directly interact with the Solr core tied to it (specified by passing the name of the core as the argument). However to use SolrClient, one must be familiar with SolrJ and Groovy.

SolrClient solrClient = SolrMethods.solr(coreName)
SolrDocumentList documents = solrClient.getById(ids)

Using the Solr Search API

Alternatively, you can use the extended Solr Search API to query documents. This will involve the use of Solr's SearchHandlers via the Solr-derived endpoint. For example:

curl -X GET \
'http://<host>:<port>/esbapi/v1/solr/<package name>/<core name>/select?q=id:<id>' \
-H 'Authorization: Bearer <access token>'