class SearchApiSolrDateSortSolrService in Search Api Solr Date Sort 7
Extension class with generic implementation of most service methods.
Hierarchy
- class \SearchApiAbstractService implements SearchApiServiceInterface
- class \SearchApiSolrService
Expanded class hierarchy of SearchApiSolrDateSortSolrService
1 string reference to 'SearchApiSolrDateSortSolrService'
File
- includes/
service.inc, line 10 - Contains SearchApiViewsEventsSolrService.
View source
class SearchApiSolrDateSortSolrService extends SearchApiSolrService {
/**
* {@inheritdoc}
*/
public function query(SearchApiIndex $index, $options = array()) {
// To Override the sort, we need to instantiate a different method.
return new SearchApiSolrDateSortQuery($index, $options);
}
/**
* {@inheritdoc}
*
* This alteration adds the first value of a multiple value date field as a string.
* It then duplicates the events that have multiple dates, and inserts them as
* a new document for each start date into the solr db.
*/
protected function alterSolrDocuments(array &$documents, SearchApiIndex $index, array $items) {
parent::alterSolrDocuments($documents, $index, $items);
// Grab only the start date fields. Duplication isn't needed for end dates.
$date_fields = _search_api_solr_date_sort_date_fields($index, 'dm');
// Loop through each document to check for the date fields.
foreach ($documents as $document) {
// Loop Through each date field.
//
// @todo: Might want to limit this to a single field.
foreach ($date_fields as $field) {
// Grab all the date field values.
$start_dates = $document
->getField($field);
$end_dates = $document
->getField($field . '2');
// If the start is not empty append the field.
if (!empty($start_dates['value'])) {
$string_field = substr_replace($field, 'ds_', 0, 3);
// We account for multiple values of dates by storing each entity as a
// new instance.
$batches = array_chunk($start_dates['value'], 25, TRUE);
foreach ($batches as $batch) {
// Create a new array of new documents that will get added into the solr index.
$new_documents = array();
foreach ($batch as $i => $date) {
if ($i == 0) {
// For the first one, set the first start date.
$document
->setField($string_field, $date);
// Set the end date.
$document
->setField($string_field . '2', $end_dates['value'][$i]);
}
else {
// Clone the document to add it to the index.
$new_document = clone $document;
// If there are multiple dates, we need an id for each date. Thus,
// append -###.
$item_id = $document
->getField('item_id');
$item_id = $item_id['value'] . '-' . $i;
// Set the new id as well
$new_document
->setField('item_id', $item_id);
unset($new_document->{$field});
$field_2 = $field . '2';
unset($new_document->{$field_2});
$hash = $document
->getField('hash');
$index_id = $document
->getField('index_id');
// Create a new id.
$new_document
->setField('id', $hash['value'] . '_' . $index_id['value'] . '_' . $item_id);
// Add the specific date for this document.
$new_document
->setField($string_field, $date);
// Set the end date.
$new_document
->setField($string_field . '2', $end_dates['value'][$i]);
$new_documents[] = $new_document;
}
}
$this
->SearchApiSolrDateSortAddNewDocs($new_documents);
}
}
}
}
}
/**
* Custom function to add the new documents.
*
* @param array $new_documents
* Array of duplcicated documents
*/
protected function SearchApiSolrDateSortAddNewDocs($new_documents) {
$ret = array();
if (!empty($new_documents)) {
try {
$this
->connect();
$this->solr
->addDocuments($new_documents);
if (!empty($index->options['index_directly'])) {
$this
->scheduleCommit();
}
return $ret;
} catch (SearchApiException $e) {
watchdog_exception('search_api_solr', $e, "%type while indexing: !message in %function (line %line of %file).");
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SearchApiAbstractService:: |
protected | property | Direct reference to the server's $options property. | |
SearchApiAbstractService:: |
protected | property | ||
SearchApiAbstractService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiServiceInterface:: |
|
SearchApiAbstractService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiServiceInterface:: |
|
SearchApiAbstractService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiServiceInterface:: |
1 |
SearchApiAbstractService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiServiceInterface:: |
|
SearchApiSolrDateSortSolrService:: |
protected | function |
This alteration adds the first value of a multiple value date field as a string.
It then duplicates the events that have multiple dates, and inserts them as
a new document for each start date into the solr db. Overrides SearchApiSolrService:: |
|
SearchApiSolrDateSortSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrDateSortSolrService:: |
protected | function | Custom function to add the new documents. | |
SearchApiSolrService:: |
protected | property | Saves whether a commit operation was already scheduled for this server. | |
SearchApiSolrService:: |
protected | property | The connection class used by this service. | |
SearchApiSolrService:: |
protected | property | Static cache for getFieldNames(). | |
SearchApiSolrService:: |
protected | property | Metadata describing fields on the Solr/Lucene index. | |
SearchApiSolrService:: |
protected | property | Request handler to use for this search query. | |
SearchApiSolrService:: |
protected | property | A connection to the Solr server. | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | Helper method for indexing. | |
SearchApiSolrService:: |
public | function | Sends a commit command to the Solr server. | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | Create a connection to the Solr server as configured in $this->options. | |
SearchApiSolrService:: |
protected | function | Transforms a query filter into a flat array of Solr filter queries, using the field names in $fields. | |
SearchApiSolrService:: |
protected | function | Create a single search query string according to the given field, value and operator. | |
SearchApiSolrService:: |
public | function | Creates an ID used as the unique identifier at the Solr server. | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::deleteItems(). Overrides SearchApiServiceInterface:: |
|
SearchApiSolrService:: |
protected | function | Extract facets from a Solr response. | |
SearchApiSolrService:: |
protected | function | Extracts short snippets with highlighting from highlighted field values. | |
SearchApiSolrService:: |
protected | function | Extract results from a Solr response. | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | Flatten a keys array into a single search string. | |
SearchApiSolrService:: |
protected | function | Format a value for filtering on a field of a specific type. | |
SearchApiSolrService:: |
protected | function | Changes highlighting tags from our custom, HTML-safe ones to HTML. | |
SearchApiSolrService:: |
public | function | ||
SearchApiSolrService:: |
public | function | Gets the Solr connection class used by this service. | |
SearchApiSolrService:: |
protected | function | Extract and format highlighting information for a specific item from a Solr response. | |
SearchApiSolrService:: |
public | function |
Returns additional, service-specific information about this server. Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | Helper method for creating the facet field parameters. | |
SearchApiSolrService:: |
public | function | Create a list of all indexed field names mapped to their Solr field names. | |
SearchApiSolrService:: |
public | function | Get metadata about fields in the Solr/Lucene index. | |
SearchApiSolrService:: |
public | function | Retrieves a config file or file list from the Solr server. | |
SearchApiSolrService:: |
protected | function | Returns the prefix and suffix for highlighting matches in the excerpt. | |
SearchApiSolrService:: |
protected | function | Helper method for creating the highlighting parameters. | |
SearchApiSolrService:: |
protected | function | Prefixes an index ID as configured. | |
SearchApiSolrService:: |
protected | function | Retrieves the effective fulltext fields from the query. | |
SearchApiSolrService:: |
public | function | Returns a link to the Solr server, if the necessary options are set. | |
SearchApiSolrService:: |
public | function | Gets the currently used Solr connection object. | |
SearchApiSolrService:: |
public | function |
Indexes the specified items. Overrides SearchApiServiceInterface:: |
|
SearchApiSolrService:: |
public | function | Ping the Solr server to tell whether it can be accessed. | |
SearchApiSolrService:: |
protected | function | Empty method to allow subclasses to apply custom changes before search results are returned. | |
SearchApiSolrService:: |
protected | function | Empty method called before sending a search query to Solr. | |
SearchApiSolrService:: |
public | function | Implements SearchApiMultiServiceInterface::queryMultiple(). | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | ||
SearchApiSolrService:: |
protected | function | Sanitizes a highlighted field value. | |
SearchApiSolrService:: |
public | function | Schedules a commit operation for this server. | |
SearchApiSolrService:: |
public | function |
Executes a search on the server represented by this object. Overrides SearchApiServiceInterface:: |
|
SearchApiSolrService:: |
public | function | Implements SearchApiMultiServiceInterface::searchMultiple(). | |
SearchApiSolrService:: |
public | function | Sets the Solr connection class used by this service. | |
SearchApiSolrService:: |
protected | function | Sets the request handler. | |
SearchApiSolrService:: |
constant | The date format that Solr uses, in PHP date() syntax. | ||
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
public | function |
Overrides SearchApiAbstractService::viewSettings(). Overrides SearchApiAbstractService:: |