Search API Numeric Boost

Search API Numeric Boost

Ever have a need to increase or decrease a product, blog post or other entity in the your search results? Here’s one way to accomplish this by adding a number field to your content type and some Search API configuration. The Search Boost here means increasing or decreasing a item in the search results. I’m doing this in Drupal 10.3.

Using a product content type as an example.

Add a number field

  1. Add a Number (integer) field type

    1. Set an appropriate field title such as “Search Boost” or “Numeric Search Boost”

  2. We’ll want a range of negative to positive numbers, say -10 to 10

    1. Minimum: -10

    2. Maximum: 10

  3. Optional: Set the default value to 0

    1. With 0 the boost factor should not have an effect

Configure Search API

  1. Make sure the Search API modules are installed (enabled)

  2. Note: Assuming you already have a search server and index already created and working

  3. Go to the Search API in the admin

    1. /admin/config/search/search-api

  4. Edit the search index

  5. Under the Fields tab add your new search boost field as an Integer Type

  6. Under the Processors tab enable “Number field-based boosting”

  7. Scroll down to the Number field-based boosting tab

  8. For your new field set the Boost factor

    1. I used 2.0 which has done a good job with the -10 to 10 range we set above, but test out different values and the effects

  9. Save

Change Boost Value And Re-index Search

  1. Change the value of your new field to a negative number to lower the search boost and push the item (product) lower in the search results, last page of results, or a positive number to increase the product in the search result, first page of results.

  2. Re-index the search index

Hope this helps 🚀

Debugging Entity Auto Complete Field

Debugging Entity Auto Complete Field