updated to 7.x-1.11
This commit is contained in:
@@ -26,7 +26,7 @@ interface SearchApiAlterCallbackInterface {
|
||||
/**
|
||||
* Check whether this data-alter callback is applicable for a certain index.
|
||||
*
|
||||
* This can be used for hiding the callback on the index's "Workflow" tab. To
|
||||
* This can be used for hiding the callback on the index's "Filters" tab. To
|
||||
* avoid confusion, you should only use criteria that are immutable, such as
|
||||
* the index's entity type. Also, since this is only used for UI purposes, you
|
||||
* should not completely rely on this to ensure certain index configurations
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiAlterAddAggregation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Search API data alteration callback that adds an URL field for all items.
|
||||
*/
|
||||
@@ -11,7 +16,11 @@ class SearchApiAlterAddAggregation extends SearchApiAbstractAlterCallback {
|
||||
$fields = $this->index->getFields(FALSE);
|
||||
$field_options = array();
|
||||
foreach ($fields as $name => $field) {
|
||||
$field_options[$name] = $field['name'];
|
||||
$field_options[$name] = check_plain($field['name']);
|
||||
$field_properties[$name] = array(
|
||||
'#attributes' => array('title' => $name),
|
||||
'#description' => check_plain($field['description']),
|
||||
);
|
||||
}
|
||||
$additional = empty($this->options['fields']) ? array() : $this->options['fields'];
|
||||
|
||||
@@ -63,14 +72,14 @@ class SearchApiAlterAddAggregation extends SearchApiAbstractAlterCallback {
|
||||
foreach (array_keys($types) as $type) {
|
||||
$form['fields'][$name]['type_descriptions'][$type]['#states']['visible'][':input[name="callbacks[search_api_alter_add_aggregation][settings][fields][' . $name . '][type]"]']['value'] = $type;
|
||||
}
|
||||
$form['fields'][$name]['fields'] = array(
|
||||
$form['fields'][$name]['fields'] = array_merge($field_properties, array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Contained fields'),
|
||||
'#options' => $field_options,
|
||||
'#default_value' => drupal_map_assoc($field['fields']),
|
||||
'#attributes' => array('class' => array('search-api-alter-add-aggregation-fields')),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
));
|
||||
$form['fields'][$name]['actions'] = array(
|
||||
'#type' => 'actions',
|
||||
'remove' => array(
|
||||
|
@@ -1,7 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Search API data alteration callback that adds an URL field for all items.
|
||||
* @file
|
||||
* Contains SearchApiAlterAddHierarchy.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds all ancestors for hierarchical fields.
|
||||
*/
|
||||
class SearchApiAlterAddHierarchy extends SearchApiAbstractAlterCallback {
|
||||
|
||||
@@ -15,24 +20,16 @@ class SearchApiAlterAddHierarchy extends SearchApiAbstractAlterCallback {
|
||||
protected $field_options;
|
||||
|
||||
/**
|
||||
* Enable this data alteration only if any hierarchical fields are available.
|
||||
* Overrides SearchApiAbstractAlterCallback::supportsIndex().
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index to check for.
|
||||
*
|
||||
* @return boolean
|
||||
* TRUE if the callback can run on the given index; FALSE otherwise.
|
||||
* Returns TRUE only if any hierarchical fields are available.
|
||||
*/
|
||||
public function supportsIndex(SearchApiIndex $index) {
|
||||
return (bool) $this->getHierarchicalFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form for configuring this callback.
|
||||
*
|
||||
* @return array
|
||||
* A form array for configuring this callback, or FALSE if no configuration
|
||||
* is possible.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configurationForm() {
|
||||
$options = $this->getHierarchicalFields();
|
||||
@@ -54,19 +51,7 @@ class SearchApiAlterAddHierarchy extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback for the form returned by configurationForm().
|
||||
*
|
||||
* This method should both return the new options and set them internally.
|
||||
*
|
||||
* @param array $form
|
||||
* The form returned by configurationForm().
|
||||
* @param array $values
|
||||
* The part of the $form_state['values'] array corresponding to this form.
|
||||
* @param array $form_state
|
||||
* The complete form state.
|
||||
*
|
||||
* @return array
|
||||
* The new options array for this callback.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configurationFormSubmit(array $form, array &$values, array &$form_state) {
|
||||
// Change the saved type of fields in the index, if necessary.
|
||||
@@ -74,7 +59,7 @@ class SearchApiAlterAddHierarchy extends SearchApiAbstractAlterCallback {
|
||||
$fields = &$this->index->options['fields'];
|
||||
$previous = drupal_map_assoc($this->options['fields']);
|
||||
foreach ($values['fields'] as $field) {
|
||||
list($key, $prop) = explode(':', $field);
|
||||
list($key) = explode(':', $field);
|
||||
if (empty($previous[$field]) && isset($fields[$key]['type'])) {
|
||||
$fields[$key]['type'] = 'list<' . search_api_extract_inner_type($fields[$key]['type']) . '>';
|
||||
$change = TRUE;
|
||||
@@ -82,7 +67,7 @@ class SearchApiAlterAddHierarchy extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
$new = drupal_map_assoc($values['fields']);
|
||||
foreach ($previous as $field) {
|
||||
list($key, $prop) = explode(':', $field);
|
||||
list($key) = explode(':', $field);
|
||||
if (empty($new[$field]) && isset($fields[$key]['type'])) {
|
||||
$w = $this->index->entityWrapper(NULL, FALSE);
|
||||
if (isset($w->$key)) {
|
||||
@@ -102,19 +87,11 @@ class SearchApiAlterAddHierarchy extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter items before indexing.
|
||||
*
|
||||
* Items which are removed from the array won't be indexed, but will be marked
|
||||
* as clean for future indexing. This could for instance be used to implement
|
||||
* some sort of access filter for security purposes (e.g., don't index
|
||||
* unpublished nodes or comments).
|
||||
*
|
||||
* @param array $items
|
||||
* An array of items to be altered, keyed by item IDs.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterItems(array &$items) {
|
||||
if (empty($this->options['fields'])) {
|
||||
return array();
|
||||
return;
|
||||
}
|
||||
foreach ($items as $item) {
|
||||
$wrapper = $this->index->entityWrapper($item, FALSE);
|
||||
@@ -137,16 +114,7 @@ class SearchApiAlterAddHierarchy extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare the properties that are (or can be) added to items with this
|
||||
* callback. If a property with this name already exists for an entity it
|
||||
* will be overridden, so keep a clear namespace by prefixing the properties
|
||||
* with the module name if this is not desired.
|
||||
*
|
||||
* @see hook_entity_property_info()
|
||||
*
|
||||
* @return array
|
||||
* Information about all additional properties, as specified by
|
||||
* hook_entity_property_info() (only the inner "properties" array).
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function propertyInfo() {
|
||||
if (empty($this->options['fields'])) {
|
||||
@@ -188,7 +156,7 @@ class SearchApiAlterAddHierarchy extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for finding all hierarchical fields of an index's type.
|
||||
* Finds all hierarchical fields for the current index.
|
||||
*
|
||||
* @return array
|
||||
* An array containing all hierarchical fields of the index, structured as
|
||||
|
@@ -1,12 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiAlterAddUrl.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Search API data alteration callback that adds an URL field for all items.
|
||||
*/
|
||||
class SearchApiAlterAddUrl extends SearchApiAbstractAlterCallback {
|
||||
|
||||
public function alterItems(array &$items) {
|
||||
foreach ($items as $id => &$item) {
|
||||
foreach ($items as &$item) {
|
||||
$url = $this->index->datasource()->getItemUrl($item);
|
||||
if (!$url) {
|
||||
$item->search_api_url = NULL;
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiAlterAddViewedEntity.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Search API data alteration callback that adds an URL field for all items.
|
||||
*/
|
||||
@@ -64,7 +69,7 @@ class SearchApiAlterAddViewedEntity extends SearchApiAbstractAlterCallback {
|
||||
|
||||
$type = $this->index->getEntityType();
|
||||
$mode = empty($this->options['mode']) ? 'full' : $this->options['mode'];
|
||||
foreach ($items as $id => &$item) {
|
||||
foreach ($items as &$item) {
|
||||
// Since we can't really know what happens in entity_view() and render(),
|
||||
// we use try/catch. This will at least prevent some errors, even though
|
||||
// it's no protection against fatal errors and the like.
|
||||
|
@@ -1,15 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Search API data alteration callback that filters out items based on their
|
||||
* bundle.
|
||||
* @file
|
||||
* Contains SearchApiAlterBundleFilter.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a data alteration that restricts entity indexes to some bundles.
|
||||
*/
|
||||
class SearchApiAlterBundleFilter extends SearchApiAbstractAlterCallback {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsIndex(SearchApiIndex $index) {
|
||||
return $index->getEntityType() && ($info = entity_get_info($index->getEntityType())) && self::hasBundles($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterItems(array &$items) {
|
||||
$info = entity_get_info($this->index->getEntityType());
|
||||
if (self::hasBundles($info) && isset($this->options['bundles'])) {
|
||||
@@ -24,6 +34,9 @@ class SearchApiAlterBundleFilter extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configurationForm() {
|
||||
$info = entity_get_info($this->index->getEntityType());
|
||||
if (self::hasBundles($info)) {
|
||||
@@ -62,8 +75,13 @@ class SearchApiAlterBundleFilter extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for figuring out if the entities with the given entity info
|
||||
* can be filtered by bundle.
|
||||
* Determines whether a certain entity type has any bundles.
|
||||
*
|
||||
* @param array $entity_info
|
||||
* The entity type's entity_get_info() array.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the entity type has bundles, FASLE otherwise.
|
||||
*/
|
||||
protected static function hasBundles(array $entity_info) {
|
||||
return !empty($entity_info['entity keys']['bundle']) && !empty($entity_info['bundles']);
|
||||
|
46
includes/callback_comment_access.inc
Normal file
46
includes/callback_comment_access.inc
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains the SearchApiAlterCommentAccess class.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds node access information to comment indexes.
|
||||
*/
|
||||
class SearchApiAlterCommentAccess extends SearchApiAlterNodeAccess {
|
||||
|
||||
/**
|
||||
* Overrides SearchApiAlterNodeAccess::supportsIndex().
|
||||
*
|
||||
* Returns TRUE only for indexes on comments.
|
||||
*/
|
||||
public function supportsIndex(SearchApiIndex $index) {
|
||||
return $index->getEntityType() === 'comment';
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides SearchApiAlterNodeAccess::getNode().
|
||||
*
|
||||
* Returns the comment's node, instead of the item (i.e., the comment) itself.
|
||||
*/
|
||||
protected function getNode($item) {
|
||||
return node_load($item->nid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides SearchApiAlterNodeAccess::configurationFormSubmit().
|
||||
*
|
||||
* Doesn't index the comment's "Author".
|
||||
*/
|
||||
public function configurationFormSubmit(array $form, array &$values, array &$form_state) {
|
||||
$old_status = !empty($form_state['index']->options['data_alter_callbacks']['search_api_alter_comment_access']['status']);
|
||||
$new_status = !empty($form_state['values']['callbacks']['search_api_alter_comment_access']['status']);
|
||||
|
||||
if (!$old_status && $new_status) {
|
||||
$form_state['index']->options['fields']['status']['type'] = 'boolean';
|
||||
}
|
||||
|
||||
return parent::configurationFormSubmit($form, $values, $form_state);
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiAlterLanguageControl.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Search API data alteration callback that filters out items based on their
|
||||
* bundle.
|
||||
@@ -7,12 +12,7 @@
|
||||
class SearchApiAlterLanguageControl extends SearchApiAbstractAlterCallback {
|
||||
|
||||
/**
|
||||
* Construct a data-alter callback.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index whose items will be altered.
|
||||
* @param array $options
|
||||
* The callback options set for this index.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(SearchApiIndex $index, array $options = array()) {
|
||||
$options += array(
|
||||
@@ -23,16 +23,10 @@ class SearchApiAlterLanguageControl extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this data-alter callback is applicable for a certain index.
|
||||
* Overrides SearchApiAbstractAlterCallback::supportsIndex().
|
||||
*
|
||||
* Only returns TRUE if the system is multilingual.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index to check for.
|
||||
*
|
||||
* @return boolean
|
||||
* TRUE if the callback can run on the given index; FALSE otherwise.
|
||||
*
|
||||
* @see drupal_multilingual()
|
||||
*/
|
||||
public function supportsIndex(SearchApiIndex $index) {
|
||||
@@ -40,10 +34,7 @@ class SearchApiAlterLanguageControl extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form for configuring this data alteration.
|
||||
*
|
||||
* @return array
|
||||
* A form array for configuring this data alteration.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configurationForm() {
|
||||
$form = array();
|
||||
@@ -98,19 +89,7 @@ class SearchApiAlterLanguageControl extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback for the form returned by configurationForm().
|
||||
*
|
||||
* This method should both return the new options and set them internally.
|
||||
*
|
||||
* @param array $form
|
||||
* The form returned by configurationForm().
|
||||
* @param array $values
|
||||
* The part of the $form_state['values'] array corresponding to this form.
|
||||
* @param array $form_state
|
||||
* The complete form state.
|
||||
*
|
||||
* @return array
|
||||
* The new options array for this callback.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configurationFormSubmit(array $form, array &$values, array &$form_state) {
|
||||
$values['languages'] = array_filter($values['languages']);
|
||||
@@ -118,15 +97,7 @@ class SearchApiAlterLanguageControl extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter items before indexing.
|
||||
*
|
||||
* Items which are removed from the array won't be indexed, but will be marked
|
||||
* as clean for future indexing. This could for instance be used to implement
|
||||
* some sort of access filter for security purposes (e.g., don't index
|
||||
* unpublished nodes or comments).
|
||||
*
|
||||
* @param array $items
|
||||
* An array of items to be altered, keyed by item IDs.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterItems(array &$items) {
|
||||
foreach ($items as $i => &$item) {
|
||||
|
@@ -10,15 +10,9 @@
|
||||
class SearchApiAlterNodeAccess extends SearchApiAbstractAlterCallback {
|
||||
|
||||
/**
|
||||
* Check whether this data-alter callback is applicable for a certain index.
|
||||
* Overrides SearchApiAbstractAlterCallback::supportsIndex().
|
||||
*
|
||||
* Returns TRUE only for indexes on nodes.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index to check for.
|
||||
*
|
||||
* @return boolean
|
||||
* TRUE if the callback can run on the given index; FALSE otherwise.
|
||||
*/
|
||||
public function supportsIndex(SearchApiIndex $index) {
|
||||
// Currently only node access is supported.
|
||||
@@ -26,15 +20,9 @@ class SearchApiAlterNodeAccess extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare the properties that are (or can be) added to items with this callback.
|
||||
* Overrides SearchApiAbstractAlterCallback::propertyInfo().
|
||||
*
|
||||
* Adds the "search_api_access_node" property.
|
||||
*
|
||||
* @see hook_entity_property_info()
|
||||
*
|
||||
* @return array
|
||||
* Information about all additional properties, as specified by
|
||||
* hook_entity_property_info() (only the inner "properties" array).
|
||||
*/
|
||||
public function propertyInfo() {
|
||||
return array(
|
||||
@@ -47,15 +35,7 @@ class SearchApiAlterNodeAccess extends SearchApiAbstractAlterCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter items before indexing.
|
||||
*
|
||||
* Items which are removed from the array won't be indexed, but will be marked
|
||||
* as clean for future indexing. This could for instance be used to implement
|
||||
* some sort of access filter for security purposes (e.g., don't index
|
||||
* unpublished nodes or comments).
|
||||
*
|
||||
* @param array $items
|
||||
* An array of items to be altered, keyed by item IDs.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterItems(array &$items) {
|
||||
static $account;
|
||||
@@ -65,30 +45,39 @@ class SearchApiAlterNodeAccess extends SearchApiAbstractAlterCallback {
|
||||
$account = drupal_anonymous_user();
|
||||
}
|
||||
|
||||
foreach ($items as $nid => &$item) {
|
||||
foreach ($items as $id => $item) {
|
||||
$node = $this->getNode($item);
|
||||
// Check whether all users have access to the node.
|
||||
if (!node_access('view', $item, $account)) {
|
||||
if (!node_access('view', $node, $account)) {
|
||||
// Get node access grants.
|
||||
$result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = :nid) AND grant_view = 1', array(':nid' => $item->nid));
|
||||
$result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = :nid) AND grant_view = 1', array(':nid' => $node->nid));
|
||||
|
||||
// Store all grants together with it's realms in the item.
|
||||
// Store all grants together with their realms in the item.
|
||||
foreach ($result as $grant) {
|
||||
if (!isset($items[$nid]->search_api_access_node)) {
|
||||
$items[$nid]->search_api_access_node = array();
|
||||
}
|
||||
$items[$nid]->search_api_access_node[] = "node_access_$grant->realm:$grant->gid";
|
||||
$items[$id]->search_api_access_node[] = "node_access_{$grant->realm}:{$grant->gid}";
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Add the generic view grant if we are not using node access or the
|
||||
// node is viewable by anonymous users.
|
||||
$items[$nid]->search_api_access_node = array('node_access__all');
|
||||
$items[$id]->search_api_access_node = array('node_access__all');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback for the configuration form.
|
||||
* Retrieves the node related to a search item.
|
||||
*
|
||||
* In the default implementation for nodes, the item is already the node.
|
||||
* Subclasses may override this to easily provide node access checks for
|
||||
* items related to nodes.
|
||||
*/
|
||||
protected function getNode($item) {
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides SearchApiAbstractAlterCallback::configurationFormSubmit().
|
||||
*
|
||||
* If the data alteration is being enabled, set "Published" and "Author" to
|
||||
* "indexed", because both are needed for the node access filter.
|
||||
|
@@ -18,46 +18,49 @@
|
||||
* aware that indexes' numerical IDs can change due to feature reverts. It is
|
||||
* therefore recommended to use search_api_index_update_datasource(), or similar
|
||||
* code, in a hook_search_api_index_update() implementation.
|
||||
*
|
||||
* All methods of the data source may throw exceptions of type
|
||||
* SearchApiDataSourceException if any exception or error state is encountered.
|
||||
*/
|
||||
interface SearchApiDataSourceControllerInterface {
|
||||
|
||||
/**
|
||||
* Constructor for a data source controller.
|
||||
* Constructs a new data source controller.
|
||||
*
|
||||
* @param $type
|
||||
* @param string $type
|
||||
* The item type for which this controller is created.
|
||||
*/
|
||||
public function __construct($type);
|
||||
|
||||
/**
|
||||
* Return information on the ID field for this controller's type.
|
||||
* Returns information on the ID field for this controller's type.
|
||||
*
|
||||
* @return array
|
||||
* An associative array containing the following keys:
|
||||
* - key: The property key for the ID field, as used in the item wrapper.
|
||||
* - type: The type of the ID field. Has to be one of the types from
|
||||
* search_api_field_types(). List types ("list<*>") are not allowed.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function getIdFieldInfo();
|
||||
|
||||
/**
|
||||
* Load items of the type of this data source controller.
|
||||
* Loads items of the type of this data source controller.
|
||||
*
|
||||
* @param array $ids
|
||||
* The IDs of the items to laod.
|
||||
*
|
||||
* @return array
|
||||
* The loaded items, keyed by ID.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function loadItems(array $ids);
|
||||
|
||||
/**
|
||||
* Get a metadata wrapper for the item type of this data source controller.
|
||||
* Creates a metadata wrapper for this datasource controller's type.
|
||||
*
|
||||
* @param $item
|
||||
* @param mixed $item
|
||||
* Unless NULL, an item of the item type for this controller to be wrapped.
|
||||
* @param array $info
|
||||
* Optionally, additional information that should be used for creating the
|
||||
@@ -67,151 +70,170 @@ interface SearchApiDataSourceControllerInterface {
|
||||
* A wrapper for the item type of this data source controller, according to
|
||||
* the info array, and optionally loaded with the given data.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*
|
||||
* @see entity_metadata_wrapper()
|
||||
*/
|
||||
public function getMetadataWrapper($item = NULL, array $info = array());
|
||||
|
||||
/**
|
||||
* Get the unique ID of an item.
|
||||
* Retrieves the unique ID of an item.
|
||||
*
|
||||
* @param $item
|
||||
* @param mixed $item
|
||||
* An item of this controller's type.
|
||||
*
|
||||
* @return
|
||||
* @return mixed
|
||||
* Either the unique ID of the item, or NULL if none is available.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function getItemId($item);
|
||||
|
||||
/**
|
||||
* Get a human-readable label for an item.
|
||||
* Retrieves a human-readable label for an item.
|
||||
*
|
||||
* @param $item
|
||||
* @param mixed $item
|
||||
* An item of this controller's type.
|
||||
*
|
||||
* @return
|
||||
* @return string|null
|
||||
* Either a human-readable label for the item, or NULL if none is available.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function getItemLabel($item);
|
||||
|
||||
/**
|
||||
* Get a URL at which the item can be viewed on the web.
|
||||
* Retrieves a URL at which the item can be viewed on the web.
|
||||
*
|
||||
* @param $item
|
||||
* @param mixed $item
|
||||
* An item of this controller's type.
|
||||
*
|
||||
* @return
|
||||
* @return array|null
|
||||
* Either an array containing the 'path' and 'options' keys used to build
|
||||
* the URL of the item, and matching the signature of url(), or NULL if the
|
||||
* item has no URL of its own.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function getItemUrl($item);
|
||||
|
||||
/**
|
||||
* Initialize tracking of the index status of items for the given indexes.
|
||||
* Initializes tracking of the index status of items for the given indexes.
|
||||
*
|
||||
* All currently known items of this data source's type should be inserted
|
||||
* into the tracking table for the given indexes, with status "changed". If
|
||||
* items were already present, these should also be set to "changed" and not
|
||||
* be inserted again.
|
||||
*
|
||||
* @param array $indexes
|
||||
* @param SearchApiIndex[] $indexes
|
||||
* The SearchApiIndex objects for which item tracking should be initialized.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function startTracking(array $indexes);
|
||||
|
||||
/**
|
||||
* Stop tracking of the index status of items for the given indexes.
|
||||
* Stops tracking of the index status of items for the given indexes.
|
||||
*
|
||||
* The tracking tables of the given indexes should be completely cleared.
|
||||
*
|
||||
* @param array $indexes
|
||||
* @param SearchApiIndex[] $indexes
|
||||
* The SearchApiIndex objects for which item tracking should be stopped.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function stopTracking(array $indexes);
|
||||
|
||||
/**
|
||||
* Start tracking the index status for the given items on the given indexes.
|
||||
* Starts tracking the index status for the given items on the given indexes.
|
||||
*
|
||||
* @param array $item_ids
|
||||
* The IDs of new items to track.
|
||||
* @param array $indexes
|
||||
* @param SearchApiIndex[] $indexes
|
||||
* The indexes for which items should be tracked.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function trackItemInsert(array $item_ids, array $indexes);
|
||||
|
||||
/**
|
||||
* Set the tracking status of the given items to "changed"/"dirty".
|
||||
* Sets the tracking status of the given items to "changed"/"dirty".
|
||||
*
|
||||
* Unless $dequeue is set to TRUE, this operation is ignored for items whose
|
||||
* status is not "indexed".
|
||||
*
|
||||
* @param $item_ids
|
||||
* @param array|false $item_ids
|
||||
* Either an array with the IDs of the changed items. Or FALSE to mark all
|
||||
* items as changed for the given indexes.
|
||||
* @param array $indexes
|
||||
* @param SearchApiIndex[] $indexes
|
||||
* The indexes for which the change should be tracked.
|
||||
* @param $dequeue
|
||||
* If set to TRUE, also change the status of queued items.
|
||||
* @param bool $dequeue
|
||||
* (deprecated) If set to TRUE, also change the status of queued items.
|
||||
* The concept of queued items will be removed in the Drupal 8 version of
|
||||
* this module.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function trackItemChange($item_ids, array $indexes, $dequeue = FALSE);
|
||||
|
||||
/**
|
||||
* Set the tracking status of the given items to "queued".
|
||||
* Sets the tracking status of the given items to "queued".
|
||||
*
|
||||
* Queued items are not marked as "dirty" even when they are changed, and they
|
||||
* are not returned by the getChangedItems() method.
|
||||
*
|
||||
* @param $item_ids
|
||||
* @param array|false $item_ids
|
||||
* Either an array with the IDs of the queued items. Or FALSE to mark all
|
||||
* items as queued for the given indexes.
|
||||
* @param SearchApiIndex $index
|
||||
* The index for which the items were queued.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* If any error state was encountered.
|
||||
*
|
||||
* @deprecated
|
||||
* As of Search API 1.10, the cron queue is not used for indexing anymore,
|
||||
* therefore this method has become useless. It will be removed in the
|
||||
* Drupal 8 version of this module.
|
||||
*/
|
||||
public function trackItemQueued($item_ids, SearchApiIndex $index);
|
||||
|
||||
/**
|
||||
* Set the tracking status of the given items to "indexed".
|
||||
* Sets the tracking status of the given items to "indexed".
|
||||
*
|
||||
* @param array $item_ids
|
||||
* The IDs of the indexed items.
|
||||
* @param SearchApiIndex $indexes
|
||||
* @param SearchApiIndex $index
|
||||
* The index on which the items were indexed.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If the index doesn't use the same item type as this controller.
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function trackItemIndexed(array $item_ids, SearchApiIndex $index);
|
||||
|
||||
/**
|
||||
* Stop tracking the index status for the given items on the given indexes.
|
||||
* Stops tracking the index status for the given items on the given indexes.
|
||||
*
|
||||
* @param array $item_ids
|
||||
* The IDs of the removed items.
|
||||
* @param array $indexes
|
||||
* @param SearchApiIndex[] $indexes
|
||||
* The indexes for which the deletions should be tracked.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function trackItemDelete(array $item_ids, array $indexes);
|
||||
|
||||
/**
|
||||
* Get a list of items that need to be indexed.
|
||||
* Retrieves a list of items that need to be indexed.
|
||||
*
|
||||
* If possible, completely unindexed items should be returned before items
|
||||
* that were indexed but later changed. Also, items that were changed longer
|
||||
@@ -219,16 +241,19 @@ interface SearchApiDataSourceControllerInterface {
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index for which changed items should be returned.
|
||||
* @param $limit
|
||||
* @param int $limit
|
||||
* The maximum number of items to return. Negative values mean "unlimited".
|
||||
*
|
||||
* @return array
|
||||
* The IDs of items that need to be indexed for the given index.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function getChangedItems(SearchApiIndex $index, $limit = -1);
|
||||
|
||||
/**
|
||||
* Get information on how many items have been indexed for a certain index.
|
||||
* Retrieves information on how many items have been indexed for a certain index.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index whose index status should be returned.
|
||||
@@ -240,22 +265,26 @@ interface SearchApiDataSourceControllerInterface {
|
||||
* index.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If the index doesn't use the same item type as this controller.
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function getIndexStatus(SearchApiIndex $index);
|
||||
|
||||
/**
|
||||
* Get the entity type of items from this datasource.
|
||||
* Retrieves the entity type of items from this datasource.
|
||||
*
|
||||
* @return string|null
|
||||
* An entity type string if the items provided by this datasource are
|
||||
* entities; NULL otherwise.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
public function getEntityType();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Default base class for the SearchApiDataSourceControllerInterface.
|
||||
* Provides a default base class for datasource controllers.
|
||||
*
|
||||
* Contains default implementations for a number of methods which will be
|
||||
* similar for most data sources. Concrete data sources can decide to extend
|
||||
@@ -330,10 +359,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
protected $changedColumn = 'changed';
|
||||
|
||||
/**
|
||||
* Constructor for a data source controller.
|
||||
*
|
||||
* @param $type
|
||||
* The item type for which this controller is created.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($type) {
|
||||
$this->type = $type;
|
||||
@@ -345,30 +371,14 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity type of items from this datasource.
|
||||
*
|
||||
* @return string|null
|
||||
* An entity type string if the items provided by this datasource are
|
||||
* entities; NULL otherwise.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEntityType() {
|
||||
return $this->entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a metadata wrapper for the item type of this data source controller.
|
||||
*
|
||||
* @param $item
|
||||
* Unless NULL, an item of the item type for this controller to be wrapped.
|
||||
* @param array $info
|
||||
* Optionally, additional information that should be used for creating the
|
||||
* wrapper. Uses the same format as entity_metadata_wrapper().
|
||||
*
|
||||
* @return EntityMetadataWrapper
|
||||
* A wrapper for the item type of this data source controller, according to
|
||||
* the info array, and optionally loaded with the given data.
|
||||
*
|
||||
* @see entity_metadata_wrapper()
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadataWrapper($item = NULL, array $info = array()) {
|
||||
$info += $this->getPropertyInfo();
|
||||
@@ -376,7 +386,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property info for this item type.
|
||||
* Retrieves the property info for this item type.
|
||||
*
|
||||
* This is a helper method for getMetadataWrapper() that can be used by
|
||||
* subclasses to specify the property information to use when creating a
|
||||
@@ -384,7 +394,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
*
|
||||
* The data structure uses largely the format specified in
|
||||
* hook_entity_property_info(). However, the first level of keys (containing
|
||||
* the entity types) is omitted, and the "property" key is called
|
||||
* the entity types) is omitted, and the "properties" key is called
|
||||
* "property info" instead. So, an example return value would look like this:
|
||||
*
|
||||
* @code
|
||||
@@ -413,6 +423,9 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
* @return array
|
||||
* Property information as specified by entity_metadata_wrapper().
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*
|
||||
* @see getMetadataWrapper()
|
||||
* @see hook_entity_property_info()
|
||||
*/
|
||||
@@ -425,13 +438,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique ID of an item.
|
||||
*
|
||||
* @param $item
|
||||
* An item of this controller's type.
|
||||
*
|
||||
* @return
|
||||
* Either the unique ID of the item, or NULL if none is available.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getItemId($item) {
|
||||
$id_info = $this->getIdFieldInfo();
|
||||
@@ -445,13 +452,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a human-readable label for an item.
|
||||
*
|
||||
* @param $item
|
||||
* An item of this controller's type.
|
||||
*
|
||||
* @return
|
||||
* Either a human-readable label for the item, or NULL if none is available.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getItemLabel($item) {
|
||||
$label = $this->getMetadataWrapper($item)->label();
|
||||
@@ -459,33 +460,14 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a URL at which the item can be viewed on the web.
|
||||
*
|
||||
* @param $item
|
||||
* An item of this controller's type.
|
||||
*
|
||||
* @return
|
||||
* Either an array containing the 'path' and 'options' keys used to build
|
||||
* the URL of the item, and matching the signature of url(), or NULL if the
|
||||
* item has no URL of its own.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getItemUrl($item) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize tracking of the index status of items for the given indexes.
|
||||
*
|
||||
* All currently known items of this data source's type should be inserted
|
||||
* into the tracking table for the given indexes, with status "changed". If
|
||||
* items were already present, these should also be set to "changed" and not
|
||||
* be inserted again.
|
||||
*
|
||||
* @param array $indexes
|
||||
* The SearchApiIndex objects for which item tracking should be initialized.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function startTracking(array $indexes) {
|
||||
if (!$this->table) {
|
||||
@@ -499,27 +481,23 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that can be used by subclasses instead of implementing startTracking().
|
||||
*
|
||||
* Returns the IDs of all items that are known for this controller's type.
|
||||
*
|
||||
* Helper method that can be used by subclasses instead of implementing
|
||||
* startTracking().
|
||||
*
|
||||
* @return array
|
||||
* An array containing all item IDs for this type.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any error state was encountered.
|
||||
*/
|
||||
protected function getAllItemIds() {
|
||||
throw new SearchApiDataSourceException(t('Items not known for type @type.', array('@type' => $this->type)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop tracking of the index status of items for the given indexes.
|
||||
*
|
||||
* The tracking tables of the given indexes should be completely cleared.
|
||||
*
|
||||
* @param array $indexes
|
||||
* The SearchApiIndex objects for which item tracking should be stopped.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function stopTracking(array $indexes) {
|
||||
if (!$this->table) {
|
||||
@@ -529,22 +507,14 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
// will mostly be called with only one index.
|
||||
foreach ($indexes as $index) {
|
||||
$this->checkIndex($index);
|
||||
$query = db_delete($this->table)
|
||||
db_delete($this->table)
|
||||
->condition($this->indexIdColumn, $index->id)
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start tracking the index status for the given items on the given indexes.
|
||||
*
|
||||
* @param array $item_ids
|
||||
* The IDs of new items to track.
|
||||
* @param array $indexes
|
||||
* The indexes for which items should be tracked.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function trackItemInsert(array $item_ids, array $indexes) {
|
||||
if (!$this->table) {
|
||||
@@ -571,21 +541,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tracking status of the given items to "changed"/"dirty".
|
||||
*
|
||||
* Unless $dequeue is set to TRUE, this operation is ignored for items whose
|
||||
* status is not "indexed".
|
||||
*
|
||||
* @param $item_ids
|
||||
* Either an array with the IDs of the changed items. Or FALSE to mark all
|
||||
* items as changed for the given indexes.
|
||||
* @param array $indexes
|
||||
* The indexes for which the change should be tracked.
|
||||
* @param $dequeue
|
||||
* If set to TRUE, also change the status of queued items.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function trackItemChange($item_ids, array $indexes, $dequeue = FALSE) {
|
||||
if (!$this->table) {
|
||||
@@ -609,21 +565,10 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tracking status of the given items to "queued".
|
||||
*
|
||||
* Queued items are not marked as "dirty" even when they are changed, and they
|
||||
* are not returned by the getChangedItems() method.
|
||||
*
|
||||
* @param $item_ids
|
||||
* Either an array with the IDs of the queued items. Or FALSE to mark all
|
||||
* items as queued for the given indexes.
|
||||
* @param SearchApiIndex $index
|
||||
* The index for which the items were queued.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function trackItemQueued($item_ids, SearchApiIndex $index) {
|
||||
$this->checkIndex($index);
|
||||
if (!$this->table) {
|
||||
return;
|
||||
}
|
||||
@@ -639,15 +584,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tracking status of the given items to "indexed".
|
||||
*
|
||||
* @param array $item_ids
|
||||
* The IDs of the indexed items.
|
||||
* @param SearchApiIndex $indexes
|
||||
* The index on which the items were indexed.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If the index doesn't use the same item type as this controller.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function trackItemIndexed(array $item_ids, SearchApiIndex $index) {
|
||||
if (!$this->table) {
|
||||
@@ -664,15 +601,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop tracking the index status for the given items on the given indexes.
|
||||
*
|
||||
* @param array $item_ids
|
||||
* The IDs of the removed items.
|
||||
* @param array $indexes
|
||||
* The indexes for which the deletions should be tracked.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function trackItemDelete(array $item_ids, array $indexes) {
|
||||
if (!$this->table) {
|
||||
@@ -690,19 +619,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of items that need to be indexed.
|
||||
*
|
||||
* If possible, completely unindexed items should be returned before items
|
||||
* that were indexed but later changed. Also, items that were changed longer
|
||||
* ago should be favored.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index for which changed items should be returned.
|
||||
* @param $limit
|
||||
* The maximum number of items to return. Negative values mean "unlimited".
|
||||
*
|
||||
* @return array
|
||||
* The IDs of items that need to be indexed for the given index.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChangedItems(SearchApiIndex $index, $limit = -1) {
|
||||
if ($limit == 0) {
|
||||
@@ -721,16 +638,7 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information on how many items have been indexed for a certain index.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index whose index status should be returned.
|
||||
*
|
||||
* @return array
|
||||
* An associative array containing two keys (in this order):
|
||||
* - indexed: The number of items already indexed in their latest version.
|
||||
* - total: The total number of items that have to be indexed for this
|
||||
* index.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIndexStatus(SearchApiIndex $index) {
|
||||
if (!$this->table) {
|
||||
@@ -752,13 +660,16 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for ensuring that an index uses the same item type as this controller.
|
||||
* Checks whether the given index is valid for this datasource controller.
|
||||
*
|
||||
* Helper method used by various methods in this class. By default only checks
|
||||
* whether the types match.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index to check.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If the index doesn't use the same type as this controller.
|
||||
* If the index doesn't fit to this datasource controller.
|
||||
*/
|
||||
protected function checkIndex(SearchApiIndex $index) {
|
||||
if ($index->item_type != $this->type) {
|
||||
|
@@ -6,18 +6,12 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data source for all entities known to the Entity API.
|
||||
* Represents a datasource for all entities known to the Entity API.
|
||||
*/
|
||||
class SearchApiEntityDataSourceController extends SearchApiAbstractDataSourceController {
|
||||
|
||||
/**
|
||||
* Return information on the ID field for this controller's type.
|
||||
*
|
||||
* @return array
|
||||
* An associative array containing the following keys:
|
||||
* - key: The property key for the ID field, as used in the item wrapper.
|
||||
* - type: The type of the ID field. Has to be one of the types from
|
||||
* search_api_field_types(). List types ("list<*>") are not allowed.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIdFieldInfo() {
|
||||
$info = entity_get_info($this->entityType);
|
||||
@@ -43,13 +37,7 @@ class SearchApiEntityDataSourceController extends SearchApiAbstractDataSourceCon
|
||||
}
|
||||
|
||||
/**
|
||||
* Load items of the type of this data source controller.
|
||||
*
|
||||
* @param array $ids
|
||||
* The IDs of the items to laod.
|
||||
*
|
||||
* @return array
|
||||
* The loaded items, keyed by ID.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadItems(array $ids) {
|
||||
$items = entity_load($this->entityType, $ids);
|
||||
@@ -65,32 +53,14 @@ class SearchApiEntityDataSourceController extends SearchApiAbstractDataSourceCon
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a metadata wrapper for the item type of this data source controller.
|
||||
*
|
||||
* @param $item
|
||||
* Unless NULL, an item of the item type for this controller to be wrapped.
|
||||
* @param array $info
|
||||
* Optionally, additional information that should be used for creating the
|
||||
* wrapper. Uses the same format as entity_metadata_wrapper().
|
||||
*
|
||||
* @return EntityMetadataWrapper
|
||||
* A wrapper for the item type of this data source controller, according to
|
||||
* the info array, and optionally loaded with the given data.
|
||||
*
|
||||
* @see entity_metadata_wrapper()
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadataWrapper($item = NULL, array $info = array()) {
|
||||
return entity_metadata_wrapper($this->entityType, $item, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique ID of an item.
|
||||
*
|
||||
* @param $item
|
||||
* An item of this controller's type.
|
||||
*
|
||||
* @return
|
||||
* Either the unique ID of the item, or NULL if none is available.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getItemId($item) {
|
||||
$id = entity_id($this->entityType, $item);
|
||||
@@ -98,13 +68,7 @@ class SearchApiEntityDataSourceController extends SearchApiAbstractDataSourceCon
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a human-readable label for an item.
|
||||
*
|
||||
* @param $item
|
||||
* An item of this controller's type.
|
||||
*
|
||||
* @return
|
||||
* Either a human-readable label for the item, or NULL if none is available.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getItemLabel($item) {
|
||||
$label = entity_label($this->entityType, $item);
|
||||
@@ -112,15 +76,7 @@ class SearchApiEntityDataSourceController extends SearchApiAbstractDataSourceCon
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a URL at which the item can be viewed on the web.
|
||||
*
|
||||
* @param $item
|
||||
* An item of this controller's type.
|
||||
*
|
||||
* @return
|
||||
* Either an array containing the 'path' and 'options' keys used to build
|
||||
* the URL of the item, and matching the signature of url(), or NULL if the
|
||||
* item has no URL of its own.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getItemUrl($item) {
|
||||
if ($this->entityType == 'file') {
|
||||
@@ -137,18 +93,7 @@ class SearchApiEntityDataSourceController extends SearchApiAbstractDataSourceCon
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize tracking of the index status of items for the given indexes.
|
||||
*
|
||||
* All currently known items of this data source's type should be inserted
|
||||
* into the tracking table for the given indexes, with status "changed". If
|
||||
* items were already present, these should also be set to "changed" and not
|
||||
* be inserted again.
|
||||
*
|
||||
* @param array $indexes
|
||||
* The SearchApiIndex objects for which item tracking should be initialized.
|
||||
*
|
||||
* @throws SearchApiDataSourceException
|
||||
* If any of the indexes doesn't use the same item type as this controller.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function startTracking(array $indexes) {
|
||||
if (!$this->table) {
|
||||
@@ -190,14 +135,7 @@ class SearchApiEntityDataSourceController extends SearchApiAbstractDataSourceCon
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that can be used by subclasses instead of implementing startTracking().
|
||||
*
|
||||
* Returns the IDs of all items that are known for this controller's type.
|
||||
*
|
||||
* Will be used when the entity type doesn't specify a "base table".
|
||||
*
|
||||
* @return array
|
||||
* An array containing all item IDs for this type.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAllItemIds() {
|
||||
return array_keys(entity_load($this->entityType));
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiException.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents an exception or error that occurred in some part of the Search API
|
||||
* framework.
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiIndex.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing a search index.
|
||||
*/
|
||||
@@ -178,18 +183,9 @@ class SearchApiIndex extends Entity {
|
||||
if ($this->enabled) {
|
||||
$this->queueItems();
|
||||
}
|
||||
$server = $this->server();
|
||||
if ($server) {
|
||||
if ($server = $this->server()) {
|
||||
// Tell the server about the new index.
|
||||
if ($server->enabled) {
|
||||
$server->addIndex($this);
|
||||
}
|
||||
else {
|
||||
$tasks = variable_get('search_api_tasks', array());
|
||||
// When we add or remove an index, we can ignore all other tasks.
|
||||
$tasks[$server->machine_name][$this->machine_name] = array('add');
|
||||
variable_set('search_api_tasks', $tasks);
|
||||
}
|
||||
$server->addIndex($this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,18 +194,7 @@ class SearchApiIndex extends Entity {
|
||||
*/
|
||||
public function postDelete() {
|
||||
if ($server = $this->server()) {
|
||||
if ($server->enabled) {
|
||||
$server->removeIndex($this);
|
||||
}
|
||||
// Once the index is deleted, servers won't be able to tell whether it was
|
||||
// read-only. Therefore, we prefer to err on the safe side and don't call
|
||||
// the server method at all if the index is read-only and the server
|
||||
// currently disabled.
|
||||
elseif (empty($this->read_only)) {
|
||||
$tasks = variable_get('search_api_tasks', array());
|
||||
$tasks[$server->machine_name][$this->machine_name] = array('remove');
|
||||
variable_set('search_api_tasks', $tasks);
|
||||
}
|
||||
$server->removeIndex($this);
|
||||
}
|
||||
|
||||
// Stop tracking entities for indexing.
|
||||
@@ -230,14 +215,14 @@ class SearchApiIndex extends Entity {
|
||||
*/
|
||||
public function dequeueItems() {
|
||||
$this->datasource()->stopTracking(array($this));
|
||||
_search_api_empty_cron_queue($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this index to the database, either creating a new record or updating
|
||||
* an existing one.
|
||||
* Saves this index to the database.
|
||||
*
|
||||
* @return
|
||||
* Either creates a new record or updates the existing one with the same ID.
|
||||
*
|
||||
* @return int|false
|
||||
* Failure to save the index will return FALSE. Otherwise, SAVED_NEW or
|
||||
* SAVED_UPDATED is returned depending on the operation performed. $this->id
|
||||
* will be set if a new index was inserted.
|
||||
@@ -253,6 +238,7 @@ class SearchApiIndex extends Entity {
|
||||
// This will also throw an exception if the server doesn't exist – which is good.
|
||||
elseif (!$this->server(TRUE)->enabled) {
|
||||
$this->enabled = FALSE;
|
||||
$this->server = NULL;
|
||||
}
|
||||
|
||||
return parent::save();
|
||||
@@ -267,7 +253,7 @@ class SearchApiIndex extends Entity {
|
||||
* @param array $fields
|
||||
* The new field values.
|
||||
*
|
||||
* @return
|
||||
* @return int|false
|
||||
* SAVE_UPDATED on success, FALSE on failure, 0 if the fields already had
|
||||
* the specified values.
|
||||
*/
|
||||
@@ -296,7 +282,7 @@ class SearchApiIndex extends Entity {
|
||||
/**
|
||||
* Schedules this search index for re-indexing.
|
||||
*
|
||||
* @return
|
||||
* @return bool
|
||||
* TRUE on success, FALSE on failure.
|
||||
*/
|
||||
public function reindex() {
|
||||
@@ -311,7 +297,7 @@ class SearchApiIndex extends Entity {
|
||||
/**
|
||||
* Clears this search index and schedules all of its items for re-indexing.
|
||||
*
|
||||
* @return
|
||||
* @return bool
|
||||
* TRUE on success, FALSE on failure.
|
||||
*/
|
||||
public function clear() {
|
||||
@@ -319,20 +305,7 @@ class SearchApiIndex extends Entity {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$server = $this->server();
|
||||
if ($server->enabled) {
|
||||
$server->deleteItems('all', $this);
|
||||
}
|
||||
else {
|
||||
$tasks = variable_get('search_api_tasks', array());
|
||||
// If the index was cleared or newly added since the server was last enabled, we don't need to do anything.
|
||||
if (!isset($tasks[$server->machine_name][$this->machine_name])
|
||||
|| (array_search('add', $tasks[$server->machine_name][$this->machine_name]) === FALSE
|
||||
&& array_search('clear', $tasks[$server->machine_name][$this->machine_name]) === FALSE)) {
|
||||
$tasks[$server->machine_name][$this->machine_name][] = 'clear';
|
||||
variable_set('search_api_tasks', $tasks);
|
||||
}
|
||||
}
|
||||
$this->server()->deleteItems('all', $this);
|
||||
|
||||
_search_api_index_reindex($this);
|
||||
module_invoke_all('search_api_index_reindex', $this, TRUE);
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiProcessorInterface and SearchApiAbstractProcessor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface representing a Search API pre- and/or post-processor.
|
||||
*
|
||||
@@ -27,7 +32,7 @@ interface SearchApiProcessorInterface {
|
||||
/**
|
||||
* Check whether this processor is applicable for a certain index.
|
||||
*
|
||||
* This can be used for hiding the processor on the index's "Workflow" tab. To
|
||||
* This can be used for hiding the processor on the index's "Filters" tab. To
|
||||
* avoid confusion, you should only use criteria that are immutable, such as
|
||||
* the index's item type. Also, since this is only used for UI purposes, you
|
||||
* should not completely rely on this to ensure certain index configurations
|
||||
|
@@ -150,8 +150,8 @@ class SearchApiHighlight extends SearchApiAbstractProcessor {
|
||||
/**
|
||||
* Retrieves the fulltext data of a result.
|
||||
*
|
||||
* @param array $result
|
||||
* All results returned in the search.
|
||||
* @param array $results
|
||||
* All results returned in the search, by reference.
|
||||
* @param int|string $i
|
||||
* The index in the results array of the result whose data should be
|
||||
* returned.
|
||||
@@ -164,11 +164,12 @@ class SearchApiHighlight extends SearchApiAbstractProcessor {
|
||||
* contained in them for the given result.
|
||||
*/
|
||||
protected function getFulltextFields(array &$results, $i, $load = TRUE) {
|
||||
global $language;
|
||||
$data = array();
|
||||
// Act as if $load is TRUE if we have a loaded item.
|
||||
$load |= !empty($result['entity']);
|
||||
|
||||
$result = &$results[$i];
|
||||
// Act as if $load is TRUE if we have a loaded item.
|
||||
$load |= !empty($result['entity']);
|
||||
$result += array('fields' => array());
|
||||
$fulltext_fields = $this->index->getFulltextFields();
|
||||
// We only need detailed fields data if $load is TRUE.
|
||||
@@ -198,6 +199,7 @@ class SearchApiHighlight extends SearchApiAbstractProcessor {
|
||||
return $data;
|
||||
}
|
||||
$wrapper = $this->index->entityWrapper($result['entity'], FALSE);
|
||||
$wrapper->language($language->language);
|
||||
$extracted = search_api_extract_fields($wrapper, $needs_extraction);
|
||||
|
||||
foreach ($extracted as $field => $info) {
|
||||
@@ -292,7 +294,6 @@ class SearchApiHighlight extends SearchApiAbstractProcessor {
|
||||
// If the sum of all fragments is too short, we look for second occurrences.
|
||||
$ranges = array();
|
||||
$included = array();
|
||||
$foundkeys = array();
|
||||
$length = 0;
|
||||
$workkeys = $keys;
|
||||
while ($length < $this->options['excerpt_length'] && count($workkeys)) {
|
||||
@@ -394,8 +395,9 @@ class SearchApiHighlight extends SearchApiAbstractProcessor {
|
||||
*/
|
||||
protected function highlightField($text, array $keys) {
|
||||
$replace = $this->options['prefix'] . '\0' . $this->options['suffix'];
|
||||
$text = preg_replace('/' . self::$boundary . '(' . implode('|', $keys) . ')' . self::$boundary . '/iu', $replace, ' ' . $text);
|
||||
return substr($text, 1);
|
||||
$keys = implode('|', array_map('preg_quote', $keys));
|
||||
$text = preg_replace('/' . self::$boundary . '(' . $keys . ')' . self::$boundary . '/iu', $replace, ' ' . $text . ' ');
|
||||
return substr($text, 1, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiHtmlFilter.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Processor for stripping HTML from indexed fulltext data. Supports assigning
|
||||
* custom boosts for any HTML element.
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiIgnoreCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Processor for making searches case-insensitive.
|
||||
*/
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiStopWords.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Processor for removing stopwords from index and search terms.
|
||||
*/
|
||||
@@ -21,8 +26,7 @@ class SearchApiStopWords extends SearchApiAbstractProcessor {
|
||||
),
|
||||
'file' => array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Stopwords file URI'),
|
||||
'#title' => t('Enter the URI of your stopwords.txt file'),
|
||||
'#title' => t('Stopwords file'),
|
||||
'#description' => t('This must be a stream-type description like <code>public://stopwords/stopwords.txt</code> or <code>http://example.com/stopwords.txt</code> or <code>private://stopwords.txt</code>.'),
|
||||
),
|
||||
'stopwords' => array(
|
||||
@@ -43,13 +47,8 @@ class SearchApiStopWords extends SearchApiAbstractProcessor {
|
||||
public function configurationFormValidate(array $form, array &$values, array &$form_state) {
|
||||
parent::configurationFormValidate($form, $values, $form_state);
|
||||
|
||||
$stopwords = trim($values['stopwords']);
|
||||
$uri = $values['file'];
|
||||
if (empty($stopwords) && empty($uri)) {
|
||||
$el = $form['file'];
|
||||
form_error($el, $el['#title'] . ': ' . t('At stopwords file or words are required.'));
|
||||
}
|
||||
if (!empty($uri) && !file_get_contents($uri)) {
|
||||
if (!empty($uri) && !@file_get_contents($uri)) {
|
||||
$el = $form['file'];
|
||||
form_error($el, t('Stopwords file') . ': ' . t('The file %uri is not readable or does not exist.', array('%uri' => $uri)));
|
||||
}
|
||||
@@ -57,7 +56,7 @@ class SearchApiStopWords extends SearchApiAbstractProcessor {
|
||||
|
||||
public function process(&$value) {
|
||||
$stopwords = $this->getStopWords();
|
||||
if (empty($stopwords) && !is_string($value)) {
|
||||
if (empty($stopwords) || !is_string($value)) {
|
||||
return;
|
||||
}
|
||||
$words = preg_split('/\s+/', $value);
|
||||
@@ -105,4 +104,4 @@ class SearchApiStopWords extends SearchApiAbstractProcessor {
|
||||
$this->stopwords = array_flip(array_merge($file_words, $form_words));
|
||||
return $this->stopwords;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiTokenizer.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Processor for tokenizing fulltext data by replacing (configurable)
|
||||
* non-letters with spaces.
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiTransliteration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Processor for making searches insensitive to accents and other non-ASCII characters.
|
||||
*/
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiQueryInterface and SearchApiQuery.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface representing a search query on an Search API index.
|
||||
*
|
||||
@@ -33,6 +38,10 @@ interface SearchApiQueryInterface {
|
||||
* implementation to use.
|
||||
* - 'search id': A string that will be used as the identifier when storing
|
||||
* this search in the Search API's static cache.
|
||||
* - 'skip result count': If present and set to TRUE, the result's
|
||||
* "result count" key will not be needed. Service classes can check for
|
||||
* this option to possibly avoid executing expensive operations to compute
|
||||
* the result count in cases where it is not needed.
|
||||
* - search_api_access_account: The account which will be used for entity
|
||||
* access checks, if available and enabled for the index.
|
||||
* - search_api_bypass_access: If set to TRUE, entity access checks will be
|
||||
@@ -62,11 +71,15 @@ interface SearchApiQueryInterface {
|
||||
*
|
||||
* @param string $conjunction
|
||||
* The conjunction to use for the filter - either 'AND' or 'OR'.
|
||||
* @param $tags
|
||||
* (Optional) An arbitrary set of tags. Can be used to identify this filter
|
||||
* down the line if necessary. This is primarily used by the facet system
|
||||
* to support OR facet queries.
|
||||
*
|
||||
* @return SearchApiQueryFilterInterface
|
||||
* A filter object that is set to use the specified conjunction.
|
||||
*/
|
||||
public function createFilter($conjunction = 'AND');
|
||||
public function createFilter($conjunction = 'AND', $tags = array());
|
||||
|
||||
/**
|
||||
* Sets the keys to search for.
|
||||
@@ -175,7 +188,9 @@ interface SearchApiQueryInterface {
|
||||
* An associative array containing the search results. The following keys
|
||||
* are standardized:
|
||||
* - 'result count': The overall number of results for this query, without
|
||||
* range restrictions. Might be approximated, for large numbers.
|
||||
* range restrictions. Might be approximated, for large numbers, or
|
||||
* skipped entirely if the "skip result count" option was set on this
|
||||
* query.
|
||||
* - results: An array of results, ordered as specified. The array keys are
|
||||
* the items' IDs, values are arrays containing the following keys:
|
||||
* - id: The item's ID.
|
||||
@@ -318,7 +333,8 @@ interface SearchApiQueryInterface {
|
||||
* @param mixed $value
|
||||
* The new value of the option.
|
||||
*
|
||||
* @return The option's previous value.
|
||||
* @return mixed
|
||||
* The option's previous value.
|
||||
*/
|
||||
public function setOption($name, $value);
|
||||
|
||||
@@ -341,12 +357,21 @@ interface SearchApiQueryInterface {
|
||||
class SearchApiQuery implements SearchApiQueryInterface {
|
||||
|
||||
/**
|
||||
* The index.
|
||||
* The index this query will use.
|
||||
*
|
||||
* @var SearchApiIndex
|
||||
*/
|
||||
protected $index;
|
||||
|
||||
/**
|
||||
* The index's machine name.
|
||||
*
|
||||
* used during serialization to avoid serializing the whole index object.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $index_id;
|
||||
|
||||
/**
|
||||
* The search keys. If NULL, this will be a filter-only search.
|
||||
*
|
||||
@@ -503,9 +528,9 @@ class SearchApiQuery implements SearchApiQueryInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createFilter($conjunction = 'AND') {
|
||||
public function createFilter($conjunction = 'AND', $tags = array()) {
|
||||
$filter_class = $this->options['filter class'];
|
||||
return new $filter_class($conjunction);
|
||||
return new $filter_class($conjunction, $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -616,6 +641,9 @@ class SearchApiQuery implements SearchApiQueryInterface {
|
||||
*
|
||||
* @param array $languages
|
||||
* The languages for which results should be returned.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If there was a logical error in the combination of filters and languages.
|
||||
*/
|
||||
protected function addLanguages(array $languages) {
|
||||
if (array_search(LANGUAGE_NONE, $languages) === FALSE) {
|
||||
@@ -776,6 +804,13 @@ class SearchApiQuery implements SearchApiQueryInterface {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the magic __clone() method to clone the filter, too.
|
||||
*/
|
||||
public function __clone() {
|
||||
$this->filter = clone $this->filter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -790,9 +825,13 @@ interface SearchApiQueryFilterInterface {
|
||||
* Constructs a new filter that uses the specified conjunction.
|
||||
*
|
||||
* @param string $conjunction
|
||||
* The conjunction to use for this filter - either 'AND' or 'OR'.
|
||||
* (optional) The conjunction to use for this filter - either 'AND' or 'OR'.
|
||||
* @param array $tags
|
||||
* (optional) An arbitrary set of tags. Can be used to identify this filter
|
||||
* down the line if necessary. This is primarily used by the facet system
|
||||
* to support OR facet queries.
|
||||
*/
|
||||
public function __construct($conjunction = 'AND');
|
||||
public function __construct($conjunction = 'AND', array $tags = array());
|
||||
|
||||
/**
|
||||
* Sets this filter's conjunction.
|
||||
@@ -856,6 +895,25 @@ interface SearchApiQueryFilterInterface {
|
||||
*/
|
||||
public function &getFilters();
|
||||
|
||||
/**
|
||||
* Checks whether a certain tag was set on this filter.
|
||||
*
|
||||
* @param string $tag
|
||||
* A tag to check for.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the tag was set for this filter, FALSE otherwise.
|
||||
*/
|
||||
public function hasTag($tag);
|
||||
|
||||
/**
|
||||
* Retrieves the tags set on this filter.
|
||||
*
|
||||
* @return array
|
||||
* The tags associated with this filter, as both the array keys and values.
|
||||
*/
|
||||
public function &getTags();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -883,9 +941,10 @@ class SearchApiQueryFilter implements SearchApiQueryFilterInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($conjunction = 'AND') {
|
||||
public function __construct($conjunction = 'AND', array $tags = array()) {
|
||||
$this->setConjunction($conjunction);
|
||||
$this->filters = array();
|
||||
$this->tags = drupal_map_assoc($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -926,4 +985,29 @@ class SearchApiQueryFilter implements SearchApiQueryFilterInterface {
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasTag($tag) {
|
||||
return isset($this->tags[$tag]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function &getTags() {
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the magic __clone() method to clone nested filters, too.
|
||||
*/
|
||||
public function __clone() {
|
||||
foreach ($this->filters as $i => $filter) {
|
||||
if (is_object($filter)) {
|
||||
$this->filters[$i] = clone $filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiServer.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing a search server.
|
||||
*
|
||||
@@ -82,7 +87,7 @@ class SearchApiServer extends Entity {
|
||||
* @param array $fields
|
||||
* The new field values.
|
||||
*
|
||||
* @return
|
||||
* @return int|false
|
||||
* SAVE_UPDATED on success, FALSE on failure, 0 if the fields already had
|
||||
* the specified values.
|
||||
*/
|
||||
@@ -136,6 +141,8 @@ class SearchApiServer extends Entity {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to calls of undefined methods on this object.
|
||||
*
|
||||
* If the service class defines additional methods, not specified in the
|
||||
* SearchApiServiceInterface interface, then they are called via this magic
|
||||
* method.
|
||||
@@ -148,81 +155,242 @@ class SearchApiServer extends Entity {
|
||||
// Proxy methods
|
||||
|
||||
// For increased clarity, and since some parameters are passed by reference,
|
||||
// we don't use the __call() magic method for those.
|
||||
// we don't use the __call() magic method for those. This also gives us the
|
||||
// opportunity to do additional error handling.
|
||||
|
||||
/**
|
||||
* Form constructor for the server configuration form.
|
||||
*
|
||||
* @see SearchApiServiceInterface::configurationForm()
|
||||
*/
|
||||
public function configurationForm(array $form, array &$form_state) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->configurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation callback for the form returned by configurationForm().
|
||||
*
|
||||
* @see SearchApiServiceInterface::configurationFormValidate()
|
||||
*/
|
||||
public function configurationFormValidate(array $form, array &$values, array &$form_state) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->configurationFormValidate($form, $values, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback for the form returned by configurationForm().
|
||||
*
|
||||
* @see SearchApiServiceInterface::configurationFormSubmit()
|
||||
*/
|
||||
public function configurationFormSubmit(array $form, array &$values, array &$form_state) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->configurationFormSubmit($form, $values, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this service class supports a given feature.
|
||||
*
|
||||
* @see SearchApiServiceInterface::supportsFeature()
|
||||
*/
|
||||
public function supportsFeature($feature) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->supportsFeature($feature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays this server's settings.
|
||||
*
|
||||
* @see SearchApiServiceInterface::viewSettings()
|
||||
*/
|
||||
public function viewSettings() {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->viewSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to the server's creation.
|
||||
*
|
||||
* @see SearchApiServiceInterface::postCreate()
|
||||
*/
|
||||
public function postCreate() {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->postCreate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies this server that its fields are about to be updated.
|
||||
*
|
||||
* @see SearchApiServiceInterface::postUpdate()
|
||||
*/
|
||||
public function postUpdate() {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->postUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies this server that it is about to be deleted from the database.
|
||||
*
|
||||
* @see SearchApiServiceInterface::preDelete()
|
||||
*/
|
||||
public function preDelete() {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->preDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new index to this server.
|
||||
*
|
||||
* If an exception in the service class implementation of this method occcurs,
|
||||
* it will be caught and the operation saved as an pending server task.
|
||||
*
|
||||
* @see SearchApiServiceInterface::addIndex()
|
||||
* @see search_api_server_tasks_add()
|
||||
*/
|
||||
public function addIndex(SearchApiIndex $index) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->addIndex($index);
|
||||
try {
|
||||
$this->proxy->addIndex($index);
|
||||
}
|
||||
catch (SearchApiException $e) {
|
||||
$vars = array(
|
||||
'%server' => $this->name,
|
||||
'%index' => $index->name,
|
||||
);
|
||||
watchdog_exception('search_api', $e, '%type while adding index %index to server %server: !message in %function (line %line of %file).', $vars);
|
||||
search_api_server_tasks_add($this, __FUNCTION__, $index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the server that the field settings for the index have changed.
|
||||
*
|
||||
* If the service class implementation of the method returns TRUE, this will
|
||||
* automatically take care of marking the items on the index for re-indexing.
|
||||
*
|
||||
* If an exception in the service class implementation of this method occcurs,
|
||||
* it will be caught and the operation saved as an pending server task.
|
||||
*
|
||||
* @see SearchApiServiceInterface::fieldsUpdated()
|
||||
* @see search_api_server_tasks_add()
|
||||
*/
|
||||
public function fieldsUpdated(SearchApiIndex $index) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->fieldsUpdated($index);
|
||||
try {
|
||||
if ($this->proxy->fieldsUpdated($index)) {
|
||||
_search_api_index_reindex($index);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
catch (SearchApiException $e) {
|
||||
$vars = array(
|
||||
'%server' => $this->name,
|
||||
'%index' => $index->name,
|
||||
);
|
||||
watchdog_exception('search_api', $e, '%type while updating the fields of index %index on server %server: !message in %function (line %line of %file).', $vars);
|
||||
search_api_server_tasks_add($this, __FUNCTION__, $index, isset($index->original) ? $index->original : NULL);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an index from this server.
|
||||
*
|
||||
* If an exception in the service class implementation of this method occcurs,
|
||||
* it will be caught and the operation saved as an pending server task.
|
||||
*
|
||||
* @see SearchApiServiceInterface::removeIndex()
|
||||
* @see search_api_server_tasks_add()
|
||||
*/
|
||||
public function removeIndex($index) {
|
||||
// When removing an index from a server, it doesn't make any sense anymore to
|
||||
// delete items from it, or react to other changes.
|
||||
search_api_server_tasks_delete(NULL, $this, $index);
|
||||
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->removeIndex($index);
|
||||
try {
|
||||
$this->proxy->removeIndex($index);
|
||||
}
|
||||
catch (SearchApiException $e) {
|
||||
$vars = array(
|
||||
'%server' => $this->name,
|
||||
'%index' => is_object($index) ? $index->name : $index,
|
||||
);
|
||||
watchdog_exception('search_api', $e, '%type while removing index %index from server %server: !message in %function (line %line of %file).', $vars);
|
||||
search_api_server_tasks_add($this, __FUNCTION__, $index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexes the specified items.
|
||||
*
|
||||
* @see SearchApiServiceInterface::indexItems()
|
||||
*/
|
||||
public function indexItems(SearchApiIndex $index, array $items) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->indexItems($index, $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes indexed items from this server.
|
||||
*
|
||||
* If an exception in the service class implementation of this method occcurs,
|
||||
* it will be caught and the operation saved as an pending server task.
|
||||
*
|
||||
* @see SearchApiServiceInterface::deleteItems()
|
||||
* @see search_api_server_tasks_add()
|
||||
*/
|
||||
public function deleteItems($ids = 'all', SearchApiIndex $index = NULL) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->deleteItems($ids, $index);
|
||||
try {
|
||||
$this->proxy->deleteItems($ids, $index);
|
||||
}
|
||||
catch (SearchApiException $e) {
|
||||
$vars = array(
|
||||
'%server' => $this->name,
|
||||
);
|
||||
watchdog_exception('search_api', $e, '%type while deleting items from server %server: !message in %function (line %line of %file).', $vars);
|
||||
search_api_server_tasks_add($this, __FUNCTION__, $index, $ids);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a query object for searching on an index lying on this server.
|
||||
*
|
||||
* @see SearchApiServiceInterface::query()
|
||||
*/
|
||||
public function query(SearchApiIndex $index, $options = array()) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->query($index, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a search on the server represented by this object.
|
||||
*
|
||||
* @see SearchApiServiceInterface::search()
|
||||
*/
|
||||
public function search(SearchApiQueryInterface $query) {
|
||||
$this->ensureProxy();
|
||||
return $this->proxy->search($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves additional information for the server, if available.
|
||||
*
|
||||
* Retrieving such information is only supported if the service class supports
|
||||
* the "search_api_service_extra" feature.
|
||||
*
|
||||
* @return array
|
||||
* An array containing additional, service class-specific information about
|
||||
* the server.
|
||||
*
|
||||
* @see SearchApiAbstractService::getExtraInformation()
|
||||
*/
|
||||
public function getExtraInformation() {
|
||||
if ($this->proxy->supportsFeature('search_api_service_extra')) {
|
||||
return $this->proxy->getExtraInformation();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,10 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SearchApiServiceInterface and SearchApiAbstractService.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface defining the methods search services have to implement.
|
||||
*
|
||||
* Before a service object is used, the corresponding server's data will be read
|
||||
* from the database (see SearchApiAbstractService for a list of fields).
|
||||
*
|
||||
* Most methods in this interface (where any change in data occurs) can throw a
|
||||
* SearchApiException. The server entity class SearchApiServer catches these
|
||||
* exceptions and uses the server tasks system to assure that the action is
|
||||
* later retried.
|
||||
*/
|
||||
interface SearchApiServiceInterface {
|
||||
|
||||
@@ -19,8 +29,15 @@ interface SearchApiServiceInterface {
|
||||
public function __construct(SearchApiServer $server);
|
||||
|
||||
/**
|
||||
* Form callback. Might be called on an uninitialized object - in this case,
|
||||
* the form is for configuring a newly created server.
|
||||
* Form constructor for the server configuration form.
|
||||
*
|
||||
* Might be called with an incomplete server (no ID). In this case, the form
|
||||
* is displayed for the initial creation of the server.
|
||||
*
|
||||
* @param array $form
|
||||
* The server options part of the form.
|
||||
* @param array $form_state
|
||||
* The current form state.
|
||||
*
|
||||
* @return array
|
||||
* A form array for setting service-specific options.
|
||||
@@ -81,29 +98,36 @@ interface SearchApiServiceInterface {
|
||||
public function supportsFeature($feature);
|
||||
|
||||
/**
|
||||
* View this server's settings. Output can be HTML or a render array, a <dl>
|
||||
* listing all relevant settings is preferred.
|
||||
* Displays this server's settings.
|
||||
*
|
||||
* Output can be HTML or a render array, a <dl> listing all relevant settings
|
||||
* is preferred.
|
||||
*/
|
||||
public function viewSettings();
|
||||
|
||||
/**
|
||||
* Reacts to the server's creation.
|
||||
*
|
||||
* Called once, when the server is first created. Allows it to set up its
|
||||
* necessary infrastructure.
|
||||
*/
|
||||
public function postCreate();
|
||||
|
||||
/**
|
||||
* Notifies this server that its fields are about to be updated. The server's
|
||||
* $original property can be used to inspect the old property values.
|
||||
* Notifies this server that its fields are about to be updated.
|
||||
*
|
||||
* @return
|
||||
* The server's $original property can be used to inspect the old property
|
||||
* values.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE, if the update requires reindexing of all content on the server.
|
||||
*/
|
||||
public function postUpdate();
|
||||
|
||||
/**
|
||||
* Notifies this server that it is about to be deleted from the database and
|
||||
* should therefore clean up, if appropriate.
|
||||
* Notifies this server that it is about to be deleted from the database.
|
||||
*
|
||||
* This should execute any necessary cleanup operations.
|
||||
*
|
||||
* Note that you shouldn't call the server's save() method, or any
|
||||
* methods that might do that, from inside of this method as the server isn't
|
||||
@@ -112,18 +136,21 @@ interface SearchApiServiceInterface {
|
||||
public function preDelete();
|
||||
|
||||
/**
|
||||
* Add a new index to this server.
|
||||
* Adds a new index to this server.
|
||||
*
|
||||
* If the index was already added to the server, the object should treat this
|
||||
* as if removeIndex() and then addIndex() were called.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index to add.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If an error occurred while adding the index.
|
||||
*/
|
||||
public function addIndex(SearchApiIndex $index);
|
||||
|
||||
/**
|
||||
* Notify the server that the field settings for the index have changed.
|
||||
* Notifies the server that the field settings for the index have changed.
|
||||
*
|
||||
* If any user action is necessary as a result of this, the method should
|
||||
* use drupal_set_message() to notify the user.
|
||||
@@ -134,11 +161,14 @@ interface SearchApiServiceInterface {
|
||||
* @return bool
|
||||
* TRUE, if this change affected the server in any way that forces it to
|
||||
* re-index the content. FALSE otherwise.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If an error occurred while reacting to the change of fields.
|
||||
*/
|
||||
public function fieldsUpdated(SearchApiIndex $index);
|
||||
|
||||
/**
|
||||
* Remove an index from this server.
|
||||
* Removes an index from this server.
|
||||
*
|
||||
* This might mean that the index has been deleted, or reassigned to a
|
||||
* different server. If you need to distinguish between these cases, inspect
|
||||
@@ -152,11 +182,14 @@ interface SearchApiServiceInterface {
|
||||
* @param $index
|
||||
* Either an object representing the index to remove, or its machine name
|
||||
* (if the index was completely deleted).
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If an error occurred while removing the index.
|
||||
*/
|
||||
public function removeIndex($index);
|
||||
|
||||
/**
|
||||
* Index the specified items.
|
||||
* Indexes the specified items.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The search index for which items should be indexed.
|
||||
@@ -187,7 +220,7 @@ interface SearchApiServiceInterface {
|
||||
public function indexItems(SearchApiIndex $index, array $items);
|
||||
|
||||
/**
|
||||
* Delete items from an index on this server.
|
||||
* Deletes indexed items from this server.
|
||||
*
|
||||
* Might be either used to delete some items (given by their ids) from a
|
||||
* specified index, or all items from that index, or all items from all
|
||||
@@ -200,11 +233,14 @@ interface SearchApiServiceInterface {
|
||||
* @param SearchApiIndex $index
|
||||
* The index from which items should be deleted, or NULL if all indexes on
|
||||
* this server should be cleared (then, $ids has to be 'all').
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If an error occurred while trying to delete the items.
|
||||
*/
|
||||
public function deleteItems($ids = 'all', SearchApiIndex $index = NULL);
|
||||
|
||||
/**
|
||||
* Create a query object for searching on an index lying on this server.
|
||||
* Creates a query object for searching on an index lying on this server.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index to search on.
|
||||
@@ -334,6 +370,30 @@ abstract class SearchApiAbstractService implements SearchApiServiceInterface {
|
||||
return $output ? "<dl>\n$output</dl>" : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns additional, service-specific information about this server.
|
||||
*
|
||||
* If a service class implements this method and supports the
|
||||
* "search_api_service_extra" option, this method will be used to add extra
|
||||
* information to the server's "View" tab.
|
||||
*
|
||||
* In the default theme implementation this data will be output in a table
|
||||
* with two columns along with other, generic information about the server.
|
||||
*
|
||||
* @return array
|
||||
* An array of additional server information, with each piece of information
|
||||
* being an associative array with the following keys:
|
||||
* - label: The human-readable label for this data.
|
||||
* - info: The information, as HTML.
|
||||
* - status: (optional) The status associated with this information. One of
|
||||
* "info", "ok", "warning" or "error". Defaults to "info".
|
||||
*
|
||||
* @see supportsFeature()
|
||||
*/
|
||||
public function getExtraInformation() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements SearchApiServiceInterface::__construct().
|
||||
*
|
||||
|
Reference in New Issue
Block a user