Class SolrTemplate

java.lang.Object
org.springframework.data.solr.core.SolrTemplate
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, SolrOperations

public class SolrTemplate extends Object implements SolrOperations, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware
Implementation of SolrOperations
  • Constructor Details

    • SolrTemplate

      public SolrTemplate(org.apache.solr.client.solrj.SolrClient solrClient)
    • SolrTemplate

      public SolrTemplate(org.apache.solr.client.solrj.SolrClient solrClient, RequestMethod requestMethod)
    • SolrTemplate

      public SolrTemplate(SolrClientFactory solrClientFactory)
    • SolrTemplate

      public SolrTemplate(SolrClientFactory solrClientFactory, RequestMethod requestMethod)
    • SolrTemplate

      public SolrTemplate(SolrClientFactory solrClientFactory, @Nullable SolrConverter solrConverter)
    • SolrTemplate

      public SolrTemplate(SolrClientFactory solrClientFactory, @Nullable SolrConverter solrConverter, @Nullable RequestMethod defaultRequestMethod)
      Parameters:
      solrClientFactory - must not be null.
      solrConverter - must not be null.
      defaultRequestMethod - can be null. Will be defaulted to RequestMethod.GET
      Since:
      2.0
  • Method Details

    • execute

      public <T> T execute(SolrCallback<T> action)
      Description copied from interface: SolrOperations
      Execute action within callback
      Specified by:
      execute in interface SolrOperations
      Returns:
    • ping

      public org.apache.solr.client.solrj.response.SolrPingResponse ping()
      Description copied from interface: SolrOperations
      Execute ping against SolrClient and return duration in msec
      Specified by:
      ping in interface SolrOperations
      Returns:
      SolrPingResponse containing ping result.
    • ping

      public org.apache.solr.client.solrj.response.SolrPingResponse ping(String collection)
      Description copied from interface: SolrOperations
      Execute ping against SolrClient and return duration in msec
      Specified by:
      ping in interface SolrOperations
      Parameters:
      collection - must not be null.
      Returns:
      SolrPingResponse containing ping result.
    • count

      public long count(String collection, SolrDataQuery query, @Nullable Class<?> domainType)
      Description copied from interface: SolrOperations
      return number of elements found by for given query
      Specified by:
      count in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      domainType - can be null.
      Returns:
      total number of documents matching given query.
    • count

      public long count(String collection, SolrDataQuery query, @Nullable Class<?> domainType, RequestMethod method)
      Description copied from interface: SolrOperations
      return number of elements found by for given query
      Specified by:
      count in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      domainType - can be null.
      method - must not be null.
      Returns:
      total number of documents matching given query.
    • saveBean

      public org.apache.solr.client.solrj.response.UpdateResponse saveBean(String collection, Object obj, Duration commitWithin)
      Description copied from interface: SolrOperations
      Execute add operation against solr, which will do either insert or update with support for commitWithin strategy.
      Specified by:
      saveBean in interface SolrOperations
      Parameters:
      collection - must not be null.
      obj - must not be null.
      commitWithin - max time within server performs commit.
      Returns:
      UpdateResponse containing update result.
    • saveBeans

      public org.apache.solr.client.solrj.response.UpdateResponse saveBeans(String collection, Collection<?> beans, Duration commitWithin)
      Description copied from interface: SolrOperations
      Add a collection of beans to solr, which will do either insert or update with support for commitWithin strategy.
      Specified by:
      saveBeans in interface SolrOperations
      Parameters:
      collection - must not be null.
      beans - must not be null.
      commitWithin - max time within server performs commit.
      Returns:
      UpdateResponse containing update result.
    • saveDocument

      public org.apache.solr.client.solrj.response.UpdateResponse saveDocument(String collection, org.apache.solr.common.SolrInputDocument document, Duration commitWithin)
      Description copied from interface: SolrOperations
      Add a solrj input document to solr, which will do either insert or update with support for commitWithin strategy
      Specified by:
      saveDocument in interface SolrOperations
      document - must not be null.
      commitWithin - must not be null.
      Returns:
      UpdateResponse containing update result.
    • saveDocuments

      public org.apache.solr.client.solrj.response.UpdateResponse saveDocuments(String collection, Collection<org.apache.solr.common.SolrInputDocument> documents, Duration commitWithin)
      Description copied from interface: SolrOperations
      Add multiple solrj input documents to solr, which will do either insert or update with support for commitWithin strategy.
      Specified by:
      saveDocuments in interface SolrOperations
      Parameters:
      collection - must not be null.
      documents - must not be null.
      commitWithin - max time within server performs commit.
      Returns:
      UpdateResponse containing update result.
    • delete

      public org.apache.solr.client.solrj.response.UpdateResponse delete(String collection, SolrDataQuery query, @Nullable Class<?> domainType)
      Description copied from interface: SolrOperations
      Find and delete all objects matching the provided Query.
      Specified by:
      delete in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      Returns:
      UpdateResponse containing delete result.
    • deleteByIds

      public org.apache.solr.client.solrj.response.UpdateResponse deleteByIds(String collection, String id)
      Description copied from interface: SolrOperations
      Detele the one object with provided id.
      Specified by:
      deleteByIds in interface SolrOperations
      Parameters:
      collection - must not be null.
      id - must not be null.
      Returns:
      UpdateResponse containing delete result.
    • deleteByIds

      public org.apache.solr.client.solrj.response.UpdateResponse deleteByIds(String collection, Collection<String> ids)
      Description copied from interface: SolrOperations
      Delete objects with given ids
      Specified by:
      deleteByIds in interface SolrOperations
      Parameters:
      collection - must not be null.
      ids - must not be null.
      Returns:
      UpdateResponse containing delete result.
    • queryForObject

      public <T> Optional<T> queryForObject(String collection, Query query, Class<T> clazz)
      Description copied from interface: SolrOperations
      Execute the query against solr and return the first returned object
      Specified by:
      queryForObject in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      Returns:
      the first matching object
    • queryForObject

      public <T> Optional<T> queryForObject(String collection, Query query, Class<T> clazz, RequestMethod method)
      Description copied from interface: SolrOperations
      Execute the query against solr and return the first returned object
      Specified by:
      queryForObject in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      method - must not be null.
      Returns:
      the first matching object
    • queryForPage

      public <T> ScoredPage<T> queryForPage(String collection, Query query, Class<T> clazz)
      Description copied from interface: SolrOperations
      Execute the query against solr and retrun result as Page
      Specified by:
      queryForPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      Returns:
      never null.
    • query

      public <T, S extends org.springframework.data.domain.Page<T>> S query(String collection, Query query, Class<T> clazz)
      Description copied from interface: SolrOperations
      Execute the query against Solr and return result as page.
      Specified by:
      query in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      Returns:
      never null.
    • query

      public <T, S extends org.springframework.data.domain.Page<T>> S query(String collection, Query query, Class<T> clazz, RequestMethod method)
      Description copied from interface: SolrOperations
      Execute the query against Solr and return result as page.
      Specified by:
      query in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      method - must not be null.
      Returns:
      never null.
    • queryForPage

      public <T> ScoredPage<T> queryForPage(String collection, Query query, Class<T> clazz, RequestMethod method)
      Description copied from interface: SolrOperations
      Execute the query against solr and retrun result as Page
      Specified by:
      queryForPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      method - must not be null.
      Returns:
      never null.
    • queryForGroupPage

      public <T> GroupPage<T> queryForGroupPage(String collection, Query query, Class<T> clazz)
      Description copied from interface: SolrOperations
      Execute the query against solr and return result as GroupPage
      Specified by:
      queryForGroupPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      Returns:
      never null.
    • queryForGroupPage

      public <T> GroupPage<T> queryForGroupPage(String collection, Query query, Class<T> clazz, RequestMethod method)
      Description copied from interface: SolrOperations
      Execute the query against solr and return result as GroupPage
      Specified by:
      queryForGroupPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      method - must not be null.
      Returns:
      never null.
    • queryForStatsPage

      public <T> StatsPage<T> queryForStatsPage(String collection, Query query, Class<T> clazz)
      Description copied from interface: SolrOperations
      Execute the query against Solr and return result as StatsPage.
      Specified by:
      queryForStatsPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      Returns:
      never null.
    • queryForStatsPage

      public <T> StatsPage<T> queryForStatsPage(String collection, Query query, Class<T> clazz, RequestMethod method)
      Description copied from interface: SolrOperations
      Execute the query against Solr and return result as StatsPage.
      Specified by:
      queryForStatsPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      method - must not be null.
      Returns:
      never null.
    • queryForFacetPage

      public <T> FacetPage<T> queryForFacetPage(String collection, FacetQuery query, Class<T> clazz)
      Description copied from interface: SolrOperations
      Execute a facet query against solr facet result will be returned along with query result within the FacetPage
      Specified by:
      queryForFacetPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      Returns:
      never null.
    • queryForFacetPage

      public <T> FacetPage<T> queryForFacetPage(String collection, FacetQuery query, Class<T> clazz, RequestMethod method)
      Description copied from interface: SolrOperations
      Execute a facet query against solr facet result will be returned along with query result within the FacetPage
      Specified by:
      queryForFacetPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      method - must not be null.
      Returns:
      never null.
    • queryForHighlightPage

      public <T> HighlightPage<T> queryForHighlightPage(String collection, HighlightQuery query, Class<T> clazz)
      Description copied from interface: SolrOperations
      Execute a query and highlight matches in result
      Specified by:
      queryForHighlightPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      Returns:
      never null.
    • queryForHighlightPage

      public <T> HighlightPage<T> queryForHighlightPage(String collection, HighlightQuery query, Class<T> clazz, RequestMethod method)
      Description copied from interface: SolrOperations
      Execute a query and highlight matches in result
      Specified by:
      queryForHighlightPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      method - must not be null.
      Returns:
      never null.
    • queryForFacetAndHighlightPage

      public <T> FacetAndHighlightPage<T> queryForFacetAndHighlightPage(String collection, FacetAndHighlightQuery query, Class<T> clazz)
      Description copied from interface: SolrOperations
      Execute a query and highlight matches in result
      Specified by:
      queryForFacetAndHighlightPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      Returns:
      never null.
    • queryForFacetAndHighlightPage

      public <T> FacetAndHighlightPage<T> queryForFacetAndHighlightPage(String collection, FacetAndHighlightQuery query, Class<T> clazz, RequestMethod method)
      Description copied from interface: SolrOperations
      Execute a query and highlight matches in result
      Specified by:
      queryForFacetAndHighlightPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      method - must not be null.
      Returns:
      never null.
    • queryForTermsPage

      public TermsPage queryForTermsPage(String collection, TermsQuery query)
      Description copied from interface: SolrOperations
      Execute query using terms handler
      Specified by:
      queryForTermsPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      Returns:
      never null.
    • queryForTermsPage

      public TermsPage queryForTermsPage(String collection, TermsQuery query, RequestMethod method)
      Description copied from interface: SolrOperations
      Execute query using terms handler
      Specified by:
      queryForTermsPage in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      method - must not be null.
      Returns:
      never null.
    • constructQuery

      protected org.apache.solr.client.solrj.SolrQuery constructQuery(SolrDataQuery query, @Nullable Class<?> domainType)
      Create the native SolrQuery from a given SolrDataQuery.
      Parameters:
      query - never null.
      Returns:
      never null.
      Since:
      2.1.11
    • commit

      public void commit(String collection)
      Description copied from interface: SolrOperations
      Send commit command SolrClient.commit()
      Specified by:
      commit in interface SolrOperations
    • softCommit

      public void softCommit(String collection)
      Description copied from interface: SolrOperations
      Send soft commmit command SolrClient.commit(boolean, boolean, boolean)
      Specified by:
      softCommit in interface SolrOperations
    • rollback

      public void rollback(String collection)
      Description copied from interface: SolrOperations
      send rollback command SolrClient.rollback()
      Specified by:
      rollback in interface SolrOperations
    • convertBeanToSolrInputDocument

      public org.apache.solr.common.SolrInputDocument convertBeanToSolrInputDocument(Object bean)
      Description copied from interface: SolrOperations
      Convert given bean into a solrj InputDocument
      Specified by:
      convertBeanToSolrInputDocument in interface SolrOperations
      Returns:
    • getSchemaName

      public String getSchemaName(String collectionName)
      Parameters:
      collectionName -
      Returns:
      Since:
      1.3
    • queryForCursor

      public <T> Cursor<T> queryForCursor(String collection, Query query, Class<T> clazz)
      Description copied from interface: SolrOperations
      Executes the given Query and returns an open Cursor allowing to iterate of results, dynamically fetching additional ones if required.
      Specified by:
      queryForCursor in interface SolrOperations
      Parameters:
      collection - must not be null.
      query - must not be null.
      clazz - must not be null.
      Returns:
      never null.
    • getByIds

      public <T> Collection<T> getByIds(String collection, Collection<?> ids, Class<T> clazz)
      Description copied from interface: SolrOperations
      Executes a realtime get using given ids.
      Specified by:
      getByIds in interface SolrOperations
      Parameters:
      collection - must not be null.
      ids - must not be null.
      clazz - must not be null.
      Returns:
    • getById

      public <T> Optional<T> getById(String collection, Object id, Class<T> clazz)
      Description copied from interface: SolrOperations
      Executes a realtime get using given id.
      Specified by:
      getById in interface SolrOperations
      Parameters:
      collection - must not be null.
      id - must not be null.
      clazz - must not be null.
      Returns:
    • getSchemaOperations

      public SchemaOperations getSchemaOperations(String collection)
      Description copied from interface: SolrOperations
      Get the SchemaOperations executable.
      Specified by:
      getSchemaOperations in interface SolrOperations
      Returns:
      never null.
    • convertQueryResponseToBeans

      public <T> List<T> convertQueryResponseToBeans(org.apache.solr.client.solrj.response.QueryResponse response, Class<T> targetClass)
    • convertSolrDocumentListToBeans

      public <T> List<T> convertSolrDocumentListToBeans(org.apache.solr.common.SolrDocumentList documents, Class<T> targetClass)
    • convertSolrDocumentToBean

      public <T> T convertSolrDocumentToBean(org.apache.solr.common.SolrDocument document, Class<T> targetClass)
    • assertNoCollection

      protected void assertNoCollection(Object o)
    • getSolrClient

      public final org.apache.solr.client.solrj.SolrClient getSolrClient()
      Description copied from interface: SolrOperations
      Get the underlying SolrClient instance
      Specified by:
      getSolrClient in interface SolrOperations
      Returns:
      the SolrClient in use. Never null.
    • getConverter

      public SolrConverter getConverter()
      Specified by:
      getConverter in interface SolrOperations
      Returns:
      Converter in use
    • getExceptionTranslator

      public static org.springframework.dao.support.PersistenceExceptionTranslator getExceptionTranslator()
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
    • registerQueryParser

      public void registerQueryParser(Class<? extends SolrDataQuery> clazz, QueryParser queryParser)
    • setSolrConverter

      public void setSolrConverter(SolrConverter solrConverter)
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • setMappingContext

      public void setMappingContext(org.springframework.data.mapping.context.MappingContext<? extends SolrPersistentEntity<?>,SolrPersistentProperty> mappingContext)
      Parameters:
      mappingContext -
      Since:
      1.3
    • setSchemaCreationFeatures

      public void setSchemaCreationFeatures(Collection<SolrPersistentEntitySchemaCreator.Feature> schemaCreationFeatures)
      Parameters:
      schemaCreationFeatures -
      Since:
      1.3
    • getSchemaCreationFeatures

      public Set<SolrPersistentEntitySchemaCreator.Feature> getSchemaCreationFeatures()
      Returns:
      Since:
      1.3
    • getDefaultRequestMethod

      public RequestMethod getDefaultRequestMethod()
      Returns:
      never null.