class NodeSearch in Multiversion 8
Handles searching for node entities using the Search module index.
Overriding search result to accommodate '_delete' flag. Only line needs change here is the query condition "AND _deleted = 0". But there is no easy way to override it.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\search\Plugin\SearchPluginBase implements RefinableCacheableDependencyInterface, ContainerFactoryPluginInterface, SearchInterface uses RefinableCacheableDependencyTrait
- class \Drupal\search\Plugin\ConfigurableSearchPluginBase implements ConfigurableSearchPluginInterface
- class \Drupal\node\Plugin\Search\NodeSearch implements AccessibleInterface, TrustedCallbackInterface, SearchIndexingInterface uses DeprecatedServicePropertyTrait
- class \Drupal\multiversion\Entity\Search\NodeSearch
- class \Drupal\node\Plugin\Search\NodeSearch implements AccessibleInterface, TrustedCallbackInterface, SearchIndexingInterface uses DeprecatedServicePropertyTrait
- class \Drupal\search\Plugin\ConfigurableSearchPluginBase implements ConfigurableSearchPluginInterface
- class \Drupal\search\Plugin\SearchPluginBase implements RefinableCacheableDependencyInterface, ContainerFactoryPluginInterface, SearchInterface uses RefinableCacheableDependencyTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of NodeSearch
See also
https://www.drupal.org/project/drupal/issues/3039265
File
- src/
Entity/ Search/ NodeSearch.php, line 18
Namespace
Drupal\multiversion\Entity\SearchView source
class NodeSearch extends CoreNodeSearch {
/**
* {@inheritdoc}
*/
protected function findResults() {
$keys = $this->keywords;
// Build matching conditions.
$query = $this->database
->select('search_index', 'i', [
'target' => 'replica',
])
->extend('Drupal\\search\\SearchQuery')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
$query
->join('node_field_data', 'n', 'n.nid = i.sid AND n.langcode = i.langcode AND _deleted = 0');
$query
->condition('n.status', 1)
->addTag('node_access')
->searchExpression($keys, $this
->getPluginId());
// Handle advanced search filters in the f query string.
// \Drupal::request()->query->get('f') is an array that looks like this in
// the URL: ?f[]=type:page&f[]=term:27&f[]=term:13&f[]=langcode:en
// So $parameters['f'] looks like:
// array('type:page', 'term:27', 'term:13', 'langcode:en');
// We need to parse this out into query conditions, some of which go into
// the keywords string, and some of which are separate conditions.
$parameters = $this
->getParameters();
if (!empty($parameters['f']) && is_array($parameters['f'])) {
$filters = [];
// Match any query value that is an expected option and a value
// separated by ':' like 'term:27'.
$pattern = '/^(' . implode('|', array_keys($this->advanced)) . '):([^ ]*)/i';
foreach ($parameters['f'] as $item) {
if (preg_match($pattern, $item, $m)) {
// Use the matched value as the array key to eliminate duplicates.
$filters[$m[1]][$m[2]] = $m[2];
}
}
// Now turn these into query conditions. This assumes that everything in
// $filters is a known type of advanced search.
foreach ($filters as $option => $matched) {
$info = $this->advanced[$option];
// Insert additional conditions. By default, all use the OR operator.
$operator = empty($info['operator']) ? 'OR' : $info['operator'];
$where = new Condition($operator);
foreach ($matched as $value) {
$where
->condition($info['column'], $value);
}
$query
->condition($where);
if (!empty($info['join'])) {
$query
->join($info['join']['table'], $info['join']['alias'], $info['join']['condition']);
}
}
}
// Add the ranking expressions.
$this
->addNodeRankings($query);
// Run the query.
$find = $query
->fields('i', [
'langcode',
])
->groupBy('i.langcode')
->limit(10)
->execute();
// Check query status and set messages if needed.
$status = $query
->getStatus();
if ($status & SearchQuery::EXPRESSIONS_IGNORED) {
$this->messenger
->addWarning($this
->t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', [
'@count' => $this->searchSettings
->get('and_or_limit'),
]));
}
if ($status & SearchQuery::LOWER_CASE_OR) {
$this->messenger
->addWarning($this
->t('Search for either of the two terms with uppercase <strong>OR</strong>. For example, <strong>cats OR dogs</strong>.'));
}
if ($status & SearchQuery::NO_POSITIVE_KEYWORDS) {
$this->messenger
->addWarning($this
->formatPlural($this->searchSettings
->get('index.minimum_word_size'), 'You must include at least one keyword to match in the content, and punctuation is ignored.', 'You must include at least one keyword to match in the content. Keywords must be at least @count characters, and punctuation is ignored.'));
}
return $find;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
ConfigurableSearchPluginBase:: |
protected | property | The unique ID for the search page using this plugin. | |
ConfigurableSearchPluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ConfigurableSearchPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ConfigurableSearchPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ConfigurableSearchPluginBase:: |
public | function |
Sets the ID for the search page using this plugin. Overrides ConfigurableSearchPluginInterface:: |
|
ConfigurableSearchPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
NodeSearch:: |
protected | property | The Drupal account to use for checking for access to advanced search. | |
NodeSearch:: |
protected | property | The list of options and info for advanced search filters. | |
NodeSearch:: |
protected | property | The current database connection. | |
NodeSearch:: |
protected | property | The replica database connection. | |
NodeSearch:: |
protected | property | ||
NodeSearch:: |
protected | property | The entity type manager. | |
NodeSearch:: |
protected | property | The language manager. | |
NodeSearch:: |
protected | property |
The messenger. Overrides MessengerTrait:: |
|
NodeSearch:: |
protected | property | A module manager object. | |
NodeSearch:: |
protected | property | An array of additional rankings from hook_ranking(). | |
NodeSearch:: |
protected | property | The Renderer service to format the username and node. | |
NodeSearch:: |
protected | property | The search index. | |
NodeSearch:: |
protected | property | A config object for 'search.settings'. | |
NodeSearch:: |
public | function |
Checks data value access. Overrides AccessibleInterface:: |
|
NodeSearch:: |
protected | function | Adds the configured rankings to the search query. | |
NodeSearch:: |
constant | A constant for setting and checking the query string. | ||
NodeSearch:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
NodeSearch:: |
public | function |
Builds the URL GET query parameters array for search. Overrides SearchPluginBase:: |
|
NodeSearch:: |
public static | function |
Creates an instance of the plugin. Overrides SearchPluginBase:: |
|
NodeSearch:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableSearchPluginBase:: |
|
NodeSearch:: |
public | function |
Executes the search. Overrides SearchInterface:: |
|
NodeSearch:: |
protected | function |
Queries to find search results, and sets status messages. Overrides NodeSearch:: |
|
NodeSearch:: |
protected | function | Gathers ranking definitions from hook_ranking(). | |
NodeSearch:: |
public | function |
Returns the search index type this plugin uses. Overrides SearchPluginBase:: |
|
NodeSearch:: |
public | function |
Clears the search index for this plugin. Overrides SearchIndexingInterface:: |
|
NodeSearch:: |
protected | function | Indexes a single node. | |
NodeSearch:: |
public | function |
Reports the status of indexing. Overrides SearchIndexingInterface:: |
|
NodeSearch:: |
public | function |
Verifies if the values set via setSearch() are valid and sufficient. Overrides SearchPluginBase:: |
|
NodeSearch:: |
public | function |
Marks the search index for reindexing for this plugin. Overrides SearchIndexingInterface:: |
|
NodeSearch:: |
protected | function | Parses the advanced search form default values. | |
NodeSearch:: |
protected | function | Prepares search results for rendering. | |
NodeSearch:: |
public | function | Removes the submitted by information from the build array. | |
NodeSearch:: |
public | function |
Alters the search form when being built for a given plugin. Overrides SearchPluginBase:: |
|
NodeSearch:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
NodeSearch:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
NodeSearch:: |
public | function |
Updates the search index for this plugin. Overrides SearchIndexingInterface:: |
|
NodeSearch:: |
public | function |
Constructs a \Drupal\node\Plugin\Search\NodeSearch object. Overrides ConfigurableSearchPluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
SearchPluginBase:: |
protected | property | The keywords to use in a search. | |
SearchPluginBase:: |
protected | property | Array of attributes - usually from the request object. | |
SearchPluginBase:: |
protected | property | Array of parameters from the query string from the request. | |
SearchPluginBase:: |
public | function |
Executes the search and builds render arrays for the result items. Overrides SearchInterface:: |
1 |
SearchPluginBase:: |
public | function |
Returns the currently set attributes (from the request). Overrides SearchInterface:: |
|
SearchPluginBase:: |
public | function |
Returns the searching help. Overrides SearchInterface:: |
1 |
SearchPluginBase:: |
public | function |
Returns the currently set keywords of the plugin instance. Overrides SearchInterface:: |
|
SearchPluginBase:: |
public | function |
Returns the current parameters set using setSearch(). Overrides SearchInterface:: |
|
SearchPluginBase:: |
public | function |
Sets the keywords, parameters, and attributes to be used by execute(). Overrides SearchInterface:: |
1 |
SearchPluginBase:: |
public | function |
Provides a suggested title for a page of search results. Overrides SearchInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |