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
c2f61e2c
Commit
c2f61e2c
authored
Jun 28, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改排序逻辑
parent
f896baad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
28 deletions
+32
-28
topic.py
search/utils/topic.py
+32
-28
No files found.
search/utils/topic.py
View file @
c2f61e2c
...
@@ -14,7 +14,6 @@ from trans2es.models.pictorial import PictorialTopics
...
@@ -14,7 +14,6 @@ from trans2es.models.pictorial import PictorialTopics
from
libs.cache
import
redis_client
from
libs.cache
import
redis_client
class
TopicUtils
(
object
):
class
TopicUtils
(
object
):
@classmethod
@classmethod
...
@@ -35,7 +34,7 @@ class TopicUtils(object):
...
@@ -35,7 +34,7 @@ class TopicUtils(object):
}
}
q
[
"_source"
]
=
{
q
[
"_source"
]
=
{
"include"
:
[
"tag_list"
,
"attention_user_id_list"
,
"pick_user_id_list"
,
"same_pictorial_user_id_list"
]
"include"
:
[
"tag_list"
,
"attention_user_id_list"
,
"pick_user_id_list"
,
"same_pictorial_user_id_list"
]
}
}
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
,
size
)
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
,
size
)
...
@@ -174,18 +173,18 @@ class TopicUtils(object):
...
@@ -174,18 +173,18 @@ class TopicUtils(object):
}
}
]
]
if
user_id
and
user_id
>
0
:
if
user_id
and
user_id
>
0
:
redis_key_prefix
=
"physical:user_similar:participant_user_id:"
redis_key_prefix
=
"physical:user_similar:participant_user_id:"
similar_redis_key
=
redis_key_prefix
+
str
(
user_id
)
similar_redis_key
=
redis_key_prefix
+
str
(
user_id
)
redis_user_similar_data
=
redis_client
.
get
(
similar_redis_key
)
redis_user_similar_data
=
redis_client
.
get
(
similar_redis_key
)
user_similar_list
=
json
.
loads
(
redis_user_similar_data
)
if
redis_user_similar_data
else
[]
user_similar_list
=
json
.
loads
(
redis_user_similar_data
)
if
redis_user_similar_data
else
[]
if
len
(
user_similar_list
)
>
0
:
if
len
(
user_similar_list
)
>
0
:
functions_list
.
extend
(
user_similar_list
)
functions_list
.
extend
(
user_similar_list
)
if
len
(
attention_user_id_list
)
>
0
:
if
len
(
attention_user_id_list
)
>
0
:
functions_list
.
append
(
functions_list
.
append
(
{
{
"filter"
:
{
"constant_score"
:
{
"filter"
:
{
"terms"
:
{
"user_id"
:
attention_user_id_list
}}}},
"filter"
:
{
"constant_score"
:
{
"filter"
:
{
"terms"
:
{
"user_id"
:
attention_user_id_list
}}}},
"weight"
:
100
,
"weight"
:
100
,
}
}
)
)
...
@@ -272,7 +271,7 @@ class TopicUtils(object):
...
@@ -272,7 +271,7 @@ class TopicUtils(object):
]
]
query_function_score
[
"query"
][
"bool"
][
"minimum_should_match"
]
=
1
query_function_score
[
"query"
][
"bool"
][
"minimum_should_match"
]
=
1
query_function_score
[
"query"
][
"bool"
][
"filter"
]
.
append
(
query_function_score
[
"query"
][
"bool"
][
"filter"
]
.
append
(
{
"range"
:
{
"content_level"
:
{
"gte"
:
3
,
"lte"
:
6
}}}
{
"range"
:
{
"content_level"
:
{
"gte"
:
3
,
"lte"
:
6
}}}
)
)
else
:
else
:
if
"must_not"
in
query_function_score
[
"query"
][
"bool"
]:
if
"must_not"
in
query_function_score
[
"query"
][
"bool"
]:
...
@@ -337,7 +336,7 @@ class TopicUtils(object):
...
@@ -337,7 +336,7 @@ class TopicUtils(object):
@classmethod
@classmethod
def
userful_tag_topic_list
(
cls
,
user_id
,
have_read_topic_list
,
size
,
def
userful_tag_topic_list
(
cls
,
user_id
,
have_read_topic_list
,
size
,
index_type
=
"topic-high-star"
,
routing
=
None
,
useful_tag_list
=
[]):
index_type
=
"topic-high-star"
,
routing
=
None
,
useful_tag_list
=
[]):
"""
"""
:remark 帖子详情页推荐列表,缺少按时间衰减
:remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
:param user_id:
...
@@ -371,20 +370,20 @@ class TopicUtils(object):
...
@@ -371,20 +370,20 @@ class TopicUtils(object):
else
:
else
:
q
=
dict
()
q
=
dict
()
q
[
"query"
]
=
{
q
[
"query"
]
=
{
"bool"
:
{
"bool"
:
{
"must"
:
[
"must"
:
[
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"terms"
:
{
"useful_tag_list"
:
useful_tag_list
}},
{
"terms"
:
{
"useful_tag_list"
:
useful_tag_list
}},
{
"term"
:{
"content_level"
:
6
}}
{
"term"
:
{
"content_level"
:
6
}}
],
],
"must_not"
:
{
"must_not"
:
{
"terms"
:
{
"terms"
:
{
"id"
:
have_read_topic_list
"id"
:
have_read_topic_list
}
}
}
}
}
}
}
}
# logging.warning("topic_tag_list:%s"%str(topic_tag_list))
# logging.warning("topic_tag_list:%s"%str(topic_tag_list))
# query_function_score = {
# query_function_score = {
# "query": {
# "query": {
...
@@ -406,7 +405,8 @@ class TopicUtils(object):
...
@@ -406,7 +405,8 @@ class TopicUtils(object):
"includes"
:
[
"id"
]
"includes"
:
[
"id"
]
}
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
index_type
,
query_body
=
q
,
size
=
size
,
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
index_type
,
query_body
=
q
,
size
=
size
,
routing
=
routing
)
routing
=
routing
)
topic_id_list
=
list
()
topic_id_list
=
list
()
...
@@ -998,7 +998,7 @@ class TopicUtils(object):
...
@@ -998,7 +998,7 @@ class TopicUtils(object):
}
}
if
sorts_by
:
if
sorts_by
:
sorts
=
cls
.
process_sort
(
sorts_by
,
pictorial_id
=
None
)
sorts
=
cls
.
process_sort
(
sorts_by
,
pictorial_id
=
None
)
if
sorts
:
if
sorts
:
q
[
"sort"
]
=
sorts
q
[
"sort"
]
=
sorts
...
@@ -1029,7 +1029,6 @@ class TopicUtils(object):
...
@@ -1029,7 +1029,6 @@ class TopicUtils(object):
def
business_topic_ids
(
cls
,
filters
,
nfilters
,
sorts_by
,
offset
=
0
,
size
=
10
,
index_name
=
"topic"
,
filter_online
=
True
):
def
business_topic_ids
(
cls
,
filters
,
nfilters
,
sorts_by
,
offset
=
0
,
size
=
10
,
index_name
=
"topic"
,
filter_online
=
True
):
must
=
cls
.
business_filters
(
filters
,
filter_online
=
filter_online
)
must
=
cls
.
business_filters
(
filters
,
filter_online
=
filter_online
)
logging
.
info
(
"get must:
%
s"
%
must
)
q
=
{
q
=
{
"query"
:
{
"query"
:
{
"bool"
:
{
"bool"
:
{
...
@@ -1039,11 +1038,17 @@ class TopicUtils(object):
...
@@ -1039,11 +1038,17 @@ class TopicUtils(object):
}
}
}
}
if
'pictorial_id'
in
filters
.
keys
():
if
sorts_by
:
logging
.
info
(
"get picotirial:
%
s"
%
filters
[
"pictorial_id"
])
sorts
=
cls
.
process_sort
(
sorts_by
)
if
sorts_by
:
if
sorts
:
sorts
=
cls
.
process_sort
(
sorts_by
,
filters
[
"pictorial_id"
])
q
[
"sort"
]
=
sorts
if
sorts
:
q
[
"sort"
]
=
sorts
else
:
if
sorts_by
:
sorts
=
cls
.
process_sort
(
sorts_by
,
pictorial_id
=
None
)
if
sorts
:
q
[
"sort"
]
=
sorts
try
:
try
:
result_dict
=
ESPerform
.
get_search_results
(
result_dict
=
ESPerform
.
get_search_results
(
...
@@ -1144,7 +1149,6 @@ class TopicUtils(object):
...
@@ -1144,7 +1149,6 @@ class TopicUtils(object):
# }
# }
# })
# })
else
:
else
:
if
isinstance
(
v
,
list
):
if
isinstance
(
v
,
list
):
...
...
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