org.dspace.discovery
Class SolrServiceImpl

java.lang.Object
  extended by org.dspace.discovery.SolrServiceImpl
All Implemented Interfaces:
IndexingService, SearchService

@Service
public class SolrServiceImpl
extends Object
implements SearchService, IndexingService

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 SolrServiceImple 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
static String FILTER_SEPARATOR
           
 
Constructor Summary
SolrServiceImpl()
           
 
Method Summary
 void cleanIndex(boolean force)
          Iterates over all documents in the Lucene index and verifies they are in database, if not, they are removed.
 void createIndex(Context c)
          create full index - wiping old index
protected  org.apache.solr.client.solrj.impl.CommonsHttpSolrServer getSolr()
          Non-Static Singelton instance of Configuration Service
 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.
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
 DiscoverResult search(Context context, DiscoverQuery discoveryQuery)
           
 DiscoverResult search(Context context, DSpaceObject dso, DiscoverQuery discoveryQuery)
           
 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
 String searchJSON(DiscoverQuery query, DSpaceObject dso, String jsonIdentifier)
           
 String searchJSON(DiscoverQuery query, 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 filterQuery)
           
 DiscoverFilterQuery toFilterQuery(Context context, String field, String value)
           
 String toSortFieldIndex(String metadataField, String type)
           
 void unIndexContent(Context context, DSpaceObject dso)
          unIndex removes an Item, Collection, or Community only works if the DSpaceObject has a handle (uses the handle for its unique ID)
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILTER_SEPARATOR

public static final String FILTER_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

SolrServiceImpl

public SolrServiceImpl()
Method Detail

getSolr

protected org.apache.solr.client.solrj.impl.CommonsHttpSolrServer getSolr()
                                                                   throws MalformedURLException,
                                                                          org.apache.solr.client.solrj.SolrServerException
Non-Static Singelton instance of Configuration Service

Throws:
MalformedURLException
org.apache.solr.client.solrj.SolrServerException

indexContent

public void indexContent(Context context,
                         DSpaceObject dso)
                  throws SQLException
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:
indexContent in interface IndexingService
Parameters:
context - Users Context
dso - DSpace Object (Item, Collection or Community
Throws:
SQLException
IOException

indexContent

public void indexContent(Context context,
                         DSpaceObject dso,
                         boolean force)
                  throws SQLException
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:
indexContent in interface IndexingService
Parameters:
context - Users Context
dso - DSpace Object (Item, Collection or Community
force - Force update even if not stale.
Throws:
SQLException
IOException

unIndexContent

public void unIndexContent(Context context,
                           DSpaceObject dso)
                    throws SQLException,
                           IOException
unIndex removes an Item, Collection, or Community only works if the DSpaceObject has a handle (uses the handle for its unique ID)

Specified by:
unIndexContent in interface IndexingService
Parameters:
context -
dso - DSpace Object, can be Community, Item, or Collection
Throws:
SQLException
IOException

unIndexContent

public void unIndexContent(Context context,
                           String handle)
                    throws IOException,
                           SQLException
Unindex a Document in the Lucene index.

Specified by:
unIndexContent in interface IndexingService
Parameters:
context - the dspace context
handle - the handle of the object to be deleted
Throws:
IOException
SQLException

unIndexContent

public void unIndexContent(Context context,
                           String handle,
                           boolean commit)
                    throws SQLException,
                           IOException
Unindex a Document in the Lucene Index.

Specified by:
unIndexContent in interface IndexingService
Parameters:
context - the dspace context
handle - the handle of the object to be deleted
Throws:
SQLException
IOException

reIndexContent

public void reIndexContent(Context context,
                           DSpaceObject dso)
                    throws SQLException,
                           IOException
reIndexContent removes something from the index, then re-indexes it

Specified by:
reIndexContent in interface IndexingService
Parameters:
context - context object
dso - object to re-index
Throws:
SQLException
IOException

createIndex

public void createIndex(Context c)
                 throws SQLException,
                        IOException
create full index - wiping old index

Specified by:
createIndex in interface IndexingService
Parameters:
c - context to use
Throws:
SQLException
IOException

updateIndex

public void updateIndex(Context context)
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:
updateIndex in interface IndexingService
Parameters:
context - the dspace context

updateIndex

public void updateIndex(Context context,
                        boolean force)
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:
updateIndex in interface IndexingService
Parameters:
context - the dspace context
force - whether or not to force the reindexing

cleanIndex

public void cleanIndex(boolean force)
                throws IOException,
                       SQLException,
                       SearchServiceException
Iterates over all documents in the Lucene index and verifies they are in database, if not, they are removed.

Specified by:
cleanIndex in interface IndexingService
Parameters:
force - whether or not to force a clean index
Throws:
IOException - IO exception
SQLException - sql exception
SearchServiceException - 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:
optimize in interface IndexingService

toDate

public static Date toDate(String t)
Helper function to retrieve a date using a best guess of the potential date encodings on a field

Parameters:
t - the string to be transformed to a date
Returns:
a date if the formatting was successful, null if not able to transform to a date

locationToName

public static String locationToName(Context context,
                                    String field,
                                    String value)
                             throws SQLException
Throws:
SQLException

search

public DiscoverResult search(Context context,
                             DSpaceObject dso,
                             DiscoverQuery discoveryQuery)
                      throws SearchServiceException
Specified by:
search in interface SearchService
Throws:
SearchServiceException

search

public DiscoverResult search(Context context,
                             DiscoverQuery discoveryQuery)
                      throws SearchServiceException
Specified by:
search in interface SearchService
Throws:
SearchServiceException

searchJSON

public String searchJSON(DiscoverQuery query,
                         DSpaceObject dso,
                         String jsonIdentifier)
                  throws SearchServiceException
Specified by:
searchJSON in interface SearchService
Throws:
SearchServiceException

searchJSON

public String searchJSON(DiscoverQuery query,
                         String jsonIdentifier)
                  throws SearchServiceException
Specified by:
searchJSON in interface SearchService
Throws:
SearchServiceException

searchAsInputStream

public InputStream searchAsInputStream(DiscoverQuery query)
                                throws SearchServiceException,
                                       IOException
Simple means to return the search result as an InputStream

Throws:
SearchServiceException
IOException

search

public List<DSpaceObject> search(Context context,
                                 String query,
                                 int offset,
                                 int max,
                                 String... filterquery)

search

public List<DSpaceObject> search(Context context,
                                 String query,
                                 String orderfield,
                                 boolean ascending,
                                 int offset,
                                 int max,
                                 String... filterquery)
Specified by:
search in interface SearchService

toFilterQuery

public DiscoverFilterQuery toFilterQuery(Context context,
                                         String filterQuery)
                                  throws SQLException
Specified by:
toFilterQuery in interface SearchService
Throws:
SQLException

toFilterQuery

public DiscoverFilterQuery toFilterQuery(Context context,
                                         String field,
                                         String value)
                                  throws SQLException
Specified by:
toFilterQuery in interface SearchService
Throws:
SQLException

toSortFieldIndex

public String toSortFieldIndex(String metadataField,
                               String type)
Specified by:
toSortFieldIndex in interface SearchService


Copyright © 2011 DuraSpace. All Rights Reserved.