@Service public class SolrServiceImpl extends Object implements SearchService, IndexingService
| Modifier and Type | Field and Description |
|---|---|
static String |
AUTHORITY_SEPARATOR |
static String |
FILTER_SEPARATOR |
protected static String |
LAST_INDEXED_FIELD |
static String |
STORE_SEPARATOR |
static String |
VARIANTS_STORE_SEPARATOR |
| Constructor and Description |
|---|
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 |
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,
int id,
String handle,
List<String> locations)
Create Lucene document with all the shared fields initialized.
|
void |
cleanIndex(boolean force)
Iterates over all documents in the Lucene index and verifies they are in
database, if not, they are removed.
|
void |
commit() |
void |
createIndex(Context c)
create full index - wiping old index
|
protected void |
emailException(Exception exception) |
protected static DSpaceObject |
findDSpaceObject(Context context,
org.apache.solr.common.SolrDocument doc) |
protected List<String> |
getCollectionLocations(Collection target) |
protected List<String> |
getItemLocations(Item myitem) |
List<Item> |
getRelatedItems(Context context,
Item item,
DiscoveryMoreLikeThisConfiguration mltConfig) |
protected org.apache.solr.client.solrj.impl.HttpSolrServer |
getSolr() |
void |
indexContent(Context context,
DSpaceObject 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,
DSpaceObject 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,
DSpaceObject dso,
boolean force,
boolean commit) |
static String |
locationToName(Context context,
String field,
String value) |
void |
optimize()
Maintenance to keep a SOLR index efficient.
|
void |
reIndexContent(Context context,
DSpaceObject 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,
DSpaceObject dso,
DiscoverQuery query)
Convenient method to call @see #search(Context, DSpaceObject,
DiscoverQuery, boolean) with includeWithdrawn=false
|
DiscoverResult |
search(Context context,
DSpaceObject dso,
DiscoverQuery discoveryQuery,
boolean includeUnDiscoverable) |
List<DSpaceObject> |
search(Context context,
String query,
int offset,
int max,
String... filterquery) |
List<DSpaceObject> |
search(Context context,
String query,
String orderfield,
boolean ascending,
int offset,
int max,
String... filterquery) |
InputStream |
searchAsInputStream(DiscoverQuery query)
Simple means to return the search result as an InputStream
|
InputStream |
searchJSON(Context context,
DiscoverQuery query,
DSpaceObject dso,
String jsonIdentifier) |
InputStream |
searchJSON(Context context,
DiscoverQuery discoveryQuery,
String jsonIdentifier) |
static 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,
DSpaceObject dso)
unIndex removes an Item, Collection, or Community
|
void |
unIndexContent(Context context,
DSpaceObject dso,
boolean commit)
unIndex removes an Item, Collection, or Community
|
void |
unIndexContent(Context context,
String handle)
Unindex a Document in the Lucene index.
|
void |
unIndexContent(Context context,
String handle,
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.
|
protected void |
writeDocument(org.apache.solr.common.SolrInputDocument doc)
Write the document to the index under the appropriate handle.
|
protected static final String LAST_INDEXED_FIELD
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
protected org.apache.solr.client.solrj.impl.HttpSolrServer getSolr()
public void indexContent(Context context, DSpaceObject dso) throws SQLException
indexContent in interface IndexingServicecontext - Users Contextdso - DSpace Object (Item, Collection or CommunitySQLExceptionIOExceptionpublic void indexContent(Context context, DSpaceObject dso, boolean force) throws SQLException
indexContent in interface IndexingServicecontext - Users Contextdso - DSpace Object (Item, Collection or Communityforce - Force update even if not stale.SQLExceptionIOExceptionpublic void unIndexContent(Context context, DSpaceObject dso) throws SQLException, IOException
unIndexContent in interface IndexingServicecontext - dso - DSpace Object, can be Community, Item, or CollectionSQLExceptionIOExceptionpublic void unIndexContent(Context context, DSpaceObject dso, boolean commit) throws SQLException, IOException
unIndexContent in interface IndexingServicecontext - dso - DSpace Object, can be Community, Item, or Collectioncommit - if true force an immediate commit on SOLRSQLExceptionIOExceptionpublic void unIndexContent(Context context, String handle) throws IOException, SQLException
unIndexContent in interface IndexingServicecontext - the dspace contexthandle - the handle of the object to be deletedIOExceptionSQLExceptionpublic void unIndexContent(Context context, String handle, boolean commit) throws SQLException, IOException
unIndexContent in interface IndexingServicecontext - the dspace contexthandle - the handle of the object to be deletedSQLExceptionIOExceptionpublic void reIndexContent(Context context, DSpaceObject 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)
updateIndex in interface IndexingServicecontext - the dspace contextforce - whether or not to force the reindexingpublic 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 optimize()
optimize in interface IndexingServiceprotected 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(Item myitem) throws SQLException
myitem - the item for which our locations are to be retrievedSQLException - sql exceptionprotected List<String> getCollectionLocations(Collection target) throws SQLException
SQLExceptionprotected void writeDocument(org.apache.solr.common.SolrInputDocument doc)
throws IOException
doc - the solr document to be written to the serverIOException - IO exceptionprotected void buildDocument(Context context, Community community) throws SQLException, IOException
community - Community to be indexedSQLExceptionIOExceptionprotected void buildDocument(Context context, Collection collection) throws SQLException, IOException
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 highlightedmetadataField - 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 indexedSQLExceptionIOExceptionprotected org.apache.solr.common.SolrInputDocument buildDocument(int type,
int id,
String handle,
List<String> locations)
type - Type of DSpace Objectid - handle - locations - @returnpublic static Date toDate(String t)
t - the string to be transformed to a datepublic static 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.SearchServiceExceptionpublic DiscoverResult search(Context context, DSpaceObject 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 objectSearchServiceExceptionpublic DiscoverResult search(Context context, DSpaceObject 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 querySearchServiceExceptionpublic 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.SearchServiceExceptionprotected org.apache.solr.client.solrj.SolrQuery resolveToSolrQuery(Context context, DiscoverQuery discoveryQuery, boolean includeUnDiscoverable)
public InputStream searchJSON(Context context, DiscoverQuery query, DSpaceObject dso, String jsonIdentifier) throws SearchServiceException
searchJSON in interface SearchServiceSearchServiceExceptionpublic InputStream searchJSON(Context context, DiscoverQuery discoveryQuery, String jsonIdentifier) throws SearchServiceException
searchJSON in interface SearchServiceSearchServiceExceptionprotected DiscoverResult retrieveResult(Context context, DiscoverQuery query, org.apache.solr.client.solrj.response.QueryResponse solrQueryResponse) throws SQLException
SQLExceptionprotected static DSpaceObject findDSpaceObject(Context context, org.apache.solr.common.SolrDocument doc) throws SQLException
SQLExceptionpublic InputStream searchAsInputStream(DiscoverQuery query) throws SearchServiceException, IOException
SearchServiceExceptionIOExceptionpublic List<DSpaceObject> search(Context context, String query, int offset, int max, String... filterquery)
public List<DSpaceObject> 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 DSpace contextfield - the field of the filter queryvalue - the filter query valueSQLException - ...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 fieldprotected 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, DSpaceObject dso, boolean force, boolean commit) throws SearchServiceException, SQLException
indexContent in interface IndexingServiceSearchServiceExceptionSQLExceptionpublic void commit()
throws SearchServiceException
commit in interface IndexingServiceSearchServiceExceptionCopyright © 2013 DuraSpace. All Rights Reserved.