You are here

public static function Utility::getBoostFactors in Search API 8

Returns the available boost factors according to the configuration.

Parameters

float[] $additional_factors: (optional) Array of boost factors that will be added to the configured ones.

Return value

string[] An array with the available boost factors (formatted as strings), as both keys and values.

4 calls to Utility::getBoostFactors()
IndexFieldsForm::buildFieldsTable in src/Form/IndexFieldsForm.php
Builds the form fields for a set of fields.
NumberFieldBoost::buildConfigurationForm in src/Plugin/search_api/processor/NumberFieldBoost.php
Form constructor.
TypeBoost::buildConfigurationForm in src/Plugin/search_api/processor/TypeBoost.php
Form constructor.
UtilityTest::testGetBoostFactors in tests/src/Unit/UtilityTest.php
Tests obtaining a list of available boost factors.

File

src/Utility/Utility.php, line 283

Class

Utility
Contains utility methods for the Search API.

Namespace

Drupal\search_api\Utility

Code

public static function getBoostFactors(array $additional_factors = []) : array {
  $settings = \Drupal::config('search_api.settings');
  $boost_factors = $settings
    ->get('boost_factors') ?: [
    0.0,
    0.1,
    0.2,
    0.3,
    0.5,
    0.6,
    0.7,
    0.8,
    0.9,
    1.0,
    1.1,
    1.2,
    1.3,
    1.4,
    1.5,
    2.0,
    3.0,
    5.0,
    8.0,
    13.0,
    21.0,
  ];
  if ($additional_factors) {
    $boost_factors = array_merge($boost_factors, $additional_factors);
    sort($boost_factors, SORT_NUMERIC);
  }
  array_walk($boost_factors, function (&$value) {
    $value = self::formatBoostFactor($value);
  });
  return array_combine($boost_factors, $boost_factors);
}