@Service public class SolrServiceImpl extends Object implements SearchService, IndexingService
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
| Modifier | Constructor and Description |
|---|---|
protected |
SolrServiceImpl() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addContainerMetadataField(org.apache.solr.common.SolrInputDocument doc,
List<String> highlightedMetadataFields,
List<String> toIgnoreMetadataFields,
String metadataField,
String value)
Add the metadata value of the community/collection to the solr document
IF needed highlighting is added !
|
protected void |
addDiscoveryFields(org.apache.solr.common.SolrInputDocument doc,
Context context,
Item item,
List<DiscoveryConfiguration> discoveryConfigurations) |
protected void |
buildDocument(Context context,
Collection collection)
Build a solr document for a DSpace Collection.
|
protected void |
buildDocument(Context context,
Community community)
Build a solr document for a DSpace Community.
|
protected void |
buildDocument(Context context,
Item item)
Build a Lucene document for a DSpace Item and write the index
|
protected org.apache.solr.common.SolrInputDocument |
buildDocument(int type,
UUID id,
String handle,
List<String> locations)
Create Lucene document with all the shared fields initialized.
|
void |
buildSpellCheck() |
String |
calculateExtremeValue(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.
|
void |
cleanIndex(boolean force)
Iterates over all documents in the Lucene index and verifies they are in
database, if not, they are removed.
|
void |
cleanIndex(boolean force,
int type) |
void |
commit() |
void |
createIndex(Context c)
create full index - wiping old index
|
String |
createLocationQueryForAdministrableItems(Context context)
Method to create a Query that includes all
communities and collections a user may administrate.
|
protected void |
emailException(Exception exception) |
String |
escapeQueryChars(String query)
Utility method to escape any special characters in a user's query
|
protected IndexableObject |
findIndexableObject(Context context,
org.apache.solr.common.SolrDocument doc)
Find the indexable object by type and UUID
|
protected List<String> |
getCollectionLocations(Context context,
Collection target) |
protected List<String> |
getCommunityLocations(Community target) |
FacetYearRange |
getFacetYearRange(Context context,
IndexableObject scope,
DiscoverySearchFilterFacet facet,
List<String> filterQueries,
DiscoverQuery parentQuery) |
protected List<String> |
getItemLocations(Context context,
Item myitem) |
List<Item> |
getRelatedItems(Context context,
Item item,
DiscoveryMoreLikeThisConfiguration mltConfig) |
protected org.apache.solr.client.solrj.SolrClient |
getSolr() |
void |
indexContent(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.
|
void |
indexContent(Context context,
IndexableObject dso,
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.
|
void |
indexContent(Context context,
IndexableObject dso,
boolean force,
boolean commit) |
String |
locationToName(Context context,
String field,
String value) |
void |
optimize()
Maintenance to keep a SOLR index efficient.
|
void |
reIndexContent(Context context,
IndexableObject dso)
reIndexContent removes something from the index, then re-indexes it
|
protected boolean |
requiresIndexing(String handle,
Date 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.SolrQuery |
resolveToSolrQuery(Context context,
DiscoverQuery discoveryQuery,
boolean includeUnDiscoverable) |
protected DiscoverResult |
retrieveResult(Context context,
DiscoverQuery query,
org.apache.solr.client.solrj.response.QueryResponse solrQueryResponse) |
DiscoverResult |
search(Context context,
DiscoverQuery query)
Convenient method to call @see #search(Context, DSpaceObject,
DiscoverQuery) with a null DSpace Object as scope (i.e.
|
DiscoverResult |
search(Context context,
DiscoverQuery discoveryQuery,
boolean includeUnDiscoverable) |
DiscoverResult |
search(Context context,
IndexableObject dso,
DiscoverQuery query)
Convenient method to call @see #search(Context, DSpaceObject,
DiscoverQuery, boolean) with includeWithdrawn=false
|
DiscoverResult |
search(Context context,
IndexableObject dso,
DiscoverQuery discoveryQuery,
boolean includeUnDiscoverable) |
List<IndexableObject> |
search(Context context,
String query,
int offset,
int max,
String... filterquery) |
List<IndexableObject> |
search(Context context,
String query,
String orderfield,
boolean ascending,
int offset,
int max,
String... filterquery) |
Date |
toDate(String t)
Helper function to retrieve a date using a best guess of the potential
date encodings on a field
|
DiscoverFilterQuery |
toFilterQuery(Context context,
String field,
String operator,
String value)
Transforms the given string field and value into a filter query
|
String |
toSortFieldIndex(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 String |
transformAuthorityValue(Context context,
String field,
String value) |
protected String |
transformDisplayedValue(Context context,
String field,
String value) |
protected String |
transformFacetField(DiscoverFacetField facetFieldConfig,
String field,
boolean removePostfix) |
protected String |
transformSortValue(Context context,
String field,
String value) |
void |
unIndexContent(Context context,
IndexableObject dso)
unIndex removes an Item, Collection, or Community
|
void |
unIndexContent(Context context,
IndexableObject dso,
boolean commit)
unIndex removes an Item, Collection, or Community
|
void |
unIndexContent(Context context,
String searchUniqueID)
Unindex a Document in the Lucene index.
|
void |
unIndexContent(Context context,
String searchUniqueID,
boolean commit)
Unindex a Document in the Lucene Index.
|
void |
updateIndex(Context context)
Iterates over all Items, Collections and Communities.
|
void |
updateIndex(Context context,
boolean force)
Iterates over all Items, Collections and Communities.
|
void |
updateIndex(Context context,
boolean force,
int type) |
protected void |
writeDocument(org.apache.solr.common.SolrInputDocument doc,
FullTextContentStreams streams)
Write the document to the index under the appropriate handle.
|
public static final String DISCOVER_WORKFLOW_CONFIGURATION_NAME
public static final String DISCOVER_WORKSPACE_CONFIGURATION_NAME
protected static final String LAST_INDEXED_FIELD
protected static final String HANDLE_FIELD
protected static final String RESOURCE_UNIQUE_ID
protected static final String RESOURCE_TYPE_FIELD
protected static final String RESOURCE_ID_FIELD
protected static final String NAMED_RESOURCE_TYPE
public static final String FILTER_SEPARATOR
public static final String AUTHORITY_SEPARATOR
public static final String STORE_SEPARATOR
public static final String VARIANTS_STORE_SEPARATOR
@Autowired(required=true) protected ContentServiceFactory contentServiceFactory
@Autowired(required=true) protected ChoiceAuthorityService choiceAuthorityService
@Autowired(required=true) protected CommunityService communityService
@Autowired(required=true) protected CollectionService collectionService
@Autowired(required=true) protected ItemService itemService
@Autowired(required=true) protected HandleService handleService
@Autowired(required=true) protected MetadataAuthorityService metadataAuthorityService
@Autowired(required=true) protected WorkspaceItemService workspaceItemService
@Autowired(required=true) protected XmlWorkflowItemService workflowItemService
@Autowired(required=true) protected ClaimedTaskService claimedTaskService
@Autowired(required=true) protected PoolTaskService poolTaskService
@Autowired(required=true) protected XmlWorkflowFactory workflowFactory
@Autowired(required=true) protected GroupService groupService
protected org.apache.solr.client.solrj.SolrClient solr
protected org.apache.solr.client.solrj.SolrClient getSolr()
public void indexContent(Context context, IndexableObject dso) throws SQLException
indexContent in interface IndexingServicecontext - Users Contextdso - DSpace Object (Item, Collection or CommunitySQLException - if errorpublic void indexContent(Context context, IndexableObject dso, boolean force) throws SQLException
indexContent in interface IndexingServicecontext - Users Contextdso - DSpace Object (Item, Collection or Communityforce - Force update even if not stale.SQLException - if errorpublic void unIndexContent(Context context, IndexableObject dso) throws SQLException, IOException
unIndexContent in interface IndexingServicecontext - The relevant DSpace Context.dso - DSpace Object, can be Community, Item, or CollectionSQLException - if database errorIOException - if IO errorpublic void unIndexContent(Context context, IndexableObject dso, boolean commit) throws SQLException, IOException
unIndexContent in interface IndexingServicecontext - The relevant DSpace Context.dso - extension of DSpace Object, can be Community, Item, Collection or InProgressSubmissioncommit - if true force an immediate commit on SOLRSQLException - if database errorIOException - if IO errorpublic void unIndexContent(Context context, String searchUniqueID) throws IOException
unIndexContent in interface IndexingServicecontext - the dspace contextsearchUniqueID - the search uniqueID of the document to be deletedIOException - if IO errorpublic void unIndexContent(Context context, String searchUniqueID, boolean commit) throws IOException
unIndexContent in interface IndexingServicecontext - the dspace contextsearchUniqueID - the search uniqueID of the document to be deletedIOException - if IO errorpublic void reIndexContent(Context context, IndexableObject dso) throws SQLException, IOException
reIndexContent in interface IndexingServicecontext - context objectdso - object to re-indexSQLExceptionIOExceptionpublic void createIndex(Context c) throws SQLException, IOException
createIndex in interface IndexingServicec - context to useSQLExceptionIOExceptionpublic void updateIndex(Context context)
updateIndex in interface IndexingServicecontext - the dspace contextpublic void updateIndex(Context context, boolean force)
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.
updateIndex in interface IndexingServicecontext - the dspace contextforce - whether or not to force the reindexingpublic void updateIndex(Context context, boolean force, int type)
updateIndex in interface IndexingServicepublic void cleanIndex(boolean force)
throws IOException,
SQLException,
SearchServiceException
cleanIndex in interface IndexingServiceforce - whether or not to force a clean indexIOException - IO exceptionSQLException - sql exceptionSearchServiceException - occurs when something went wrong with querying the solr serverpublic void cleanIndex(boolean force,
int type)
throws IOException,
SQLException,
SearchServiceException
cleanIndex in interface IndexingServiceIOExceptionSQLExceptionSearchServiceExceptionpublic void optimize()
optimize in interface IndexingServicepublic void buildSpellCheck()
throws SearchServiceException,
IOException
buildSpellCheck in interface IndexingServiceSearchServiceExceptionIOExceptionprotected void emailException(Exception exception)
protected boolean requiresIndexing(String handle, Date lastModified) throws SQLException, IOException, SearchServiceException
handle - the handle of the dsolastModified - the last modified date of the DSpace objectSQLException - sql exceptionIOException - io exceptionSearchServiceException - if something went wrong with querying the solr serverprotected List<String> getItemLocations(Context context, Item myitem) throws SQLException
context - DSpace contextmyitem - the item for which our locations are to be retrievedSQLException - sql exceptionprotected List<String> getCollectionLocations(Context context, Collection target) throws SQLException
SQLExceptionprotected List<String> getCommunityLocations(Community target) throws SQLException
SQLExceptionpublic String createLocationQueryForAdministrableItems(Context context) throws SQLException
SearchServicecreateLocationQueryForAdministrableItems in interface SearchServicecontext - The relevant DSpace Context.SQLException - An exception that provides information on a database access error or other errors.protected void writeDocument(org.apache.solr.common.SolrInputDocument doc,
FullTextContentStreams streams)
throws IOException
doc - the solr document to be written to the serverstreams - list of bitstream content streamsIOException - A general class of exceptions produced by failed or interrupted I/O operations.protected void buildDocument(Context context, Community community) throws SQLException, IOException
context - The relevant DSpace Context.community - Community to be indexedSQLException - if database errorIOException - if IO errorprotected void buildDocument(Context context, Collection collection) throws SQLException, IOException
context - The relevant DSpace Context.collection - Collection to be indexedSQLException - sql exceptionIOException - IO exceptionprotected void addContainerMetadataField(org.apache.solr.common.SolrInputDocument doc,
List<String> highlightedMetadataFields,
List<String> toIgnoreMetadataFields,
String metadataField,
String value)
doc - the solr documenthighlightedMetadataFields - the list of metadata fields that CAN be highlightedtoIgnoreMetadataFields - the list of metadata fields to skip adding to SolrmetadataField - the metadata field addedvalue - the value (can be NULL !)protected void buildDocument(Context context, Item item) throws SQLException, IOException
context - Users Contextitem - The DSpace Item to be indexedSQLException - if database errorIOException - if IO errorprotected void addDiscoveryFields(org.apache.solr.common.SolrInputDocument doc,
Context context,
Item item,
List<DiscoveryConfiguration> discoveryConfigurations)
throws SQLException,
IOException
SQLExceptionIOExceptionprotected org.apache.solr.common.SolrInputDocument buildDocument(int type,
UUID id,
String handle,
List<String> locations)
type - Type of DSpace Objectid - internal identifierhandle - handle stringlocations - list of collection/community internal identifierspublic Date toDate(String t)
t - the string to be transformed to a datepublic String locationToName(Context context, String field, String value) throws SQLException
SQLExceptionpublic DiscoverResult search(Context context, DiscoverQuery query) throws SearchServiceException
SearchServicesearch in interface SearchServicecontext - DSpace Context object.query - the discovery query object.SearchServiceException - if search errorpublic DiscoverResult search(Context context, IndexableObject dso, DiscoverQuery query) throws SearchServiceException
SearchServicesearch in interface SearchServicecontext - DSpace Context objectdso - a DSpace Object to use as scope of the search (only results
within this object)query - the discovery query objectSearchServiceException - if search errorpublic DiscoverResult search(Context context, IndexableObject dso, DiscoverQuery discoveryQuery, boolean includeUnDiscoverable) throws SearchServiceException
search in interface SearchServicecontext - DSpace Context objectdso - a DSpace Object to use as scope of the search (only results
within this object)discoveryQuery - the discovery query objectincludeUnDiscoverable - use true to include in the results also withdrawn
items that match the querySearchServiceException - if search errorpublic DiscoverResult search(Context context, DiscoverQuery discoveryQuery, boolean includeUnDiscoverable) throws SearchServiceException
search in interface SearchServicecontext - DSpace Context object.discoveryQuery - the discovery query object.includeUnDiscoverable - use true to include in the results also withdrawn
items that match the query.SearchServiceException - if search errorprotected org.apache.solr.client.solrj.SolrQuery resolveToSolrQuery(Context context, DiscoverQuery discoveryQuery, boolean includeUnDiscoverable) throws SearchServiceException
SearchServiceExceptionprotected DiscoverResult retrieveResult(Context context, DiscoverQuery query, org.apache.solr.client.solrj.response.QueryResponse solrQueryResponse) throws SQLException
SQLExceptionprotected IndexableObject findIndexableObject(Context context, org.apache.solr.common.SolrDocument doc) throws SQLException
context - The relevant DSpace Context.doc - the solr documentSQLException - An exception that provides information on a database access error or other errors.public List<IndexableObject> search(Context context, String query, int offset, int max, String... filterquery)
public List<IndexableObject> search(Context context, String query, String orderfield, boolean ascending, int offset, int max, String... filterquery)
search in interface SearchServicepublic DiscoverFilterQuery toFilterQuery(Context context, String field, String operator, String value) throws SQLException
SearchServicetoFilterQuery in interface SearchServicecontext - The relevant DSpace Context.field - the field of the filter queryoperator - equals/notequals/notcontains/authority/notauthorityvalue - the filter query valueSQLException - if database error
An exception that provides information on a database access error or other errors.public List<Item> getRelatedItems(Context context, Item item, DiscoveryMoreLikeThisConfiguration mltConfig)
getRelatedItems in interface SearchServicepublic String toSortFieldIndex(String metadataField, String type)
SearchServicetoSortFieldIndex in interface SearchServicemetadataField - the metadata fieldtype - see DiscoveryConfigurationParametersprotected String transformFacetField(DiscoverFacetField facetFieldConfig, String field, boolean removePostfix)
protected String transformDisplayedValue(Context context, String field, String value) throws SQLException
SQLExceptionprotected String transformAuthorityValue(Context context, String field, String value) throws SQLException
SQLExceptionprotected String transformSortValue(Context context, String field, String value) throws SQLException
SQLExceptionpublic void indexContent(Context context, IndexableObject dso, boolean force, boolean commit) throws SearchServiceException, SQLException
indexContent in interface IndexingServiceSearchServiceExceptionSQLExceptionpublic void commit()
throws SearchServiceException
commit in interface IndexingServiceSearchServiceExceptionpublic String escapeQueryChars(String query)
SearchServiceescapeQueryChars in interface SearchServicequery - User's query to escape.public FacetYearRange getFacetYearRange(Context context, IndexableObject scope, DiscoverySearchFilterFacet facet, List<String> filterQueries, DiscoverQuery parentQuery) throws SearchServiceException
getFacetYearRange in interface SearchServiceSearchServiceExceptionpublic String calculateExtremeValue(Context context, String valueField, String sortField, DiscoverQuery.SORT_ORDER sortOrder) throws SearchServiceException
SearchServicecalculateExtremeValue in interface SearchServicecontext - 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 valueSearchServiceExceptionCopyright © 2019 DuraSpace. All rights reserved.