Commit 88ffb253 authored by luhongguang's avatar luhongguang

update:es查询功能优化

parent fe8e4aa5
......@@ -132,7 +132,6 @@ class ElasticGoodService
$result["count"] = $res["hits"]["total"]["value"];
foreach ($res["hits"]["hits"] as $key => $source) {
$result["list"][$key]["goods_desc_pic_url_list"] = [];
if (!empty($source["_source"]["goods_desc_pic_url"])) {
$ksyun = GoodsService::getUrlList($source["_source"]["goods_desc_pic_url"], 200, 200);
......@@ -154,7 +153,7 @@ class ElasticGoodService
$result["list"][$key]["life_account_id"] = $source["_source"]["life_account_id"];
$result["list"][$key]["life_account_name"] = $source["_source"]["life_account_name"];
$result["list"][$key]["life_account_icon"] = $source["_source"]["life_account_icon"];
$result["list"][$key]["distance"] = empty($source["sort"][1]) ? "" : round($source["sort"][1], 2) . "km";
$result["list"][$key]["distance"] = empty($source["sort"][0]) ? "" : round($source["sort"][0], 2) . "km";
$result["list"][$key]["update_time"] = $source["_source"]["update_time"];
}
}
......@@ -187,7 +186,7 @@ class ElasticGoodService
["price_sort" => "asc"],
];
$sortInit = empty($sortList[$sortType - 1]) ? $sortList[0] : $sortList[$sortType - 1];
$sortInit = isset($sortList[$sortType]) ? $sortList[$sortType] : $sortList[0];
$sort = array_merge($sortInit, $subjectSort);
$data = [
"sort" => $sort,
......@@ -201,7 +200,7 @@ class ElasticGoodService
],
"order" => "asc",
"unit" => "km",
"distance_type" => "plane",
"distance_type" => "plane",//更快但精度稍差的 plane 计算方法
];
}
return $data;
......@@ -232,6 +231,9 @@ class ElasticGoodService
["term" => ["audit_status" => GoodsSku::STATUS_PASS]],
["term" => ["online_status" => GoodsSku::ONLINE_STATUS_ONLINE]],
];
//gte 是大于等于; gt是大于; lte是小于等于; lt是小于
$data["query"]["bool"]["filter"][]["range"] = ["inventory_rest" => [["gt" => 0]]];
if (!empty($searchContent) || (!empty($subjectName) && $subjectName != "本周上新")) {
$multiMatch = [["multi_match" => [
"query" => $searchContent.$subjectName,
......@@ -249,7 +251,7 @@ class ElasticGoodService
}
if (!empty($latitude) && !empty($longitude)) {
$data["query"]["bool"]["filter"]["geo_distance"] = [
$data["query"]["bool"]["filter"][]["geo_distance"] = [
"distance" => "50km",
"shop_location" => [
"lat" => $latitude,
......@@ -257,7 +259,6 @@ class ElasticGoodService
]
];
}
return $data;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment