Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
SolrWebService Class Reference
Inheritance diagram for SolrWebService:
XmlWebService WebService

Public Member Functions

 _addArticleXml (&$articleDoc, &$article, &$journal, $markToDelete=false)
 
 _addSubquery ($fieldList, $searchPhrase, $params)
 
 _cacheMiss (&$cache, $id)
 
 _convertDate ($timestamp)
 
 _deleteFromIndex ($xml)
 
 _expandFieldList ($fields)
 
 _getAdminUrl ()
 
 _getArticleListXml (&$articles, $totalCount, &$numDeleted)
 
 _getAutosuggestUrl ($autosuggestType)
 
_getCache ()
 
 _getCoreAdminUrl ()
 
 _getDihUrl ()
 
 _getDocumentsProcessed ($result)
 
 _getFacetingAutosuggestions ($url, $searchRequest, $userInput, $fieldName)
 
 _getFieldNames ($fieldType)
 
 _getInterestingTermsUrl ()
 
_getIssue ($issueId, $journalId)
 
_getJournal ($journalId)
 
 _getLocalesAndFormats ($field)
 
 _getOrdering ($field, $direction)
 
 _getSearchQueryParameters (&$searchRequest)
 
 _getSearchUrl ()
 
 _getSuggesterAutosuggestions ($url, $userInput, $fieldName)
 
 _getUpdateUrl ()
 
 _indexingTransaction ($sendXmlCallback, $batchSize=SOLR_INDEXING_MAX_BATCHSIZE, $journalId=null)
 
 _isArticleAccessAuthorized (&$article)
 
_makeRequest ($url, $params=array(), $method= 'GET')
 
 _pushIndexingCallback (&$articleXml, $batchCount, $numDeleted)
 
 _setQuery ($fieldList, $searchPhrase, $spellcheck=false)
 
 _translateSearchPhrase ($searchPhrase, $backwards=false)
 
 deleteArticleFromIndex ($articleId)
 
 deleteArticlesFromIndex ($journalId=null)
 
 flushFieldCache ()
 
 getArticleFromIndex ($articleId)
 
 getAutosuggestions ($searchRequest, $fieldName, $userInput, $autosuggestType)
 
 getAvailableFields ($fieldType)
 
 getInterestingTerms ($articleId)
 
 getServerStatus ()
 
 getServiceMessage ()
 
 markArticleChanged ($articleId)
 
 markJournalChanged ($journalId)
 
 pullChangedArticles ($pullIndexingCallback, $batchSize=SOLR_INDEXING_MAX_BATCHSIZE, $journalId=null)
 
 pushChangedArticles ($batchSize=SOLR_INDEXING_MAX_BATCHSIZE, $journalId=null)
 
 retrieveResults (&$searchRequest, &$totalResults)
 
 SolrWebService ($searchHandler, $username, $password, $instId)
 
- Public Member Functions inherited from XmlWebService
call (&$webServiceRequest)
 
 getReturnType ()
 
 setReturnType ($returnType)
 
 XmlWebService ()
 
- Public Member Functions inherited from WebService
 _authenticateRequest (&$ch)
 
 _buildHeaders (&$webServiceRequest)
 
 _callGetWebService (&$webServiceRequest)
 
 _callPostWebService ($webServiceRequest)
 
 _callPostWebServiceAsync ($webServiceRequest)
 
call (&$webServiceRequest)
 
 getLastResponseStatus ()
 
 setAuthPassword ($authPassword)
 
 setAuthUsername ($authUsername)
 

Detailed Description

Implements the communication protocol with the solr search server.

This class relies on the PHP curl extension. Please activate the extension before trying to access a solr server through this class.

Definition at line 48 of file SolrWebService.inc.php.

Member Function Documentation

SolrWebService::_addArticleXml ( $articleDoc,
$article,
$journal,
  $markToDelete = false 
)

Add the metadata XML of a single article to an XML article list.

Parameters
$articleDocDOMDocument
$articlePublishedArticle
$journalJournal
$markToDeleteboolean If true the returned XML will only contain a deletion marker.

Definition at line 1265 of file SolrWebService.inc.php.

References _convertDate(), PKPLocale\get3LetterFrom2LetterIsoLanguage(), DAORegistry\getDAO(), PKPLocale\getLocaleFrom3LetterIso(), PKPApplication\getRequest(), and PKPLocale\isLocaleValid().

Referenced by _getArticleListXml().

SolrWebService::_addSubquery (   $fieldList,
  $searchPhrase,
  $params 
)

Add a subquery to the search query.

NB: subqueries do not support collation (for alternative spelling suggestions).

