This is the documentation for Recommendations AI, Retail Search, and the new Retail console.

Boost results

This page outlines boosting of search results.

Boosting tutorial

This tutorial shows you some examples of product boosting.


For step-by-step guidance on this task directly in Cloud Shell Editor, click Guide me:

Guide me


The following sections take you through the same steps as clicking Guide me.

Example dataset

This page uses the following dataset as an example. Only the fields necessary for explanation are included.

Prerequisites

See Filter and order results for the filter expression syntax.

Boost

With boosting, you can control the result ranking by apply a boost to prioritize or deprioritize the results.

For example, if you search for "Google speaker", then you would get "nest_mini_2nd_gen", "nest_audio", "nest_hub_max", "nest_hub", "google_home_max" and "google_home_mini" in no specific order.

Java

public static SearchResponse searchProductsWithBoostSpec(String query, int pageSize,
    String condition, float boostStrength) throws IOException, InterruptedException {
  SearchServiceClient searchClient = getSearchServiceClient();

  BoostSpec boostSpec = BoostSpec.newBuilder()
      .addConditionBoostSpecs(ConditionBoostSpec.newBuilder()
          .setCondition(condition)
          .setBoost(boostStrength)
          .build())
      .build();

  SearchRequest searchRequest = SearchRequest.newBuilder()
      .setPlacement(DEFAULT_SEARCH_PLACEMENT_NAME)
      .setBranch(DEFAULT_BRANCH_NAME)
      .setVisitorId(VISITOR_ID)
      .setQuery(query)
      .setPageSize(pageSize)
      .setBoostSpec(boostSpec)
      .build();

  SearchResponse response = searchClient.search(searchRequest).getPage().getResponse();

  searchClient.shutdownNow();
  searchClient.awaitTermination(2, TimeUnit.SECONDS);

  return response;
}

Suppose that you want to prioritize the cheaper products (less than 95 dollars) and deprioritize the expensive ones (higher than 95 dollars). You can apply a boost spec as:

JSON

{
  condition_boost_specs {
    condition: "price: IN(*, 95.0e)"
    boost: 0.5
  }
  condition_boost_specs {
    condition: "price: IN(95.0e, *)"
    boost: -0.5
  }
}

In the result, "nest_mini_2nd_gen", "google_home_mini" and "nest_hub" might be the first three, while "nest_audio", "nest_hub_max" and "google_home_max" might be last three. However, no specific order is guaranteed, which is different from ordering by price, as discussed in Filter and order results.