查詢擴充

查詢擴充功能會逐步放寬查詢限制,以便在最初找不到任何結果或結果太少時,納入更多結果。因此系統會調整每個查詢的結果大小。

如果查詢完全沒有相關文件,查詢擴展功能會傳回較不相關的文件,確保查詢不會傳回零個搜尋結果。

教學課程:查詢擴充

本教學課程說明如何啟用查詢擴充功能。如果購物者使用模稜兩可或多個字詞組成的搜尋詞組,可能會收到空白回覆。啟用查詢擴充功能後,系統會分析要求,並根據剖析的搜尋查詢傳回擴充的產品清單。


如要直接在 Cloud Shell 編輯器中按照逐步指南操作,請按一下「Guide me」(逐步引導)

逐步引導


範例資料集

本頁會使用下列資料集做為範例。展開即可查看範例產品說明資料集中的欄位。

產品資料集範例

ID title 品牌 類別 price_info.price
"nest_mini_2nd_gen" 「Nest Mini (第 2 代)」 ["Google", "Nest"] ["Nest > 音箱和螢幕"] 49.00
「nest_audio」 「Nest Audio」 ["Google", "Nest"] ["Nest > 音箱和螢幕"] 99.99
「nest_hub_max」 「Nest Hub Max」 ["Google", "Nest"] ["Nest > 音箱和螢幕"] 229.00
「nest_hub」 「Nest Hub」 ["Google", "Nest"] ["Nest > 音箱和螢幕"] 88.99
「google_home_max」 「Google Home Max」 ["Google", "Nest"] ["Nest > 音箱和螢幕"] 299.00
「google_home_mini」 「Google Home Mini」 ["Google", "Nest"] ["Nest > 音箱和螢幕"] 49.00
「google_pixel_5」 「Google Pixel 5」 ["Google", "Pixel"] ["Pixel > 手機"] 699.00
"google_pixel_4a_with_5g" 「Google Pixel 4a 5G 版」 ["Google", "Pixel"] ["Pixel > 手機"] 499.00
「google_pixel_4a」 「Google Pixel 4a 手機」 ["Google", "Pixel"] ["Pixel > 手機"] 349.00
「google_pixel_stand」 「Google Pixel Stand」 ["Google", "Pixel"] ["Pixel > featured accessories"] 79.00
「google_pixel_buds」 「Google Pixel Buds」 ["Google", "Pixel"] ["Pixel > featured accessories"] 179.00
"google_pixel_5_case" 「Google Pixel 5 保護殼」 ["Google", "Pixel"] ["Pixel > featured accessories"] 40.00
"google_pixel_4a_5g_case" 「Google Pixel 4a (5G) 保護殼」 ["Google", "Pixel"] ["Pixel > featured accessories"] 40.00
"google_pixel_4a_case" 「Google Pixel 4a 保護殼」 ["Google", "Pixel"] ["Pixel > featured accessories"] 40.00

查詢擴充

查詢擴充功能可提高結果較少的查詢字詞 (尤其是長尾查詢) 的召回率。

這項搜尋功能是由規格驅動,可決定查詢擴展條件。其中包含預設為關閉的 pinUnexpandedResults 選項。如果設為 true,搜尋結果頂端會顯示未使用擴充功能的產品。頂端會顯示最佳搜尋結果,下方則會顯示展開的結果。

Java

import com.google.cloud.retail.v2.SearchRequest;
import com.google.cloud.retail.v2.SearchRequest.QueryExpansionSpec;
import com.google.cloud.retail.v2.SearchRequest.QueryExpansionSpec.Condition;
import com.google.cloud.retail.v2.SearchResponse;
import com.google.cloud.retail.v2.SearchServiceClient;

public static void searchProductsWithQueryExpansion(String query, int pageSize,
    Condition condition) throws IOException, InterruptedException {
  QueryExpansionSpec queryExpansionSpec = QueryExpansionSpec.newBuilder()
      .setCondition(condition)
      .build();

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

  try (SearchServiceClient searchClient = SearchServiceClient.create()) {
    SearchResponse response = searchClient.search(searchRequest).getPage().getResponse();
    System.out.println("Search response: " + searchResponse);
  }
}

舉例來說,如果您搜尋「Google Pixel 5」,但未擴大查詢範圍,結果只會顯示 google_pixel_5 ID。不過,透過查詢擴展功能,您也可能會在範例產品說明資料集中取得 google_pixel_4a_with_5ggoogle_pixel_4agoogle_pixel_5_case ID。