Package org.dspace.discovery
Class SolrServiceImpl
java.lang.Object
org.dspace.discovery.SolrServiceImpl
- All Implemented Interfaces:
IndexingService,SearchService
SolrIndexer contains the methods that index Items and their metadata,
collections, communities, etc. It is meant to either be invoked from the
command line (see dspace/bin/index-all) or via the indexContent() methods
within DSpace.
The Administrator can choose to run SolrIndexer in a cron that repeats regularly, a failed attempt to index from the UI will be "caught" up on in that cron. The SolrServiceImpl is registered as a Service in the ServiceManager via a Spring configuration file located under classpath://spring/spring-dspace-applicationContext.xml Its configuration is Autowired by the ApplicationContext
- Author:
- Kevin Van de Velde (kevin at atmire dot com), Mark Diggory (markd at atmire dot com), Ben Bosman (ben at atmire dot com)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConfigurationServiceprotected ContentServiceFactoryprotected GroupServiceprotected IndexObjectFactoryFactorystatic final Stringprotected SolrSearchCore -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAtomically update the index of a single field for an objectvoidcalculateExtremeValue(Context context, String valueField, String sortField, DiscoverQuery.SORT_ORDER sortOrder) This method returns us either the highest or lowest value for the field that we give to it depending on what sortOrder we give this method.voidIterates over all documents in the Lucene index and verifies they are in database, if not, they are removed.voidcommit()voidcreate full index - wiping old indexMethod to create a Query that includes all communities and collections a user may administrate.voidRemoves all documents from the Lucene indexprotected voidemailException(Exception exception) escapeQueryChars(String query) Utility method to escape any special characters in a user's queryprotected IndexableObjectfindIndexableObject(Context context, org.apache.solr.common.SolrDocument doc) Find the indexable object by type and UUIDgetFacetYearRange(Context context, IndexableObject scope, DiscoverySearchFilterFacet facet, List<String> filterQueries, DiscoverQuery parentQuery) getRelatedItems(Context context, Item item, DiscoveryMoreLikeThisConfiguration mltConfig) voidindexContent(Context context, IndexableObject dso) If the handle for the "dso" already exists in the index, and the "dso" has a lastModified timestamp that is newer than the document in the index then it is updated, otherwise a new document is added.voidindexContent(Context context, IndexableObject indexableObject, boolean force) If the handle for the "dso" already exists in the index, and the "dso" has a lastModified timestamp that is newer than the document in the index then it is updated, otherwise a new document is added.voidindexContent(Context context, IndexableObject dso, boolean force, boolean commit) voidindexContent(Context context, IndexableObject indexableObject, boolean force, boolean commit, boolean preDb) Index a given DSOiteratorSearch(Context context, IndexableObject dso, DiscoverQuery query) Convenience method to call @see #search(Context, DSpaceObject, DiscoverQuery) and getting an iterator for the resultslocationToName(Context context, String field, String value) voidoptimize()Maintenance to keep a SOLR index efficient.voidreIndexContent(Context context, IndexableObject dso) reIndexContent removes something from the index, then re-indexes itprotected booleanrequiresIndexing(String uniqueId, Instant lastModified) Is stale checks the lastModified time stamp in the database and the index to determine if the index is stale.protected org.apache.solr.client.solrj.SolrQueryresolveToSolrQuery(Context context, DiscoverQuery discoveryQuery) protected DiscoverResultretrieveResult(Context context, DiscoverQuery query) search(Context context, String query, String orderfield, boolean ascending, int offset, int max, String... filterquery) search(Context context, DiscoverQuery discoveryQuery) Convenient method to callSearchService.search(Context, DSpaceObject, DiscoverQuery)with a null DSpace Object as scope (i.e. all the repository)search(Context context, IndexableObject dso, DiscoverQuery discoveryQuery) Convenient method to call @see #search(Context, DSpaceObject, DiscoverQuery, boolean) with includeWithdrawn=falsetoFilterQuery(Context context, String field, String operator, String value, DiscoveryConfiguration config) Transforms the given string field and value into a filter querytoSortFieldIndex(String metadataField, String type) Transforms the metadata field of the given sort configuration into the indexed field which we can then use in our Solr queries.protected StringtransformAuthorityValue(Context context, String field, String value) protected StringtransformDisplayedValue(Context context, String field, String value) protected StringtransformFacetField(DiscoverFacetField facetFieldConfig, String field, boolean removePostfix) protected StringtransformPrefixFacetField(DiscoverFacetField facetFieldConfig, String field, boolean removePostfix) Gets the solr field that contains the facet value split on each word break to the end, so can be searched on each word in the value, see#saveFacetPrefixParts(SolrInputDocument, DiscoverySearchFilter, String, String)Only applicable to facets of typeDiscoveryConfigurationParameters.TYPE_TEXT, otherwise uses the regular facet filter fieldprotected StringtransformSortValue(Context context, String field, String value) voidunIndexContent(Context context, String searchUniqueID) Unindex a Document in the Lucene index.voidunIndexContent(Context context, String searchUniqueID, boolean commit) Unindex a Document in the Lucene Index.voidunIndexContent(Context context, IndexableObject dso) unIndex removes an Item, Collection, or CommunityvoidunIndexContent(Context context, IndexableObject indexableObject, boolean commit) unIndex removes an Item, Collection, or Communityprotected voidupdate(Context context, IndexFactory indexableObjectService, IndexableObject indexableObject) protected voidupdate(Context context, IndexFactory indexableObjectService, IndexableObject indexableObject, boolean preDB) Update the given indexable object using a given servicevoidupdateIndex(Context context) Iterates over all Items, Collections and Communities.voidupdateIndex(Context context, boolean force) Iterates over all Items, Collections and Communities.voidupdateIndex(Context context, boolean force, String type)
-
Field Details
-
SOLR_FIELD_SUFFIX_FACET_PREFIXES
- See Also:
-
contentServiceFactory
-
groupService
-
indexObjectServiceFactory
-
solrSearchCore
-
configurationService
-
-
Constructor Details
-
SolrServiceImpl
protected SolrServiceImpl()
-
-
Method Details
-
indexContent
If the handle for the "dso" already exists in the index, and the "dso" has a lastModified timestamp that is newer than the document in the index then it is updated, otherwise a new document is added.- Specified by:
indexContentin interfaceIndexingService- Parameters:
context- Users Contextdso- DSpace Object (Item, Collection or Community- Throws:
SQLException- if error
-
indexContent
If the handle for the "dso" already exists in the index, and the "dso" has a lastModified timestamp that is newer than the document in the index then it is updated, otherwise a new document is added.- Specified by:
indexContentin interfaceIndexingService- Parameters:
context- Users ContextindexableObject- The object we want to indexforce- Force update even if not stale.
-
update
protected void update(Context context, IndexFactory indexableObjectService, IndexableObject indexableObject) throws IOException, SQLException, org.apache.solr.client.solrj.SolrServerException - Throws:
IOExceptionSQLExceptionorg.apache.solr.client.solrj.SolrServerException
-
update
protected void update(Context context, IndexFactory indexableObjectService, IndexableObject indexableObject, boolean preDB) throws IOException, SQLException, org.apache.solr.client.solrj.SolrServerException Update the given indexable object using a given service- Parameters:
context- The DSpace ContextindexableObjectService- The service to index the object withindexableObject- The object to indexpreDB- Add a "preDB" status to the document- Throws:
IOExceptionSQLExceptionorg.apache.solr.client.solrj.SolrServerException
-
unIndexContent
unIndex removes an Item, Collection, or Community- Specified by:
unIndexContentin interfaceIndexingService- Parameters:
context- The relevant DSpace Context.dso- DSpace Object, can be Community, Item, or Collection- Throws:
SQLException- if database errorIOException- if IO error
-
unIndexContent
public void unIndexContent(Context context, IndexableObject indexableObject, boolean commit) throws SQLException, IOException unIndex removes an Item, Collection, or Community- Specified by:
unIndexContentin interfaceIndexingService- Parameters:
context- The relevant DSpace Context.indexableObject- The object to be indexedcommit- iftrueforce an immediate commit on SOLR- Throws:
SQLException- if database errorIOException- if IO error
-
unIndexContent
Unindex a Document in the Lucene index.- Specified by:
unIndexContentin interfaceIndexingService- Parameters:
context- the dspace contextsearchUniqueID- the search uniqueID of the document to be deleted- Throws:
IOException- if IO error
-
unIndexContent
public void unIndexContent(Context context, String searchUniqueID, boolean commit) throws IOException Unindex a Document in the Lucene Index.- Specified by:
unIndexContentin interfaceIndexingService- Parameters:
context- the dspace contextsearchUniqueID- the search uniqueID of the document to be deletedcommit- commit the update immediately.- Throws:
IOException- if IO error
-
reIndexContent
reIndexContent removes something from the index, then re-indexes it- Specified by:
reIndexContentin interfaceIndexingService- Parameters:
context- context objectdso- object to re-index- Throws:
SQLException- passed through.IOException- passed through.
-
createIndex
create full index - wiping old index- Specified by:
createIndexin interfaceIndexingService- Parameters:
c- context to use- Throws:
SQLException- passed through.IOException- passed through.
-
updateIndex
Iterates over all Items, Collections and Communities. And updates them in the index. Uses decaching to control memory footprint. Uses indexContent and isStale to check state of item in index.- Specified by:
updateIndexin interfaceIndexingService- Parameters:
context- the dspace context
-
updateIndex
Iterates over all Items, Collections and Communities. And updates them in the index. Uses decaching to control memory footprint. Uses indexContent and isStale to check state of item in index.At first it may appear counterintuitive to have an IndexWriter/Reader opened and closed on each DSO. But this allows the UI processes to step in and attain a lock and write to the index even if other processes/jvms are running a reindex.
- Specified by:
updateIndexin interfaceIndexingService- Parameters:
context- the dspace contextforce- whether or not to force the reindexing
-
updateIndex
- Specified by:
updateIndexin interfaceIndexingService
-
deleteIndex
public void deleteIndex()Removes all documents from the Lucene index- Specified by:
deleteIndexin interfaceIndexingService
-
cleanIndex
Iterates over all documents in the Lucene index and verifies they are in database, if not, they are removed.- Specified by:
cleanIndexin interfaceIndexingService- Throws:
IOException- IO exceptionSQLException- sql exceptionSearchServiceException- occurs when something went wrong with querying the solr server
-
optimize
public void optimize()Maintenance to keep a SOLR index efficient. Note: This might take a long time.- Specified by:
optimizein interfaceIndexingService
-
buildSpellCheck
- Specified by:
buildSpellCheckin interfaceIndexingService- Throws:
SearchServiceExceptionIOException
-
atomicUpdate
public void atomicUpdate(Context context, String uniqueIndexId, String field, Map<String, Object> fieldModifier) throws org.apache.solr.client.solrj.SolrServerException, IOExceptionDescription copied from interface:IndexingServiceAtomically update the index of a single field for an object- Specified by:
atomicUpdatein interfaceIndexingService- Parameters:
context- The DSpace contextuniqueIndexId- The unique index ID of the object to update the index forfield- The field to updatefieldModifier- The modifiers for the field to update. More information on how to atomically update a solr field using a field modifier can be found here: https://yonik.com/solr/atomic-updates/- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
emailException
-
requiresIndexing
protected boolean requiresIndexing(String uniqueId, Instant lastModified) throws SQLException, IOException, SearchServiceException Is stale checks the lastModified time stamp in the database and the index to determine if the index is stale.- Parameters:
uniqueId- the unique identifier of the object that we want to indexlastModified- the last modified date of the DSpace object- Returns:
- a boolean indicating if the dso should be re indexed again
- Throws:
SQLException- sql exceptionIOException- io exceptionSearchServiceException- if something went wrong with querying the solr server
-
createLocationQueryForAdministrableItems
Description copied from interface:SearchServiceMethod to create a Query that includes all communities and collections a user may administrate. If a user has the appropriate rights to administrate communities and/or collections we want to look up all contents of those communities and/or collections, ignoring the read policies of the items (e.g. to list all private items of communities/collections the user administrates). This method returns a query to filter for items that belong to those communities/collections only.- Specified by:
createLocationQueryForAdministrableItemsin interfaceSearchService- Parameters:
context- The relevant DSpace Context.- Returns:
- query string specific to the user's rights
- Throws:
SQLException- An exception that provides information on a database access error or other errors.
-
locationToName
- Throws:
SQLException
-
search
public DiscoverResult search(Context context, IndexableObject dso, DiscoverQuery discoveryQuery) throws SearchServiceException Description copied from interface:SearchServiceConvenient method to call @see #search(Context, DSpaceObject, DiscoverQuery, boolean) with includeWithdrawn=false- Specified by:
searchin interfaceSearchService- Parameters:
context- DSpace Context objectdso- a DSpace Object to use as scope of the search (only results within this object)discoveryQuery- the discovery query object- Returns:
- discovery search result object
- Throws:
SearchServiceException- if search error
-
iteratorSearch
public Iterator<Item> iteratorSearch(Context context, IndexableObject dso, DiscoverQuery query) throws SearchServiceException Description copied from interface:SearchServiceConvenience method to call @see #search(Context, DSpaceObject, DiscoverQuery) and getting an iterator for the results- Specified by:
iteratorSearchin interfaceSearchService- Parameters:
context- DSpace context objectdso- a DSpace object to use as a scope of the searchquery- the discovery query object- Returns:
- an iterator iterating over all results from the search
- Throws:
SearchServiceException- if search error
-
search
public DiscoverResult search(Context context, DiscoverQuery discoveryQuery) throws SearchServiceException Description copied from interface:SearchServiceConvenient method to callSearchService.search(Context, DSpaceObject, DiscoverQuery)with a null DSpace Object as scope (i.e. all the repository)- Specified by:
searchin interfaceSearchService- Parameters:
context- DSpace Context object.discoveryQuery- the discovery query object.- Returns:
- discovery search result object
- Throws:
SearchServiceException- if search error
-
resolveToSolrQuery
protected org.apache.solr.client.solrj.SolrQuery resolveToSolrQuery(Context context, DiscoverQuery discoveryQuery) throws SearchServiceException - Throws:
SearchServiceException
-
retrieveResult
protected DiscoverResult retrieveResult(Context context, DiscoverQuery query) throws SQLException, org.apache.solr.client.solrj.SolrServerException, IOException, SearchServiceException - Throws:
SQLExceptionorg.apache.solr.client.solrj.SolrServerExceptionIOExceptionSearchServiceException
-
findIndexableObject
protected IndexableObject findIndexableObject(Context context, org.apache.solr.common.SolrDocument doc) throws SQLException Find the indexable object by type and UUID- Parameters:
context- The relevant DSpace Context.doc- the solr document, the following fields MUST be present RESOURCE_TYPE_FIELD, RESOURCE_ID_FIELD and HANDLE_FIELD- Returns:
- an IndexableObject
- Throws:
SQLException- An exception that provides information on a database access error or other errors.
-
search
public List<IndexableObject> search(Context context, String query, int offset, int max, String... filterquery) -
search
public List<IndexableObject> search(Context context, String query, String orderfield, boolean ascending, int offset, int max, String... filterquery) - Specified by:
searchin interfaceSearchService
-
toFilterQuery
public DiscoverFilterQuery toFilterQuery(Context context, String field, String operator, String value, DiscoveryConfiguration config) throws SQLException Description copied from interface:SearchServiceTransforms the given string field and value into a filter query- Specified by:
toFilterQueryin interfaceSearchService- Parameters:
context- The relevant DSpace Context.field- the field of the filter queryoperator- equals/notequals/notcontains/authority/notauthorityvalue- the filter query valueconfig- (nullable) the discovery configuration (if not null, field's corresponding facet.type checked to be standard so suffix is not added for equals operator)- Returns:
- a filter query
- Throws:
SQLException- if database error An exception that provides information on a database access error or other errors.
-
getRelatedItems
public List<Item> getRelatedItems(Context context, Item item, DiscoveryMoreLikeThisConfiguration mltConfig) - Specified by:
getRelatedItemsin interfaceSearchService
-
toSortFieldIndex
Description copied from interface:SearchServiceTransforms the metadata field of the given sort configuration into the indexed field which we can then use in our Solr queries.- Specified by:
toSortFieldIndexin interfaceSearchService- Parameters:
metadataField- the metadata fieldtype- seeDiscoveryConfigurationParameters- Returns:
- the indexed field
-
transformPrefixFacetField
protected String transformPrefixFacetField(DiscoverFacetField facetFieldConfig, String field, boolean removePostfix) Gets the solr field that contains the facet value split on each word break to the end, so can be searched on each word in the value, see#saveFacetPrefixParts(SolrInputDocument, DiscoverySearchFilter, String, String)Only applicable to facets of typeDiscoveryConfigurationParameters.TYPE_TEXT, otherwise uses the regular facet filter field -
transformFacetField
protected String transformFacetField(DiscoverFacetField facetFieldConfig, String field, boolean removePostfix) -
transformDisplayedValue
protected String transformDisplayedValue(Context context, String field, String value) throws SQLException - Throws:
SQLException
-
transformAuthorityValue
protected String transformAuthorityValue(Context context, String field, String value) throws SQLException - Throws:
SQLException
-
transformSortValue
protected String transformSortValue(Context context, String field, String value) throws SQLException - Throws:
SQLException
-
indexContent
public void indexContent(Context context, IndexableObject dso, boolean force, boolean commit) throws SearchServiceException, SQLException - Specified by:
indexContentin interfaceIndexingService- Throws:
SearchServiceExceptionSQLException
-
indexContent
public void indexContent(Context context, IndexableObject indexableObject, boolean force, boolean commit, boolean preDb) throws SearchServiceException, SQLException Description copied from interface:IndexingServiceIndex a given DSO- Specified by:
indexContentin interfaceIndexingService- Parameters:
context- The DSpace ContextindexableObject- The DSpace Object to indexforce- Force update even if not stalecommit- Commit the changespreDb- Add a "preDB" status to the index (only applicable to Items)- Throws:
SearchServiceExceptionSQLException
-
commit
- Specified by:
commitin interfaceIndexingService- Throws:
SearchServiceException
-
escapeQueryChars
Description copied from interface:SearchServiceUtility method to escape any special characters in a user's query- Specified by:
escapeQueryCharsin interfaceSearchService- Parameters:
query- User's query to escape.- Returns:
- query with any special characters escaped
-
getFacetYearRange
public FacetYearRange getFacetYearRange(Context context, IndexableObject scope, DiscoverySearchFilterFacet facet, List<String> filterQueries, DiscoverQuery parentQuery) throws SearchServiceException - Specified by:
getFacetYearRangein interfaceSearchService- Throws:
SearchServiceException
-
calculateExtremeValue
public String calculateExtremeValue(Context context, String valueField, String sortField, DiscoverQuery.SORT_ORDER sortOrder) throws SearchServiceException Description copied from interface:SearchServiceThis method returns us either the highest or lowest value for the field that we give to it depending on what sortOrder we give this method.- Specified by:
calculateExtremeValuein interfaceSearchService- Parameters:
context- The relevant DSpace contextvalueField- The field in solr for which we'll calculate the extreme valuesortField- The field in solr for which we'll sort the calculated extreme value on This is typically the valueField appended with "_sort"sortOrder- Entering ascending will return the minimum value Entering descending will return the maximum value- Returns:
- Returns the min or max value based on the field in the parameters.
- Throws:
SearchServiceException
-