You are here

protected function BackendTest::regressionTest2938646 in Search API 8

Tests indexing of items with boost.

See also

https://www.drupal.org/node/2938646

1 call to BackendTest::regressionTest2938646()
BackendTest::backendSpecificRegressionTests in modules/search_api_db/tests/src/Kernel/BackendTest.php
Runs backend specific regression tests.

File

modules/search_api_db/tests/src/Kernel/BackendTest.php, line 659

Class

BackendTest
Tests index and search capabilities using the Database search backend.

Namespace

Drupal\Tests\search_api_db\Kernel

Code

protected function regressionTest2938646() {
  $db_info = $this
    ->getIndexDbInfo();
  $text_table = $db_info['field_tables']['body']['table'];
  $item_id = $this
    ->getItemIds([
    1,
  ])[0];
  $select = \Drupal::database()
    ->select($text_table, 't');
  $select
    ->fields('t', [
    'score',
  ])
    ->condition('item_id', $item_id)
    ->condition('word', 'test');
  $select2 = clone $select;

  // Check old score.
  $old_score = $select
    ->execute()
    ->fetchField();
  $this
    ->assertNotSame(FALSE, $old_score);
  $this
    ->assertGreaterThan(0, $old_score);

  // Re-index item with higher boost.
  $index = $this
    ->getIndex();
  $item = $this->container
    ->get('search_api.fields_helper')
    ->createItem($index, $item_id);
  $item
    ->setBoost(2);
  $indexed_ids = $this
    ->indexItemDirectly($index, $item);
  $this
    ->assertEquals([
    $item_id,
  ], $indexed_ids);

  // Verify the field scores changed accordingly.
  $new_score = $select2
    ->execute()
    ->fetchField();
  $this
    ->assertNotSame(FALSE, $new_score);
  $this
    ->assertEquals(2 * $old_score, $new_score);
}