Parameters
$fieldListstring A list of fields to be queried, separated by '|'.
$searchPhrasestring The search phrase to be added.
$paramsarray The existing query parameters.

Definition at line 1677 of file SolrWebService.inc.php.

References _expandFieldList().

Referenced by _getSearchQueryParameters().

SolrWebService::_cacheMiss ( $cache,
  $id 
)

Refresh the cache from the solr server.

Parameters
$cacheFileCache
$idstring The field type.
Returns
array The available field names.

Definition at line 716 of file SolrWebService.inc.php.

References _getCoreAdminUrl(), _getFieldNames(), and _makeRequest().

SolrWebService::_convertDate (   $timestamp)

Convert a date from local time (unix timestamp or ISO date string) to UTC time as understood by solr.

NB: Using intermediate unix timestamps can be a problem in older PHP versions, especially on Windows where negative timestamps are not supported.

As Solr requires PHP5 that should not be a big problem in practice, except for electronic publications that go back until earlier than 1901. It does not seem probable that such a situation could realistically arise with OJS.

Parameters
$timestampint|string Unix timestamp or local ISO time.
Returns
string ISO UTC timestamp

Definition at line 1581 of file SolrWebService.inc.php.

Referenced by _addArticleXml(), and _getSearchQueryParameters().

SolrWebService::_deleteFromIndex (   $xml)

Delete documents from the index (by ID or by query).

Parameters
$xmlstring The documents to delete.
Returns
boolean true, if successful, otherwise false.

Definition at line 1600 of file SolrWebService.inc.php.

References _getUpdateUrl(), and _makeRequest().

Referenced by deleteArticleFromIndex(), and deleteArticlesFromIndex().

SolrWebService::_expandFieldList (   $fields)

Expand the given list of fields.

