Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
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
alpha
physical
Commits
ca181dec
Commit
ca181dec
authored
Jun 17, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
689e886e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
21 deletions
+37
-21
tasks.py
injection/data_sync/tasks.py
+4
-4
group.py
search/utils/group.py
+3
-2
search_hotword.py
search/views/search_hotword.py
+30
-15
No files found.
injection/data_sync/tasks.py
View file @
ca181dec
...
...
@@ -113,16 +113,16 @@ def sync_user_similar_score():
def
get_tag_count
():
try
:
# 获取搜索推荐热词
results_registr_tag
=
RegisterShowTag
.
objects
.
filter
(
is_deleted
=
False
,
is_online
=
1
)
.
count
(
)
results_registr_tag
=
list
(
set
(
RegisterShowTag
.
objects
.
filter
(
is_deleted
=
False
,
is_online
=
1
)
.
values_list
(
"tag_id"
,
flat
=
True
))
)
# 获取符合条件的核心词
results_tag
=
Tag
.
objects
.
filter
(
is_online
=
True
,
collection
=
1
)
.
count
(
)
results_tag
=
list
(
set
(
Tag
.
objects
.
filter
(
is_online
=
True
,
is_deleted
=
False
,
collection
=
1
)
.
values_list
(
"id"
,
flat
=
True
))
)
redis_registr_tag
=
"physical:search_hotword:results_registr_tag"
redis_tag
=
"physical:search_hotword:results_tag"
redis_client
.
set
(
redis_registr_tag
,
str
(
results_registr_tag
))
redis_client
.
set
(
redis_tag
,
str
(
results_tag
))
redis_client
.
set
(
redis_registr_tag
,
list
(
results_registr_tag
))
redis_client
.
set
(
redis_tag
,
list
(
results_tag
))
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
search/utils/group.py
View file @
ca181dec
...
...
@@ -247,7 +247,8 @@ class GroupUtils(object):
}
}
q
[
"_source"
]
=
{
"includes"
:
[
"id"
,
"is_online"
,
"is_deleted"
,
"is_default"
,
"topic_id_list"
,
"is_cover"
,
"includes"
:
[
"id"
,
"is_online"
,
"is_deleted"
,
"is_default"
,
"name"
,
"tag_name"
,
"description"
,
"is_cover"
,
"offline_score"
,
"is_default"
]
}
...
...
@@ -269,9 +270,9 @@ class GroupUtils(object):
}
]
logging
.
info
(
"get get_search_pictorial_topic:
%
s"
%
q
)
es_cli_obj
=
ESPerform
.
get_cli
()
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"pictorial"
,
q
,
offset
,
size
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
return
result_dict
except
:
...
...
search/views/search_hotword.py
View file @
ca181dec
...
...
@@ -33,38 +33,53 @@ def search_hotword(device_id=-1):
"""
try
:
all_tag_name_list
=
set
()
results_registr_tag
=
int
(
redis_client
.
get
(
"physical:search_hotword:results_registr_tag"
))
results_tag
=
int
(
redis_client
.
get
(
"physical:search_hotword:results_tag"
))
logging
.
info
(
"get redis_client:
%
s"
%
redis_client
)
results_registr_tag
=
json
.
loads
(
redis_client
.
get
(
"physical:search_hotword:results_registr_tag"
))
results_tag
=
json
.
loads
(
redis_client
.
get
(
"physical:search_hotword:results_tag"
))
# 先获取搜索推荐热词
for
num
in
range
(
1
,
results_tag
):
tag_id
=
random
.
randint
(
1
,
results_tag
)
results_tag_chose
=
RegisterShowTag
.
objects
.
filter
(
id
=
tag_id
,
is_online
=
True
)
.
values_list
(
"name"
,
flat
=
True
)
all_tag_name_list
.
add
(
results_tag_chose
)
for
num
in
range
(
0
,
len
(
results_registr_tag
)
-
1
):
tag_id
=
random
.
randint
(
0
,
len
(
results_registr_tag
)
-
1
)
results_tag_chose
=
list
(
set
(
RegisterShowTag
.
objects
.
filter
(
tag_id
=
results_registr_tag
[
tag_id
],
is_online
=
True
)
.
values_list
(
"tag_id"
,
flat
=
True
)))
if
results_tag_chose
:
results_tag_recommend
=
list
(
set
(
Tag
.
objects
.
filter
(
id
=
results_tag_chose
[
0
],
is_online
=
True
)
.
values_list
(
"name"
,
flat
=
True
)))
if
results_tag_recommend
:
all_tag_name_list
.
add
(
results_tag_recommend
[
0
])
if
len
(
all_tag_name_list
)
==
6
or
num
==
results_tag
:
break
logging
.
info
(
"get all_tag_name_list:
%
s"
%
all_tag_name_list
)
# 获取个性化标签
linucb_recommend_redis_prefix
=
"physical:linucb:tag_recommend:device_id:"
tag_recommend_redis_key
=
linucb_recommend_redis_prefix
+
str
(
device_id
)
linucb_recommend_tag_data
=
redis_client
.
get
(
tag_recommend_redis_key
)
linucb_recommend_tag_list
=
json
.
loads
(
linucb_recommend_tag_data
)
if
linucb_recommend_tag_data
else
[]
for
item
in
linucb_recommend_tag_list
:
results_tag_recommend
=
Tag
.
objects
.
filter
(
id
=
item
,
is_online
=
True
)
.
values_list
(
"name"
,
flat
=
True
)
results_tag_recommend
=
list
(
set
(
Tag
.
objects
.
filter
(
id
=
item
,
is_online
=
True
)
.
values_list
(
"name"
,
flat
=
True
)))
all_tag_name_list
.
add
(
results_tag_recommend
[
0
])
if
len
(
all_tag_name_list
)
==
12
:
logging
.
info
(
"get all_tag_name_list:
%
s"
%
all_tag_name_list
)
return
{
"recommend_tag_name"
:
list
(
all_tag_name_list
)}
# 取不够数则取核心标签
if
len
(
all_tag_name_list
)
<
12
:
for
i
in
range
(
0
,
12
):
tag_id
=
random
.
randint
(
1
,
results_registr_tag
)
results_tag_hexin
=
Tag
.
objects
.
filter
(
id
=
tag_id
,
is_online
=
True
,
collection
=
1
)
.
values_list
(
"name"
,
flat
=
True
)
if
results_tag_hexin
not
in
all_tag_name_list
:
all_tag_name_list
.
add
(
results_tag_hexin
[
0
])
if
len
(
all_tag_name_list
)
>=
12
:
return
{
"recommend_tag_name"
:
list
(
all_tag_name_list
)}
tag_id
=
random
.
randint
(
1
,
len
(
results_tag
))
results_tag_hexin
=
Tag
.
objects
.
filter
(
id
=
results_tag
[
tag_id
],
is_online
=
True
,
collection
=
1
)
.
values_list
(
"name"
,
flat
=
True
)
if
results_tag_hexin
:
if
results_tag_hexin
[
0
]
not
in
all_tag_name_list
:
all_tag_name_list
.
add
(
results_tag_hexin
[
0
])
if
len
(
all_tag_name_list
)
>=
12
:
logging
.
info
(
"get all_tag_name_list:
%
s"
%
all_tag_name_list
)
return
{
"recommend_tag_name"
:
list
(
all_tag_name_list
)}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
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