You are here

public function StreamingExpressionBuilder::getSearchAllRows in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Utility/StreamingExpressionBuilder.php \Drupal\search_api_solr\Utility\StreamingExpressionBuilder::getSearchAllRows()

Returns the row limit for _search_all() and _topic_all() expressions.

Both need a row limit that matches the real number of documents or higher. To increase the number of query result cache hits the required document counts are "normalized" to the nearest higher power of 2. Setting them to a very high fixed value makes no sense as this would waste memory in Solr Cloud and might lead to out of memory exceptions. The numbers are prepared via search_api_solr_cron(). If the cron hasn't run yet the function return 1024 as fallback.

Return value

int Integer of the row limit.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

\Drupal\search_api_solr\SearchApiSolrException

See also

search_api_solr_cron()

2 calls to StreamingExpressionBuilder::getSearchAllRows()
StreamingExpressionBuilder::_search_all in src/Utility/StreamingExpressionBuilder.php
Eases search() streaming expressions if all results are required.
StreamingExpressionBuilder::_topic_all in src/Utility/StreamingExpressionBuilder.php
Eases topic() expressions if there's no specific checkpoint collection.

File

src/Utility/StreamingExpressionBuilder.php, line 776

Class

StreamingExpressionBuilder
Provides methods for creating streaming expressions targeting a given index.

Namespace

Drupal\search_api_solr\Utility

Code

public function getSearchAllRows() {
  if (!$this->searchAllRows) {
    $rows = \Drupal::state()
      ->get('search_api_solr.search_all_rows', []);
    $this->searchAllRows = $rows[$this->serverId][$this->targetedSiteHash][$this->targetedIndexId] ?? FALSE;
    if (FALSE === $this->searchAllRows) {
      $counts = $this->backend
        ->getDocumentCounts();
      $this->searchAllRows = $rows[$this->serverId][$this->targetedSiteHash][$this->targetedIndexId] = Utility::normalizeMaxRows($counts[$this->targetedSiteHash][$this->targetedIndexId] ?? $counts['#total'] ?? 512);
      \Drupal::state()
        ->set('search_api_solr.search_all_rows', $rows);
    }
  }
  return $this->searchAllRows;
}