public class

SolrConnector

extends Object
java.lang.Object
   ↳ org.mule.modules.SolrConnector
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Module for Apache Solr Integration, it is based on the SolrJ Java Client API and allows interaction with Apache Solr standalone servers.

Summary

Fields
private static final String[] EMPTY_STRING_ARRAY
private static final Logger logger
private String password The password for Solr's http basic authentication.
private SolrServer server
private String serverUrl The URL of the Solr server to connect to.
private String username The username for Solr's http basic authentication.
Public Constructors
SolrConnector()
Public Methods
synchronized void connect()
Connect to the Solr Server using commons http client gateway.
String connectionIdentifier()
Identify the connection.
UpdateResponse deleteById(String id)
Delete a specific element on the index by ID.
UpdateResponse deleteByQuery(String q)
Delete elements by specifying a query, if you wish to delete everything use *:* as the query parameter.
synchronized void disconnect()
Disconnect from the server, nothing special needed at this time.
String getPassword()
String getServerUrl()
String getUsername()
UpdateResponse index(Object payload)
Index a simple document or a collection of documents and then, if everything goes well, commit the results to solr.
UpdateResponse indexPojo(Object payload)
Index a simple pojo or a collection of pojo's and then, if everything goes well, commit the results to solr.
boolean isConnected()
Validate the connection by sending a ping request.
static SolrInputDocument messageToInputDocumentTransformer(Map<StringObject> fields)
Convert the information of a message to an indexable SolrInputDocument.
QueryResponse query(String q, String handler, String highlightField, int highlightSnippets, List<String> facetFields, int facetLimit, int facetMinCount, Map<StringString> parameters, List<String> filterQueries, Map<String, SolrQuery.ORDER> sortFields)
Submit a query to the server and get the results.
void setPassword(String password)
void setServerUrl(String serverUrl)
void setUsername(String username)
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private static final String[] EMPTY_STRING_ARRAY

private static final Logger logger

private String password

The password for Solr's http basic authentication. This connector does not allow empty passwords.

private SolrServer server

private String serverUrl

The URL of the Solr server to connect to. To define the solr core to use, specify it here, otherwise the default core will be used.

private String username

The username for Solr's http basic authentication. This connector does not allow empty user names.

Public Constructors

public SolrConnector ()

Public Methods

public synchronized void connect ()

Connect to the Solr Server using commons http client gateway.

Throws
ConnectionException

public String connectionIdentifier ()

Identify the connection.

Returns
  • null, not used at this time.

public UpdateResponse deleteById (String id)

Delete a specific element on the index by ID.

Parameters
id The ID of the element to delete.
Returns
  • the server response object.
Throws
SolrModuleException This exception wraps the exceptions thrown by the client.

public UpdateResponse deleteByQuery (String q)

Delete elements by specifying a query, if you wish to delete everything use *:* as the query parameter.

Parameters
q The query of which results will be deleted.
Returns
  • the server response object.
Throws
SolrModuleException This exception wraps the exceptions thrown by the client.

public synchronized void disconnect ()

Disconnect from the server, nothing special needed at this time.

public String getPassword ()

public String getServerUrl ()

public String getUsername ()

public UpdateResponse index (Object payload)

Index a simple document or a collection of documents and then, if everything goes well, commit the results to solr.

Parameters
payload The document or collection of documents to send to the solr server.
Returns
  • the API response when committing the update.
Throws
SolrModuleException This exception wraps exceptions thrown by the client.

public UpdateResponse indexPojo (Object payload)

Index a simple pojo or a collection of pojo's and then, if everything goes well, commit the results to solr.

Parameters
payload The pojo or collection of pojos to send to the solr server.
Returns
  • the API response when committing the update.
Throws
SolrModuleException This exception wraps exceptions thrown by the client.

public boolean isConnected ()

Validate the connection by sending a ping request.

Returns
  • true if the ping call succeeds, false otherwise.

public static SolrInputDocument messageToInputDocumentTransformer (Map<StringObject> fields)

Convert the information of a message to an indexable SolrInputDocument.

Parameters
fields A map which keys are field names and which values are the actual values for these fields.
Returns
  • a SolrInputDocument when the fields parameter is not null or empty, it will return null otherwise.

public QueryResponse query (String q, String handler, String highlightField, int highlightSnippets, List<String> facetFields, int facetLimit, int facetMinCount, Map<StringString> parameters, List<String> filterQueries, Map<String, SolrQuery.ORDER> sortFields)

Submit a query to the server and get the results.

Parameters
q This is the query string called 'q' using solr's nomenclature, normally this has the form of field:value or just value for querying the default field. Please take a look at solr's documentation for info on how to write queries.
handler Which handler to use when querying.
highlightField The field on which to highlight search results.
highlightSnippets The number of highlight snippets per result.
facetFields A list of fields for a faceted query. If not null, will enable faceted search.
facetLimit The facet limit of the query.
facetMinCount The facet minimum count of the query.
parameters These parameters will be added to the query.
filterQueries A list of queries to filter the results.
sortFields A list of fields (with sorting criteria) in which the results will be sorted. Sorting criteria values could be only either asc or desc.
Returns
  • a QueryResponse QueryResponse object with the search results.
Throws
SolrModuleException This exception wraps exceptions thrown when querying the server fails.

public void setPassword (String password)

Parameters
password

public void setServerUrl (String serverUrl)

Parameters
serverUrl

public void setUsername (String username)

Parameters
username