- π·π΄Romania abautu
I am using this patch on some projects that use version 7 alpha3 and alpha4 of the module. Recently I noticed that when accessing some of the /admin/config/search/search-api/index/index_name pages (for large indexes) I was getting 500 errors, caused by PHP reaching its memory limit. After debuging, I found out that Search API themeing function (template_preprocess_search_api_index) does a query with offset 0 and limit 0 to check if the search index is alive. However, this patch turns that 0 rows limit into 10000 and that simple stats page tries to load tons of data.
I updated the patch to use !isset instead of empty. This will make a difference between Search API (using limit 0) and Display all page (using no limit, i.e. NULL). - π·πΈSerbia miksha
I opted for Event subscriber solution without patching module:
// File my_module/src/EventSubscriber/SearchQueryAlterSubscriber.php <?php namespace Drupal\my_module\EventSubscriber; use Drupal\elasticsearch_connector\Event\PrepareSearchQueryEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Event subscriber to alter search query config from ES connector. */ class SearchQueryAlterSubscriber implements EventSubscriberInterface { /** * {@inheritdoc} */ public static function getSubscribedEvents() { return [ PrepareSearchQueryEvent::PREPARE_QUERY => ['onPrepareSearchQuery', 100], ]; } /** * Sets the query limit to 1000. * * @param \Drupal\elasticsearch_connector\Event\PrepareSearchQueryEvent $event * The event. */ public function onPrepareSearchQuery(PrepareSearchQueryEvent $event) { // Get the Elasticsearch query from the event. /** @var \Drupal\elasticsearch_connector\Event\PrepareSearchQueryEvent $elastic_search_query */ $elastic_search_query = $event->getElasticSearchQuery(); $elastic_search_query['query_limit'] = 1000; // Set the altered query back to the event. $event->setElasticSearchQuery($elastic_search_query); } } // File my_module/my_module.services.yml services: my_module.search_query_alter: class: Drupal\my_module\EventSubscriber\SearchQueryAlterSubscriber tags: - { name: event_subscriber }
- π·πΈSerbia miksha
My event subscriber actually wouldn't work because in `SearchBuilder.php` we already set `$query_limit` based on `$query_option` but inside `PrepareSearchQueryEvent` we don't have any original information from `$query_options` as we only pass `$elasticSearchQuery` and `$indexName`. If e.g. I want to check if query limit is set inside my event subscriber while `Display all items` is chosen in the view, I would get result that it is set and its value is 10. This isn't something I can use inside event subscriber therefore I would suggest that `getSearchQueryOptions()` needs to be changed and we either pass original query so it is accessible in an event subscriber or some other solution to pass relevant information from original query that is changed inside `getSearchQueryOptions()`.