Parameters
$fieldsarray
Returns
string A space-separated field list (e.g. to be used in edismax's qf parameter).

Definition at line 1049 of file SolrWebService.inc.php.

References _getLocalesAndFormats().

Referenced by _addSubquery(), _setQuery(), getInterestingTerms(), and retrieveResults().

SolrWebService::_getAdminUrl ( )

Identifies the general solr admin endpoint from the search handler URL.

Returns
string

Definition at line 900 of file SolrWebService.inc.php.

Referenced by getServerStatus().

SolrWebService::_getArticleListXml ( $articles,
  $totalCount,
$numDeleted 
)

Retrieve the XML for a batch of articles to be updated.

Parameters
$articlesDBResultFactory The articles to be included in the list.
$totalCountinteger The overall number of changed articles (not only the current batch).
Returns
string The XML ready to be consumed by the Solr data import service.

Definition at line 1208 of file SolrWebService.inc.php.

References _addArticleXml(), _getJournal(), _isArticleAccessAuthorized(), XMLCustomWriter\createDocument(), and DAORegistry\getDAO().

Referenced by _indexingTransaction().

SolrWebService::_getAutosuggestUrl (   $autosuggestType)

Returns the solr auto-suggestion endpoint.

Parameters
$autosuggestTypestring One of the SOLR_AUTOSUGGEST_* constants
Returns
string

Definition at line 866 of file SolrWebService.inc.php.

Referenced by getAutosuggestions().

& SolrWebService::_getCache ( )

Get the field cache.

Returns
FileCache

Definition at line 810 of file SolrWebService.inc.php.

Referenced by flushFieldCache(), and getAvailableFields().

SolrWebService::_getCoreAdminUrl ( )

Identifies the solr core-specific admin endpoint from the search handler URL.

Returns
string

Definition at line 911 of file SolrWebService.inc.php.

Referenced by _cacheMiss(), and getArticleFromIndex().

SolrWebService::_getDihUrl ( )

Returns the solr DIH endpoint.

Returns
string

Definition at line 847 of file SolrWebService.inc.php.

Referenced by _pushIndexingCallback().

SolrWebService::_getDocumentsProcessed (   $result)

Retrieve the number of indexed documents from a DIH response XML

Parameters
$resultDOMXPath
Returns
integer

Definition at line 1622 of file SolrWebService.inc.php.

Referenced by _pushIndexingCallback().

SolrWebService::_getFacetingAutosuggestions (   $url,
  $searchRequest,
  $userInput,
  $fieldName 
)

Retrieve auto-suggestions from the faceting service.

Parameters
$urlstring
$searchRequestSolrSearchRequest
$userInputstring
$fieldNamestring
Returns
array The generated suggestions.

Definition at line 1883 of file SolrWebService.inc.php.

References _getSearchQueryParameters(), _makeRequest(), String\strlen(), String\strtolower(), and String\substr().

Referenced by getAutosuggestions().

SolrWebService::_getFieldNames (   $fieldType)

Return a list of all text fields that may occur in the index.

Parameters
$fieldTypestring "search", "sort" or "all"
Returns
array

Definition at line 967 of file SolrWebService.inc.php.

Referenced by _cacheMiss(), _getLocalesAndFormats(), _getOrdering(), and retrieveResults().

SolrWebService::_getInterestingTermsUrl ( )

Returns the solr endpoint to retrieve "interesting terms" from a given document.

Returns
string

Definition at line 890 of file SolrWebService.inc.php.

Referenced by getInterestingTerms().

& SolrWebService::_getIssue (   $issueId,
  $journalId 
)

Retrieve an issue (possibly from the cache).

Parameters
$issueIdint
$journalIdint
Returns
Issue

Definition at line 143 of file SolrWebService.inc.php.

References DAORegistry\getDAO().

Referenced by _isArticleAccessAuthorized().

& SolrWebService::_getJournal (   $journalId)

Retrieve a journal (possibly from the cache).

Parameters
$journalIdint
Returns
Journal

Definition at line 125 of file SolrWebService.inc.php.

References DAORegistry\getDAO().

Referenced by _getArticleListXml(), and _isArticleAccessAuthorized().

SolrWebService::_getLocalesAndFormats (   $field)

Identify all format/locale versions of the given field.

Parameters
$fieldstring A field name without any extension.
Returns
array A list of index fields.

Definition at line 1016 of file SolrWebService.inc.php.

References _getFieldNames(), and getAvailableFields().

Referenced by _expandFieldList().

SolrWebService::_getOrdering (   $field,
  $direction 
)

Generate the ordering parameter of a search query.

Parameters
$fieldstring the field to order by
$directionboolean true for ascending, false for descending
Returns
string The ordering to be used (default: descending relevance).

Definition at line 1063 of file SolrWebService.inc.php.

References _getFieldNames(), getAvailableFields(), and AppLocale\getLocale().

Referenced by retrieveResults().

SolrWebService::_getSearchQueryParameters ( $searchRequest)

Create the edismax query parameters from a search request.

Parameters
$searchRequestSolrSearchRequest
Returns
array|null A parameter array or null if something went wrong.

Definition at line 1758 of file SolrWebService.inc.php.

References _addSubquery(), _convertDate(), _setQuery(), and _translateSearchPhrase().

Referenced by _getFacetingAutosuggestions(), and retrieveResults().

SolrWebService::_getSearchUrl ( )

Returns the solr search endpoint.

Returns
string

Definition at line 856 of file SolrWebService.inc.php.

Referenced by retrieveResults().

SolrWebService::_getSuggesterAutosuggestions (   $url,
  $userInput,
  $fieldName 
)

Retrieve auto-suggestions from the suggester service.

Parameters
$urlstring
$userInputstring
$fieldNamestring
Returns
array The generated suggestions.

Definition at line 1822 of file SolrWebService.inc.php.

References _makeRequest(), String\strlen(), and String\substr().

Referenced by getAutosuggestions().

SolrWebService::_getUpdateUrl ( )

Returns the solr update endpoint.

Returns
string

Definition at line 837 of file SolrWebService.inc.php.

Referenced by _deleteFromIndex().

SolrWebService::_indexingTransaction (   $sendXmlCallback,
  $batchSize = SOLR_INDEXING_MAX_BATCHSIZE,
  $journalId = null 
)

This method encapsulates an indexing transaction (pull or push). It consists in generating the XML, transferring it to the server and marking the transferred articles as "indexed".

Parameters
$sendXmlCallbackcallback This function will be called with the generated XML.
$batchSizeinteger The maximum number of articles to be returned.
$journalIdinteger If given, only retrieves articles for the given journal.

Definition at line 1114 of file SolrWebService.inc.php.

References _getArticleListXml(), and DAORegistry\getDAO().

Referenced by pullChangedArticles(), and pushChangedArticles().

SolrWebService::_isArticleAccessAuthorized ( $article)

Check whether access to the given article is authorized to the requesting party (i.e. the Solr server).

Parameters
$articleArticle
Returns
boolean True if authorized, otherwise false.

Definition at line 1962 of file SolrWebService.inc.php.

References _getIssue(), _getJournal(), IssueAction\subscribedDomain(), and IssueAction\subscriptionRequired().

Referenced by _getArticleListXml().

& SolrWebService::_makeRequest (   $url,
  $params = array(),
  $method = 'GET' 
)

Make a request

Parameters
$urlstring The request URL
$paramsarray request parameters
$methodstring GET or POST
Returns
DOMXPath An XPath object with the response loaded. Null if an error occurred. See _serviceMessage for more details about the error.

Definition at line 926 of file SolrWebService.inc.php.

References XmlWebService\call(), PKPApplication\getApplication(), WebService\getLastResponseStatus(), and XmlWebService\setReturnType().

Referenced by _cacheMiss(), _deleteFromIndex(), _getFacetingAutosuggestions(), _getSuggesterAutosuggestions(), _pushIndexingCallback(), getArticleFromIndex(), getInterestingTerms(), getServerStatus(), and retrieveResults().

SolrWebService::_pushIndexingCallback ( $articleXml,
  $batchCount,
  $numDeleted 
)

Handle push indexing.

This method pushes XML with index changes directly to the Solr data import handler for immediate processing.

Parameters
$articleXmlstring The XML with index changes to be pushed to the Solr server.
$batchCountinteger The number of articles in the XML list (i.e. the expected number of documents to be indexed).
$numDeletedinteger The number of articles in the XML list that are marked for deletion.
Returns
integer The number of articles processed or null if an error occured.

After an error the method SolrWebService::getServiceMessage() will return details of the error.

Definition at line 1181 of file SolrWebService.inc.php.

References _getDihUrl(), _getDocumentsProcessed(), and _makeRequest().

SolrWebService::_setQuery (   $fieldList,
  $searchPhrase,
  $spellcheck = false 
)

Set the query parameters for a search query.

Parameters
$fieldListstring A list of fields to be queried, separated by '|'.
$searchPhrasestring The search phrase to be added.
$paramsarray The existing query parameters.
$spellcheckboolean Whether to switch spellchecking on.

Definition at line 1639 of file SolrWebService.inc.php.

References _expandFieldList().

Referenced by _getSearchQueryParameters().

SolrWebService::_translateSearchPhrase (   $searchPhrase,
  $backwards = false 
)

Translate query keywords.

Parameters
$searchPhrasestring
Returns
The translated search phrase.

Definition at line 1725 of file SolrWebService.inc.php.

References String\regexp_replace(), and String\strtoupper().

Referenced by _getSearchQueryParameters(), and retrieveResults().

SolrWebService::deleteArticleFromIndex (   $articleId)

Deletes the given article from the Solr index.

Parameters
$articleIdinteger The ID of the article to be deleted.
Returns
boolean true if successful, otherwise false.

Definition at line 268 of file SolrWebService.inc.php.

References _deleteFromIndex().

SolrWebService::deleteArticlesFromIndex (   $journalId = null)

Deletes all articles of a journal or of the installation from the Solr index.

Parameters
$journalIdinteger If given, only articles from this journal will be deleted.
Returns
boolean true if successful, otherwise false.

Definition at line 281 of file SolrWebService.inc.php.

References _deleteFromIndex().

SolrWebService::flushFieldCache ( )

Flush the field cache.

Definition at line 638 of file SolrWebService.inc.php.

References _getCache().

SolrWebService::getArticleFromIndex (   $articleId)

Retrieve a document directly from the index (for testing/debugging purposes only).

Parameters
$articleId
Returns
array The document fields.

Definition at line 651 of file SolrWebService.inc.php.

References _getCoreAdminUrl(), and _makeRequest().

SolrWebService::getAutosuggestions (   $searchRequest,
  $fieldName,
  $userInput,
  $autosuggestType 
)

Retrieve auto-suggestions from the solr index corresponding to the given user input.

Parameters
$searchRequestSolrSearchRequest Active search filters. Choosing the faceting auto-suggest implementation via $autosuggestType will pre-filter auto-suggestions based on this search request. In case of the suggester component, the search request will simply be ignored.
$fieldNamestring The field to suggest values for. Values are queried on field level to improve relevance of suggestions.
$userInputstring Partial query input. This input will be split split up. Only the last query term will be used to suggest values.
$autosuggestTypestring One of the SOLR_AUTOSUGGEST_* constants. The faceting implementation is slower but will return more relevant suggestions. The suggestor implementation is faster and scales better in large deployments. It will return terms from a field-specific global dictionary, though, e.g. from different journals.
Returns
array A list of suggested queries

Definition at line 558 of file SolrWebService.inc.php.

References _getAutosuggestUrl(), _getFacetingAutosuggestions(), and _getSuggesterAutosuggestions().

SolrWebService::getAvailableFields (   $fieldType)

Returns an array with all (dynamic) fields in the index.

NB: This is cached data so after an index update we may have to flush the index to re-read the current index state.

Parameters
$fieldTypestring Either 'search' or 'sort'.
Returns
array

Definition at line 629 of file SolrWebService.inc.php.

References _getCache().

Referenced by _getLocalesAndFormats(), and _getOrdering().

SolrWebService::getInterestingTerms (   $articleId)

Retrieve "interesting terms" from a document to be used in a "similar documents" search.

Parameters
$articleIdinteger The article from which we retrieve "interesting terms".
Returns
array An array of terms that can be used to execute a search for similar documents.

Definition at line 589 of file SolrWebService.inc.php.

References _expandFieldList(), _getInterestingTermsUrl(), and _makeRequest().

SolrWebService::getServerStatus ( )

Checks the solr server status.

Returns
integer One of the SOLR_STATUS_* constants.

Definition at line 676 of file SolrWebService.inc.php.

References _getAdminUrl(), and _makeRequest().

SolrWebService::getServiceMessage ( )

Get the last service message.

Returns
string

Definition at line 115 of file SolrWebService.inc.php.

SolrWebService::markArticleChanged (   $articleId)

Mark a single article "changed" so that the indexing back-end will update it during the next batch update.

Parameters
$articleIdInteger

Definition at line 164 of file SolrWebService.inc.php.

References DAORegistry\getDAO().

Referenced by markJournalChanged().

SolrWebService::markJournalChanged (   $journalId)

Mark the given journal for re-indexing.

Parameters
$journalIdinteger The ID of the journal to be (re-)indexed.
Returns
integer The number of articles that have been marked.

Definition at line 182 of file SolrWebService.inc.php.

References DAORegistry\getDAO(), and markArticleChanged().

SolrWebService::pullChangedArticles (   $pullIndexingCallback,
  $batchSize = SOLR_INDEXING_MAX_BATCHSIZE,
  $journalId = null 
)

Retrieves a batch of articles in XML format.

This is the pull-indexing implementation of the Solr web service.

To control memory usage and response time we index articles in batches. Batches should be as large as possible to reduce index commit overhead.

Parameters
$sendXmlCallbackcallback This function will be called with the generated XML. We do not send the XML from here as communication with the requesting counterparty should be done from the controller and not from the back-end.
$batchSizeinteger The maximum number of articles to be returned.
$journalIdinteger If given, only returns articles from the given journal.
Returns
integer The number of articles processed or null if an error occured. After an error the method SolrWebService::getServiceMessage() will return details of the error.

Definition at line 253 of file SolrWebService.inc.php.

References _indexingTransaction().

SolrWebService::pushChangedArticles (   $batchSize = SOLR_INDEXING_MAX_BATCHSIZE,
  $journalId = null 
)

(Re-)indexes all changed articles in Solr.

This is the push-indexing implementation of the Solr web service.

To control memory usage and response time we index articles in batches. Batches should be as large as possible to reduce index commit overhead.

Parameters
$batchSizeinteger The maximum number of articles to be indexed in this run.
$journalIdinteger If given, restrains index updates to the given journal.
Returns
integer The number of articles processed or null if an error occured. After an error the method SolrWebService::getServiceMessage() will return details of the error.

Definition at line 221 of file SolrWebService.inc.php.

References _indexingTransaction().

SolrWebService::retrieveResults ( $searchRequest,
$totalResults 
)

Execute a search against the Solr search server.

Parameters
$searchRequestSolrSearchRequest
$totalResultsinteger An output parameter returning the total number of search results found by the query. This differs from the actual number of returned results as the search can be limited.
Returns
array An array of search results. The main keys are result types. These are "scoredResults" and "alternativeSpelling". The keys in the "scoredResults" sub-array are scores (1-9999) and the values are article IDs. The alternative spelling sub-array returns an alternative query string (if any) and the number of hits for this string. Null if an error occured while querying the server.

Definition at line 310 of file SolrWebService.inc.php.

References _expandFieldList(), _getFieldNames(), _getOrdering(), _getSearchQueryParameters(), _getSearchUrl(), _makeRequest(), _translateSearchPhrase(), and AppLocale\getLocale().

SolrWebService::SolrWebService (   $searchHandler,
  $username,
  $password,
  $instId 
)

Constructor

Parameters
$searchHandlerstring The search handler URL. We assume the embedded server as a default.
$usernamestring The HTTP BASIC authentication username.
$passwordstring The corresponding password.
$instIdstring The unique ID of this OJS installation to partition a shared index.

Definition at line 85 of file SolrWebService.inc.php.

References WebService\setAuthPassword(), and WebService\setAuthUsername().


The documentation for this class was generated from the following file: