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 Summary
ConstructorsConstructorDescriptionSolrTemplate(org.apache.solr.client.solrj.SolrClient solrClient) SolrTemplate(org.apache.solr.client.solrj.SolrClient solrClient, RequestMethod requestMethod) SolrTemplate(SolrClientFactory solrClientFactory) SolrTemplate(SolrClientFactory solrClientFactory, SolrConverter solrConverter) SolrTemplate(SolrClientFactory solrClientFactory, SolrConverter solrConverter, RequestMethod defaultRequestMethod) SolrTemplate(SolrClientFactory solrClientFactory, RequestMethod requestMethod) -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidvoidSend commit commandSolrClient.commit()protected org.apache.solr.client.solrj.SolrQueryconstructQuery(SolrDataQuery query, Class<?> domainType) Create the nativeSolrQueryfrom a givenSolrDataQuery.org.apache.solr.common.SolrInputDocumentConvert given bean into a solrj InputDocument<T> List<T>convertQueryResponseToBeans(org.apache.solr.client.solrj.response.QueryResponse response, Class<T> targetClass) <T> List<T>convertSolrDocumentListToBeans(org.apache.solr.common.SolrDocumentList documents, Class<T> targetClass) <T> TconvertSolrDocumentToBean(org.apache.solr.common.SolrDocument document, Class<T> targetClass) longcount(String collection, SolrDataQuery query, Class<?> domainType) return number of elements found by for given querylongcount(String collection, SolrDataQuery query, Class<?> domainType, RequestMethod method) return number of elements found by for given queryorg.apache.solr.client.solrj.response.UpdateResponsedelete(String collection, SolrDataQuery query, Class<?> domainType) Find and delete all objects matching the provided Query.org.apache.solr.client.solrj.response.UpdateResponsedeleteByIds(String collection, String id) Detele the one object with provided id.org.apache.solr.client.solrj.response.UpdateResponsedeleteByIds(String collection, Collection<String> ids) Delete objects with given ids<T> Texecute(SolrCallback<T> action) Execute action within callback<T> Optional<T>Executes a realtime get using given id.<T> Collection<T>getByIds(String collection, Collection<?> ids, Class<T> clazz) Executes a realtime get using given ids.static org.springframework.dao.support.PersistenceExceptionTranslatorgetSchemaName(String collectionName) getSchemaOperations(String collection) Get theSchemaOperationsexecutable.final org.apache.solr.client.solrj.SolrClientGet the underlying SolrClient instanceorg.apache.solr.client.solrj.response.SolrPingResponseping()Execute ping against SolrClient and return duration in msecorg.apache.solr.client.solrj.response.SolrPingResponseExecute ping against SolrClient and return duration in msec<T,S extends org.springframework.data.domain.Page<T>>
SExecute the query against Solr and return result as page.<T,S extends org.springframework.data.domain.Page<T>>
Squery(String collection, Query query, Class<T> clazz, RequestMethod method) Execute the query against Solr and return result as page.<T> Cursor<T>queryForCursor(String collection, Query query, Class<T> clazz) <T> FacetAndHighlightPage<T>queryForFacetAndHighlightPage(String collection, FacetAndHighlightQuery query, Class<T> clazz) Execute a query and highlight matches in result<T> FacetAndHighlightPage<T>queryForFacetAndHighlightPage(String collection, FacetAndHighlightQuery query, Class<T> clazz, RequestMethod method) Execute a query and highlight matches in result<T> FacetPage<T>queryForFacetPage(String collection, FacetQuery query, Class<T> clazz) Execute a facet query against solr facet result will be returned along with query result within the FacetPage<T> FacetPage<T>queryForFacetPage(String collection, FacetQuery query, Class<T> clazz, RequestMethod method) Execute a facet query against solr facet result will be returned along with query result within the FacetPage<T> GroupPage<T>queryForGroupPage(String collection, Query query, Class<T> clazz) Execute the query against solr and return result asGroupPage<T> GroupPage<T>queryForGroupPage(String collection, Query query, Class<T> clazz, RequestMethod method) Execute the query against solr and return result asGroupPage<T> HighlightPage<T>queryForHighlightPage(String collection, HighlightQuery query, Class<T> clazz) Execute a query and highlight matches in result<T> HighlightPage<T>queryForHighlightPage(String collection, HighlightQuery query, Class<T> clazz, RequestMethod method) Execute a query and highlight matches in result<T> Optional<T>queryForObject(String collection, Query query, Class<T> clazz) Execute the query against solr and return the first returned object<T> Optional<T>queryForObject(String collection, Query query, Class<T> clazz, RequestMethod method) Execute the query against solr and return the first returned object<T> ScoredPage<T>queryForPage(String collection, Query query, Class<T> clazz) Execute the query against solr and retrun result asPage<T> ScoredPage<T>queryForPage(String collection, Query query, Class<T> clazz, RequestMethod method) Execute the query against solr and retrun result asPage<T> StatsPage<T>queryForStatsPage(String collection, Query query, Class<T> clazz) Execute the query against Solr and return result asStatsPage.<T> StatsPage<T>queryForStatsPage(String collection, Query query, Class<T> clazz, RequestMethod method) Execute the query against Solr and return result asStatsPage.queryForTermsPage(String collection, TermsQuery query) Execute query using terms handlerqueryForTermsPage(String collection, TermsQuery query, RequestMethod method) Execute query using terms handlervoidregisterQueryParser(Class<? extends SolrDataQuery> clazz, QueryParser queryParser) voidsend rollback commandSolrClient.rollback()org.apache.solr.client.solrj.response.UpdateResponseExecute add operation against solr, which will do either insert or update with support for commitWithin strategy.org.apache.solr.client.solrj.response.UpdateResponsesaveBeans(String collection, Collection<?> beans, Duration commitWithin) Add a collection of beans to solr, which will do either insert or update with support for commitWithin strategy.org.apache.solr.client.solrj.response.UpdateResponsesaveDocument(String collection, org.apache.solr.common.SolrInputDocument document, Duration commitWithin) Add a solrj input document to solr, which will do either insert or update with support for commitWithin strategyorg.apache.solr.client.solrj.response.UpdateResponsesaveDocuments(String collection, Collection<org.apache.solr.common.SolrInputDocument> documents, Duration commitWithin) Add multiple solrj input documents to solr, which will do either insert or update with support for commitWithin strategy.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetMappingContext(org.springframework.data.mapping.context.MappingContext<? extends SolrPersistentEntity<?>, SolrPersistentProperty> mappingContext) voidsetSchemaCreationFeatures(Collection<SolrPersistentEntitySchemaCreator.Feature> schemaCreationFeatures) voidsetSolrConverter(SolrConverter solrConverter) voidsoftCommit(String collection) Send soft commmit commandSolrClient.commit(boolean, boolean, boolean)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.solr.core.SolrOperations
count, count, delete, saveBean, saveBeans, saveDocument, saveDocuments
-
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
-
SolrTemplate
-
SolrTemplate
-
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 toRequestMethod.GET- Since:
- 2.0
-
-
Method Details
-
execute
Description copied from interface:SolrOperationsExecute action within callback- Specified by:
executein interfaceSolrOperations- Returns:
-
ping
public org.apache.solr.client.solrj.response.SolrPingResponse ping()Description copied from interface:SolrOperationsExecute ping against SolrClient and return duration in msec- Specified by:
pingin interfaceSolrOperations- Returns:
SolrPingResponsecontaining ping result.
-
ping
Description copied from interface:SolrOperationsExecute ping against SolrClient and return duration in msec- Specified by:
pingin interfaceSolrOperations- Parameters:
collection- must not be null.- Returns:
SolrPingResponsecontaining ping result.
-
count
Description copied from interface:SolrOperationsreturn number of elements found by for given query- Specified by:
countin interfaceSolrOperations- 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:SolrOperationsreturn number of elements found by for given query- Specified by:
countin interfaceSolrOperations- 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:SolrOperationsExecute add operation against solr, which will do either insert or update with support for commitWithin strategy.- Specified by:
saveBeanin interfaceSolrOperations- Parameters:
collection- must not be null.obj- must not be null.commitWithin- max time within server performs commit.- Returns:
UpdateResponsecontaining update result.
-
saveBeans
public org.apache.solr.client.solrj.response.UpdateResponse saveBeans(String collection, Collection<?> beans, Duration commitWithin) Description copied from interface:SolrOperationsAdd a collection of beans to solr, which will do either insert or update with support for commitWithin strategy.- Specified by:
saveBeansin interfaceSolrOperations- Parameters:
collection- must not be null.beans- must not be null.commitWithin- max time within server performs commit.- Returns:
UpdateResponsecontaining 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:SolrOperationsAdd a solrj input document to solr, which will do either insert or update with support for commitWithin strategy- Specified by:
saveDocumentin interfaceSolrOperationsdocument- must not be null.commitWithin- must not be null.- Returns:
UpdateResponsecontaining 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:SolrOperationsAdd multiple solrj input documents to solr, which will do either insert or update with support for commitWithin strategy.- Specified by:
saveDocumentsin interfaceSolrOperations- Parameters:
collection- must not be null.documents- must not be null.commitWithin- max time within server performs commit.- Returns:
UpdateResponsecontaining update result.
-
delete
public org.apache.solr.client.solrj.response.UpdateResponse delete(String collection, SolrDataQuery query, @Nullable Class<?> domainType) Description copied from interface:SolrOperationsFind and delete all objects matching the provided Query.- Specified by:
deletein interfaceSolrOperations- Parameters:
collection- must not be null.query- must not be null.- Returns:
UpdateResponsecontaining delete result.
-
deleteByIds
public org.apache.solr.client.solrj.response.UpdateResponse deleteByIds(String collection, String id) Description copied from interface:SolrOperationsDetele the one object with provided id.- Specified by:
deleteByIdsin interfaceSolrOperations- Parameters:
collection- must not be null.id- must not be null.- Returns:
UpdateResponsecontaining delete result.
-
deleteByIds
public org.apache.solr.client.solrj.response.UpdateResponse deleteByIds(String collection, Collection<String> ids) Description copied from interface:SolrOperationsDelete objects with given ids- Specified by:
deleteByIdsin interfaceSolrOperations- Parameters:
collection- must not be null.ids- must not be null.- Returns:
UpdateResponsecontaining delete result.
-
queryForObject
Description copied from interface:SolrOperationsExecute the query against solr and return the first returned object- Specified by:
queryForObjectin interfaceSolrOperations- 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:SolrOperationsExecute the query against solr and return the first returned object- Specified by:
queryForObjectin interfaceSolrOperations- 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
Description copied from interface:SolrOperationsExecute the query against solr and retrun result asPage- Specified by:
queryForPagein interfaceSolrOperations- 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:SolrOperationsExecute the query against Solr and return result as page.- Specified by:
queryin interfaceSolrOperations- 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:SolrOperationsExecute the query against Solr and return result as page.- Specified by:
queryin interfaceSolrOperations- 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:SolrOperationsExecute the query against solr and retrun result asPage- Specified by:
queryForPagein interfaceSolrOperations- 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
Description copied from interface:SolrOperationsExecute the query against solr and return result asGroupPage- Specified by:
queryForGroupPagein interfaceSolrOperations- 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:SolrOperationsExecute the query against solr and return result asGroupPage- Specified by:
queryForGroupPagein interfaceSolrOperations- 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
Description copied from interface:SolrOperationsExecute the query against Solr and return result asStatsPage.- Specified by:
queryForStatsPagein interfaceSolrOperations- 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:SolrOperationsExecute the query against Solr and return result asStatsPage.- Specified by:
queryForStatsPagein interfaceSolrOperations- 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
Description copied from interface:SolrOperationsExecute a facet query against solr facet result will be returned along with query result within the FacetPage- Specified by:
queryForFacetPagein interfaceSolrOperations- 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:SolrOperationsExecute a facet query against solr facet result will be returned along with query result within the FacetPage- Specified by:
queryForFacetPagein interfaceSolrOperations- 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:SolrOperationsExecute a query and highlight matches in result- Specified by:
queryForHighlightPagein interfaceSolrOperations- 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:SolrOperationsExecute a query and highlight matches in result- Specified by:
queryForHighlightPagein interfaceSolrOperations- 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:SolrOperationsExecute a query and highlight matches in result- Specified by:
queryForFacetAndHighlightPagein interfaceSolrOperations- 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:SolrOperationsExecute a query and highlight matches in result- Specified by:
queryForFacetAndHighlightPagein interfaceSolrOperations- 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
Description copied from interface:SolrOperationsExecute query using terms handler- Specified by:
queryForTermsPagein interfaceSolrOperations- Parameters:
collection- must not be null.query- must not be null.- Returns:
- never null.
-
queryForTermsPage
Description copied from interface:SolrOperationsExecute query using terms handler- Specified by:
queryForTermsPagein interfaceSolrOperations- 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 nativeSolrQueryfrom a givenSolrDataQuery.- Parameters:
query- never null.- Returns:
- never null.
- Since:
- 2.1.11
-
commit
Description copied from interface:SolrOperationsSend commit commandSolrClient.commit()- Specified by:
commitin interfaceSolrOperations
-
softCommit
Description copied from interface:SolrOperationsSend soft commmit commandSolrClient.commit(boolean, boolean, boolean)- Specified by:
softCommitin interfaceSolrOperations
-
rollback
Description copied from interface:SolrOperationssend rollback commandSolrClient.rollback()- Specified by:
rollbackin interfaceSolrOperations
-
convertBeanToSolrInputDocument
Description copied from interface:SolrOperationsConvert given bean into a solrj InputDocument- Specified by:
convertBeanToSolrInputDocumentin interfaceSolrOperations- Returns:
-
getSchemaName
- Parameters:
collectionName-- Returns:
- Since:
- 1.3
-
queryForCursor
Description copied from interface:SolrOperationsExecutes the givenQueryand returns an openCursorallowing to iterate of results, dynamically fetching additional ones if required.- Specified by:
queryForCursorin interfaceSolrOperations- Parameters:
collection- must not be null.query- must not be null.clazz- must not be null.- Returns:
- never null.
-
getByIds
Description copied from interface:SolrOperationsExecutes a realtime get using given ids.- Specified by:
getByIdsin interfaceSolrOperations- Parameters:
collection- must not be null.ids- must not be null.clazz- must not be null.- Returns:
-
getById
Description copied from interface:SolrOperationsExecutes a realtime get using given id.- Specified by:
getByIdin interfaceSolrOperations- Parameters:
collection- must not be null.id- must not be null.clazz- must not be null.- Returns:
-
getSchemaOperations
Description copied from interface:SolrOperationsGet theSchemaOperationsexecutable.- Specified by:
getSchemaOperationsin interfaceSolrOperations- Returns:
- never null.
-
convertQueryResponseToBeans
-
convertSolrDocumentListToBeans
-
convertSolrDocumentToBean
public <T> T convertSolrDocumentToBean(org.apache.solr.common.SolrDocument document, Class<T> targetClass) -
assertNoCollection
-
getSolrClient
public final org.apache.solr.client.solrj.SolrClient getSolrClient()Description copied from interface:SolrOperationsGet the underlying SolrClient instance- Specified by:
getSolrClientin interfaceSolrOperations- Returns:
- the
SolrClientin use. Never null.
-
getConverter
- Specified by:
getConverterin interfaceSolrOperations- Returns:
- Converter in use
-
getExceptionTranslator
public static org.springframework.dao.support.PersistenceExceptionTranslator getExceptionTranslator() -
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware
-
registerQueryParser
-
setSolrConverter
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.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
- Returns:
- Since:
- 1.3
-
getDefaultRequestMethod
- Returns:
- never null.
-