class SearchApiSolrDateSortQuery in Search Api Solr Date Sort 7
Base extension to override the sorting to allow for the date to sort.
Hierarchy
- class \SearchApiQuery implements SearchApiQueryInterface
- class \SearchApiSolrDateSortQuery
Expanded class hierarchy of SearchApiSolrDateSortQuery
File
- includes/
query.inc, line 10 - Contains SearchApiViewsQuery.
View source
class SearchApiSolrDateSortQuery extends SearchApiQuery {
/**
* {@inheritdoc}
*/
// Largely copied from SearchApiQuery but adds handling for date string
public function sort($field, $order = 'ASC') {
$fields = $this->index->options['fields'];
$fields += array(
'search_api_relevance' => array(
'type' => 'decimal',
),
'search_api_id' => array(
'type' => 'integer',
),
'search_api_random' => array(
'type' => 'integer',
),
);
// Add Date Handling for the sort.
$date_fields = array();
foreach ($fields as $k => $v) {
// If a date field, process the name into the defined string.
if ($v['type'] == 'list<date>') {
$date_fields[search_api_solr_date_sort_to_string($k)] = array(
'type' => 'date',
);
}
}
$fields += $date_fields;
if (empty($fields[$field])) {
throw new SearchApiException(t('Trying to sort on unknown field @field.', array(
'@field' => $field,
)));
}
$type = $fields[$field]['type'];
// Add the check to make sure the list<date> isn't include, but other lists are excluded.
if ($type != 'list<date>' && (search_api_is_list_type($type) || search_api_is_text_type($type))) {
throw new SearchApiException(t('Trying to sort on field @field of illegal type @type.', array(
'@field' => $field,
'@type' => $type,
)));
}
if ($field != 'search_api_random') {
$order = strtoupper(trim($order)) == 'DESC' ? 'DESC' : 'ASC';
}
else {
if ($order == 'ASC' || $order == "DESC") {
$order = 'random_' . rand(1, 200) . ' asc';
}
}
$this->sort[$field] = $order;
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SearchApiQuery:: |
protected | property | The fields that will be searched for the keys. | |
SearchApiQuery:: |
protected | property | The search filter associated with this query. | |
SearchApiQuery:: |
protected | property | The index this query will use. | |
SearchApiQuery:: |
protected | property | The index's machine name. | |
SearchApiQuery:: |
protected | property | The search keys. If NULL, this will be a filter-only search. | |
SearchApiQuery:: |
protected | property | Search options configuring this query. | |
SearchApiQuery:: |
protected | property | The unprocessed search keys, as passed to the keys() method. | |
SearchApiQuery:: |
protected | property | Flag for whether preExecute() was already called for this query. | |
SearchApiQuery:: |
protected | property | The sort associated with this query. | |
SearchApiQuery:: |
protected | function | Adds language filters for the query. | |
SearchApiQuery:: |
public | function |
Adds a new ($field $operator $value) condition filter. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Creates a new filter to use with this query object. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Executes this search query. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Adds a subfilter to this query's filter. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Retrieves the fulltext fields that will be searched for the search keys. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Retrieves the filter object associated with this search query. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Retrieves the index associated with this search. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Retrieves the search keys for this query. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Retrieves an option set on this search query. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Retrieves all options set for this search query. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Retrieves the unparsed search keys for this query as originally entered. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Retrieves the sorts set for this query. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Sets the keys to search for. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
protected | function | ||
SearchApiQuery:: |
public | function |
Retrieves the parse modes supported by this query class. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Postprocesses the search results before they are returned. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Prepares the query object for the search. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function |
Adds a range of results to return. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
protected | function | Sanitizes an array of options in a way that plays nice with var_export(). | |
SearchApiQuery:: |
public | function |
Sets an option for this search query. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function | Implements the magic __clone() method to clone the filter, too. | |
SearchApiQuery:: |
public | function |
Constructs a new search query. Overrides SearchApiQueryInterface:: |
|
SearchApiQuery:: |
public | function | Implements the magic __sleep() method to avoid serializing the index. | |
SearchApiQuery:: |
public | function | Implements the magic __toString() method to simplify debugging. | |
SearchApiQuery:: |
public | function | Implements the magic __wakeup() method to reload the query's index. | |
SearchApiSolrDateSortQuery:: |
public | function |
Adds a sort directive to this search query. Overrides SearchApiQuery:: |