本页面简要介绍了查询扩展。
教程:查询扩展
本教程介绍了如何启用查询扩展功能。买家使用含糊不清或包含多个字词的搜索词组时,可能会收到空响应。启用查询扩展后,系统会对请求进行分析,并返回根据解析的搜索查询展开的商品列表。
如需在 Cloud Shell Editor 中直接遵循有关此任务的分步指导,请点击操作演示:
示例数据集
本页以下面的数据集为例。仅包含说明所需的字段。
商品数据集示例
ID | title | brands | categories | price_info.price |
---|---|---|---|---|
"nest_mini_2nd_gen" | "Nest Mini (2nd gen)" | ["Google", "Nest"] | ["Nest > speakers and displays"] | 49.00 |
"nest_audio" | "Nest Audio" | ["Google", "Nest"] | ["Nest > speakers and displays"] | 99.99 |
"nest_hub_max" | "Nest Hub Max" | ["Google", "Nest"] | ["Nest > speakers and displays"] | 229.00 |
"nest_hub" | "Nest Hub" | ["Google", "Nest"] | ["Nest > speakers and displays"] | 88.99 |
"google_home_max" | "Google Home Max" | ["Google", "Nest"] | ["Nest > speakers and displays"] | 299.00 |
"google_home_mini" | "Google Home Mini" | ["Google", "Nest"] | ["Nest > speakers and displays"] | 49.00 |
"google_pixel_5" | "Google Pixel 5" | ["Google", "Pixel"] | ["Pixel > phones"] | 699.00 |
"google_pixel_4a_with_5g" | "Google Pixel 4a with 5G" | ["Google", "Pixel"] | ["Pixel > phones"] | 499.00 |
"google_pixel_4a" | "Google Pixel 4a Phones" | ["Google", "Pixel"] | ["Pixel > phones"] | 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 Case" | ["Google", "Pixel"] | ["Pixel > featured accessories"] | 40.00 |
"google_pixel_4a_5g_case" | "Google Pixel 4a (5G) Case" | ["Google", "Pixel"] | ["Pixel > featured accessories"] | 40.00 |
"google_pixel_4a_case" | "Google Pixel 4a Case" | ["Google", "Pixel"] | ["Pixel > featured accessories"] | 40.00 |
查询扩展
查询扩展会增加查询字词的召回率,但结果很少,尤其是长尾查询。
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”。而使用查询扩展时,您可能会收到“google_pixel_4a_with_5g”、“google_pixel_4a”和“google_pixel_5_case”。