Loading CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Search API 1.x, dev (xxxx-xx-xx): --------------------------------- - #3347901 by drunken monkey: Added possibility for dates to be used in number field-based boosting. - #3321499 by andrew-minich, Shriaas, siddharthjain_7998, drunken monkey: Fixed errors with views on disabled indexes. - #3361041 by BigDave91, drunken monkey: Fixed integer overflow error in DB Loading src/Plugin/search_api/processor/NumberFieldBoost.php +9 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ class NumberFieldBoost extends ProcessorPluginBase implements PluginFormInterfac $boost_factors[Utility::formatBoostFactor(0)] = $this->t('Ignore'); foreach ($this->index->getFields(TRUE) as $field_id => $field) { if (in_array($field->getType(), ['integer', 'decimal'])) { if (in_array($field->getType(), ['integer', 'decimal', 'date'])) { $form['boosts'][$field_id] = [ '#type' => 'details', '#title' => $field->getLabel(), Loading Loading @@ -145,6 +145,14 @@ class NumberFieldBoost extends ProcessorPluginBase implements PluginFormInterfac } if ($value) { // Normalize values from dates (which are represented by UNIX // timestamps) to be not too large to store in the database, and // to also not be negative (in case it is a date from before // 1970). if ($field->getType() === 'date') { $value /= 1000000; $value = max($value, 0); } $item->setBoost($item->getBoost() * (double) $value * (double) $settings['boost_factor']); } } Loading tests/src/Kernel/Processor/NumberFieldBoostTest.php +32 −10 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ class NumberFieldBoostTest extends ProcessorTestBase { 'type' => 'page', 'title' => 'node 1 title', 'body' => 'node 1 body', 'created' => 1400000000, 'field_boost' => [8], ]); $node->save(); Loading @@ -73,6 +74,7 @@ class NumberFieldBoostTest extends ProcessorTestBase { 'type' => 'page', 'title' => 'node 2 title', 'body' => 'node 2 body', 'created' => 1600000000, 'field_boost' => [3, 10], ]); $node->save(); Loading @@ -82,6 +84,7 @@ class NumberFieldBoostTest extends ProcessorTestBase { 'type' => 'page', 'title' => 'node 3 title', 'body' => 'node 3 body', 'created' => 1500000000, 'field_boost' => [1], ]); $node->save(); Loading @@ -92,22 +95,22 @@ class NumberFieldBoostTest extends ProcessorTestBase { ]); $this->index->setDatasources($datasources); $nid_info = [ $fields_helper = $this->container->get('search_api.fields_helper'); $this->index->addField($fields_helper->createField($this->index, 'nid', [ 'datasource_id' => 'entity:node', 'property_path' => 'nid', 'type' => 'integer', ]; $boost_info = [ ])); $this->index->addField($fields_helper->createField($this->index, 'field_boost', [ 'datasource_id' => 'entity:node', 'property_path' => 'field_boost', 'type' => 'integer', ]; $fields_helper = $this->container->get('search_api.fields_helper'); $this->index->addField($fields_helper->createField($this->index, 'nid', $nid_info)); $this->index->addField($fields_helper->createField($this->index, 'field_boost', $boost_info)); ])); $this->index->addField($fields_helper->createField($this->index, 'created', [ 'datasource_id' => 'entity:node', 'property_path' => 'created', 'type' => 'date', ])); $this->index->save(); Loading Loading @@ -237,6 +240,25 @@ class NumberFieldBoostTest extends ProcessorTestBase { 'entity:node/3:en', ], array_keys($result->getResultItems())); $configuration = [ 'boosts' => [ 'created' => [ 'boost_factor' => 1.0, 'aggregation' => 'first', ], ], ]; $processor->setConfiguration($configuration); $this->index->addProcessor($processor); $this->index->save(); $this->indexItems(); $result = $this->getSearchResults(); $this->assertEquals([ 'entity:node/2:en', 'entity:node/3:en', 'entity:node/1:en', ], array_keys($result->getResultItems())); } /** Loading Loading
CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Search API 1.x, dev (xxxx-xx-xx): --------------------------------- - #3347901 by drunken monkey: Added possibility for dates to be used in number field-based boosting. - #3321499 by andrew-minich, Shriaas, siddharthjain_7998, drunken monkey: Fixed errors with views on disabled indexes. - #3361041 by BigDave91, drunken monkey: Fixed integer overflow error in DB Loading
src/Plugin/search_api/processor/NumberFieldBoost.php +9 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ class NumberFieldBoost extends ProcessorPluginBase implements PluginFormInterfac $boost_factors[Utility::formatBoostFactor(0)] = $this->t('Ignore'); foreach ($this->index->getFields(TRUE) as $field_id => $field) { if (in_array($field->getType(), ['integer', 'decimal'])) { if (in_array($field->getType(), ['integer', 'decimal', 'date'])) { $form['boosts'][$field_id] = [ '#type' => 'details', '#title' => $field->getLabel(), Loading Loading @@ -145,6 +145,14 @@ class NumberFieldBoost extends ProcessorPluginBase implements PluginFormInterfac } if ($value) { // Normalize values from dates (which are represented by UNIX // timestamps) to be not too large to store in the database, and // to also not be negative (in case it is a date from before // 1970). if ($field->getType() === 'date') { $value /= 1000000; $value = max($value, 0); } $item->setBoost($item->getBoost() * (double) $value * (double) $settings['boost_factor']); } } Loading
tests/src/Kernel/Processor/NumberFieldBoostTest.php +32 −10 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ class NumberFieldBoostTest extends ProcessorTestBase { 'type' => 'page', 'title' => 'node 1 title', 'body' => 'node 1 body', 'created' => 1400000000, 'field_boost' => [8], ]); $node->save(); Loading @@ -73,6 +74,7 @@ class NumberFieldBoostTest extends ProcessorTestBase { 'type' => 'page', 'title' => 'node 2 title', 'body' => 'node 2 body', 'created' => 1600000000, 'field_boost' => [3, 10], ]); $node->save(); Loading @@ -82,6 +84,7 @@ class NumberFieldBoostTest extends ProcessorTestBase { 'type' => 'page', 'title' => 'node 3 title', 'body' => 'node 3 body', 'created' => 1500000000, 'field_boost' => [1], ]); $node->save(); Loading @@ -92,22 +95,22 @@ class NumberFieldBoostTest extends ProcessorTestBase { ]); $this->index->setDatasources($datasources); $nid_info = [ $fields_helper = $this->container->get('search_api.fields_helper'); $this->index->addField($fields_helper->createField($this->index, 'nid', [ 'datasource_id' => 'entity:node', 'property_path' => 'nid', 'type' => 'integer', ]; $boost_info = [ ])); $this->index->addField($fields_helper->createField($this->index, 'field_boost', [ 'datasource_id' => 'entity:node', 'property_path' => 'field_boost', 'type' => 'integer', ]; $fields_helper = $this->container->get('search_api.fields_helper'); $this->index->addField($fields_helper->createField($this->index, 'nid', $nid_info)); $this->index->addField($fields_helper->createField($this->index, 'field_boost', $boost_info)); ])); $this->index->addField($fields_helper->createField($this->index, 'created', [ 'datasource_id' => 'entity:node', 'property_path' => 'created', 'type' => 'date', ])); $this->index->save(); Loading Loading @@ -237,6 +240,25 @@ class NumberFieldBoostTest extends ProcessorTestBase { 'entity:node/3:en', ], array_keys($result->getResultItems())); $configuration = [ 'boosts' => [ 'created' => [ 'boost_factor' => 1.0, 'aggregation' => 'first', ], ], ]; $processor->setConfiguration($configuration); $this->index->addProcessor($processor); $this->index->save(); $this->indexItems(); $result = $this->getSearchResults(); $this->assertEquals([ 'entity:node/2:en', 'entity:node/3:en', 'entity:node/1:en', ], array_keys($result->getResultItems())); } /** Loading