You are here

public function SearchApiSolrTest::checkSearchResultGrouping in Search API Solr 8.3

Same name and namespace in other branches
  1. 8 tests/src/Kernel/SearchApiSolrTest.php \Drupal\Tests\search_api_solr\Kernel\SearchApiSolrTest::checkSearchResultGrouping()
  2. 4.x tests/src/Kernel/SearchApiSolrTest.php \Drupal\Tests\search_api_solr\Kernel\SearchApiSolrTest::checkSearchResultGrouping()

Tests search result grouping.

1 call to SearchApiSolrTest::checkSearchResultGrouping()
SearchApiSolrTest::checkBackendSpecificFeatures in tests/src/Kernel/SearchApiSolrTest.php
Checks backend specific features.

File

tests/src/Kernel/SearchApiSolrTest.php, line 834

Class

SearchApiSolrTest
Tests index and search capabilities using the Solr search backend.

Namespace

Drupal\Tests\search_api_solr\Kernel

Code

public function checkSearchResultGrouping() {
  $this->travisLogger
    ->debug('SearchApiSolrTest::checkSearchResultGrouping()');
  if (in_array('search_api_grouping', $this
    ->getIndex()
    ->getServerInstance()
    ->getBackend()
    ->getSupportedFeatures())) {
    $query = $this
      ->buildSearch(NULL, [], [], FALSE);
    $query
      ->setOption('search_api_grouping', [
      'use_grouping' => TRUE,
      'fields' => [
        'type',
      ],
    ]);
    $results = $query
      ->execute();
    $this
      ->assertEquals(2, $results
      ->getResultCount(), 'Get the results count grouping by type.');
    $data = $results
      ->getExtraData('search_api_solr_response');
    $this
      ->assertEquals(5, $data['grouped']['ss_type']['matches'], 'Get the total documents after grouping.');
    $this
      ->assertEquals(2, $data['grouped']['ss_type']['ngroups'], 'Get the number of groups after grouping.');
    $this
      ->assertResults([
      1,
      4,
    ], $results, 'Grouping by type');
  }
  else {
    $this
      ->markTestSkipped("The selected backend/connector doesn't support the *search_api_grouping* feature.");
  }
}