Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goods
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
goods
Commits
2bd425f8
Commit
2bd425f8
authored
Jul 01, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:es data list
parent
d4fb078b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
51 deletions
+92
-51
ElasticGoodService.php
application/services/goods/ElasticGoodService.php
+92
-51
No files found.
application/services/goods/ElasticGoodService.php
View file @
2bd425f8
...
...
@@ -10,6 +10,11 @@ class ElasticGoodService
{
const
INDEX
=
"bp_goods"
;
const
SORT_TYPE_COMPREHENSIVE
=
0
;
const
SORT_TYPE_DISTANCE
=
1
;
const
SORT_TYPE_SALES
=
2
;
const
SORT_TYPE_PRICE
=
3
;
public
static
function
createIndex
()
{
$elasticClient
=
ElasticUtil
::
getInstance
();
...
...
@@ -115,57 +120,10 @@ class ElasticGoodService
*/
public
static
function
searchDoc
(
$params
=
[])
{
$sortType
=
0
;
if
(
!
empty
(
$params
[
"sort_type"
]))
{
$sortType
=
$params
[
"sort_type"
];
}
$from
=
empty
(
$params
[
"from"
])
?
0
:
(
int
)
$params
[
"from"
];
$size
=
empty
(
$params
[
"size"
])
?
10
:
(
int
)
$params
[
"size"
];
$sortList
=
[
[
"price_sort"
=>
"asc"
,
"total_amount_sold"
=>
"desc"
],
[
"total_amount_sold"
=>
"desc"
],
[
"price_sort"
=>
"asc"
],
];
$data
=
[
"from"
=>
$from
,
"size"
=>
$size
,
"sort"
=>
$sortList
[
$sortType
],
];
if
(
!
empty
(
$params
[
"search_content"
]))
{
$data
[
"query"
][
"bool"
][
"must"
][
"multi_match"
]
=
[
"query"
=>
$params
[
"search_content"
],
"fields"
=>
[
"goods_name"
,
"category_1_name"
,
"category_2_name"
,
"desc"
,
"life_account_name"
,
"shop_name"
],
];
}
// 注意这里顺序,必须 multi_match 在前,term在后
$data
[
"query"
][
"bool"
][
"must"
]
=
[
[
"term"
=>
[
"audit_status"
=>
GoodsSku
::
STATUS_PASS
]],
[
"term"
=>
[
"online_status"
=>
GoodsSku
::
ONLINE_STATUS_ONLINE
]],
];
if
(
!
empty
(
$params
[
"latitude"
])
&&
!
empty
(
$params
[
"longitude"
]))
{
$data
[
"query"
][
"bool"
][
"filter"
][
"geo_distance"
]
=
[
"distance"
=>
"50km"
,
"shop_location"
=>
[
"lat"
=>
$params
[
"latitude"
],
"lon"
=>
$params
[
"longitude"
],
]
];
$data
[
"sort"
][
"_geo_distance"
]
=
[
"shop_location"
=>
[
"lat"
=>
$params
[
"latitude"
],
"lon"
=>
$params
[
"longitude"
],
],
"order"
=>
"asc"
,
"unit"
=>
"km"
,
"distance_type"
=>
"plane"
,
];
}
$dataSort
=
self
::
getSortConditions
(
$params
);
$dataConditions
=
self
::
getSearchConditions
(
$params
);
$data
=
array_merge
(
$dataSort
,
$dataConditions
);
$elasticClient
=
ElasticUtil
::
getInstance
();
$res
=
$elasticClient
->
searchDoc
(
self
::
INDEX
,
$data
);
...
...
@@ -194,7 +152,7 @@ class ElasticGoodService
$result
[
"list"
][
$key
][
"shop_location"
]
=
$source
[
"_source"
][
"shop_location"
];
$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"
][
2
])
?
""
:
round
(
$source
[
"sort"
][
2
],
2
)
.
"km"
;
$result
[
"list"
][
$key
][
"distance"
]
=
empty
(
$source
[
"sort"
][
1
])
?
""
:
round
(
$source
[
"sort"
][
1
],
2
)
.
"km"
;
}
}
...
...
@@ -202,6 +160,89 @@ class ElasticGoodService
return
$result
?
$result
:
(
object
)
$result
;
}
/**
* 排序条件
* @param array $params
* @return array
*/
private
static
function
getSortConditions
(
$params
=
[])
{
// sort_type : 0综合排序,1距离,2销量,3价格
$sortType
=
empty
(
$params
[
"sort_type"
])
?
self
::
SORT_TYPE_COMPREHENSIVE
:
$params
[
"sort_type"
];
$latitude
=
empty
(
$params
[
"latitude"
])
?
""
:
$params
[
"latitude"
];
$longitude
=
empty
(
$params
[
"longitude"
])
?
""
:
$params
[
"longitude"
];
$sortList
=
[
[
"price_sort"
=>
"asc"
,
"total_amount_sold"
=>
"desc"
],
[],
[
"total_amount_sold"
=>
"desc"
],
[
"price_sort"
=>
"asc"
],
];
$data
=
[
"sort"
=>
$sortList
[
$sortType
],
];
if
(
!
empty
(
$latitude
)
&&
!
empty
(
$longitude
))
{
$data
[
"sort"
][
"_geo_distance"
]
=
[
"shop_location"
=>
[
"lat"
=>
$params
[
"latitude"
],
"lon"
=>
$params
[
"longitude"
],
],
"order"
=>
"asc"
,
"unit"
=>
"km"
,
"distance_type"
=>
"plane"
,
];
}
return
$data
;
}
/**
* 查询条件
* @param array $params
* @param array $data
* @return array|int[]
*/
private
static
function
getSearchConditions
(
$params
=
[])
{
$from
=
empty
(
$params
[
"from"
])
?
0
:
(
int
)
$params
[
"from"
];
$size
=
empty
(
$params
[
"size"
])
?
10
:
(
int
)
$params
[
"size"
];
$latitude
=
empty
(
$params
[
"latitude"
])
?
""
:
$params
[
"latitude"
];
$longitude
=
empty
(
$params
[
"longitude"
])
?
""
:
$params
[
"longitude"
];
$searchContent
=
empty
(
$params
[
"search_content"
])
?
""
:
$params
[
"search_content"
];
$subjectName
=
empty
(
$params
[
"subject_name"
])
?
""
:
$params
[
"subject_name"
];
$data
=
[
"from"
=>
$from
*
$size
,
"size"
=>
$size
,
];
$mustInit
=
[
[
"term"
=>
[
"audit_status"
=>
GoodsSku
::
STATUS_PASS
]],
[
"term"
=>
[
"online_status"
=>
GoodsSku
::
ONLINE_STATUS_ONLINE
]],
];
if
(
!
empty
(
$searchContent
))
{
$multiMatch
=
[[
"multi_match"
=>
[
"query"
=>
$searchContent
.
$subjectName
,
"fields"
=>
[
"goods_name"
,
"category_1_name"
,
"category_2_name"
,
"desc"
,
"life_account_name"
,
"shop_name"
],
]]];
$data
[
"query"
][
"bool"
][
"must"
]
=
array_merge
(
$mustInit
,
$multiMatch
);
}
else
{
$data
[
"query"
][
"bool"
][
"must"
]
=
$mustInit
;
}
if
(
!
empty
(
$latitude
)
&&
!
empty
(
$longitude
))
{
$data
[
"query"
][
"bool"
][
"filter"
][
"geo_distance"
]
=
[
"distance"
=>
"50km"
,
"shop_location"
=>
[
"lat"
=>
$latitude
,
"lon"
=>
$longitude
,
]
];
}
return
$data
;
}
/**
* id 在es数据里是否存在
* @param $skuId
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment