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
钟尚武
physical
Commits
87920e61
Commit
87920e61
authored
May 09, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
779336c0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
55 deletions
+111
-55
topic.py
search/utils/topic.py
+111
-55
No files found.
search/utils/topic.py
View file @
87920e61
...
...
@@ -120,9 +120,11 @@ class TopicUtils(object):
return
{}
@classmethod
def
get_recommend_topic_ids
(
cls
,
user_id
,
tag_id
,
offset
,
size
,
single_size
,
query
=
None
,
query_type
=
TopicPageType
.
FIND_PAGE
,
filter_topic_id_list
=
[],
test_score
=
False
,
must_topic_id_list
=
[],
recommend_tag_list
=
[],
user_similar_score_list
=
[],
index_type
=
"topic"
,
routing
=
None
,
attention_tag_list
=
[],
linucb_user_id_list
=
[],
disable_collpase
=
False
):
def
get_recommend_topic_ids
(
cls
,
user_id
,
tag_id
,
offset
,
size
,
single_size
,
query
=
None
,
query_type
=
TopicPageType
.
FIND_PAGE
,
filter_topic_id_list
=
[],
test_score
=
False
,
must_topic_id_list
=
[],
recommend_tag_list
=
[],
user_similar_score_list
=
[],
index_type
=
"topic"
,
routing
=
None
,
attention_tag_list
=
[],
current_topic_id
=-
1
,
topic_tag_list
=
[],
topic_user_id
=-
1
):
"""
:remark:获取首页推荐帖子列表
:param user_id:
...
...
@@ -158,14 +160,14 @@ class TopicUtils(object):
q
[
"query"
]
=
dict
()
functions_list
=
[
#
{
#
"filter": {
#
"term": {
#
"language_type": 1
#
}
#
},
#
"weight": 60
#
},
{
"filter"
:
{
"term"
:
{
"language_type"
:
1
}
},
"weight"
:
60
},
{
"gauss"
:
{
"create_time"
:
{
...
...
@@ -175,18 +177,18 @@ class TopicUtils(object):
},
"weight"
:
60
},
#
{
#
"filter": {
# "constant_score":
{
# "filter":
{
#
"term": {
#
"content_level": 6
#
}
#
}
#
}
#
},
#
"weight": 600
#
}
{
"filter"
:
{
"constant_score"
:
{
"filter"
:
{
"term"
:
{
"content_level"
:
6
}
}
}
},
"weight"
:
600
}
]
# if len(user_similar_score_list) > 0:
...
...
@@ -216,7 +218,25 @@ class TopicUtils(object):
"weight"
:
100
}
)
if
current_topic_id
!=
-
1
:
if
len
(
topic_tag_list
)
>
0
:
functions_list
.
append
(
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"terms"
:
{
"tag_list"
:
topic_tag_list
}}}},
"weight"
:
2000
}
)
if
topic_user_id
!=
-
1
:
functions_list
.
append
(
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"term"
:
{
"user_id"
:
topic_user_id
}}}},
"weight"
:
1500
}
)
query_function_score
=
{
"query"
:
{
"bool"
:
{
...
...
@@ -242,10 +262,7 @@ class TopicUtils(object):
}
}
],
"minimum_should_match"
:
1
,
"must_not"
:
[
{
"term"
:
{
"is_history"
:
True
}}
]
"minimum_should_match"
:
1
}
},
"score_mode"
:
"sum"
,
...
...
@@ -260,18 +277,14 @@ class TopicUtils(object):
}
if
len
(
filter_topic_id_list
)
>
0
:
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
=
[
{
"terms"
:{
"id"
:
filter_topic_id_list
}}
]
if
len
(
linucb_user_id_list
)
>
0
:
if
"must_not"
in
query_function_score
[
"query"
][
"bool"
]:
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
+=
[
{
"terms"
:
{
"user_id"
:
linucb_user_id_list
}}
]
else
:
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
=
[
{
"terms"
:
{
"user_id"
:
linucb_user_id_list
}}
{
"terms"
:
{
"id"
:
filter_topic_id_list
}}
]
if
current_topic_id
!=
-
1
:
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
=
[{
"term"
:
{
"id"
:
current_topic_id
}
}]
if
query
is
not
None
:
# 搜索帖子
multi_fields
=
{
'description'
:
200
,
...
...
@@ -289,8 +302,7 @@ class TopicUtils(object):
query_function_score
[
"query"
][
"bool"
][
"should"
]
=
[
{
'multi_match'
:
multi_match
},
{
"term"
:
{
"tag_list"
:
tag_id
}},
{
"term"
:
{
"user_nick_name_pre"
:
query
.
lower
()}}
{
"term"
:
{
"tag_list"
:
tag_id
}}
]
query_function_score
[
"query"
][
"bool"
][
"minimum_should_match"
]
=
1
else
:
...
...
@@ -303,7 +315,6 @@ class TopicUtils(object):
{
"term"
:
{
"is_operation_home_recommend"
:
True
}}
]
q
[
"query"
][
"function_score"
]
=
query_function_score
if
not
disable_collpase
:
q
[
"collapse"
]
=
{
"field"
:
"user_id"
}
...
...
@@ -325,18 +336,18 @@ class TopicUtils(object):
# }
# },
{
"
offline
_score"
:
{
"_score"
:
{
"order"
:
"desc"
}
},
{
"_score"
:
{
"
offline
_score"
:
{
"order"
:
"desc"
}
}
]
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
index_type
,
query_body
=
q
,
offset
=
offset
,
size
=
size
,
routing
=
routing
)
offset
=
offset
,
size
=
size
,
routing
=
routing
)
topic_id_list
=
list
()
...
...
@@ -349,7 +360,8 @@ class TopicUtils(object):
@classmethod
def
get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_id
,
topic_tag_list
,
topic_pictorial_id
,
topic_user_id
,
filter_topic_user_id
,
have_read_topic_list
,
offset
,
size
,
es_cli_obj
=
None
,
index_type
=
"topic"
,
routing
=
None
):
filter_topic_user_id
,
have_read_topic_list
,
offset
,
size
,
es_cli_obj
=
None
,
index_type
=
"topic"
,
routing
=
None
):
"""
:remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
...
...
@@ -426,7 +438,7 @@ class TopicUtils(object):
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
index_type
,
query_body
=
q
,
offset
=
offset
,
size
=
size
,
routing
=
routing
)
offset
=
offset
,
size
=
size
,
routing
=
routing
)
return
result_dict
[
"hits"
]
except
:
...
...
@@ -434,9 +446,10 @@ class TopicUtils(object):
return
[]
@classmethod
def
top_get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_id
,
have_read_topic_list
,
size
,
es_cli_obj
=
None
,
index_type
=
"topic"
,
routing
=
None
,
collection_topic_tag_list
=
[],
topic_tag_list
=
[],
topic_user_id
=-
1
):
def
top_get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_id
,
have_read_topic_list
,
size
,
es_cli_obj
=
None
,
index_type
=
"topic"
,
routing
=
None
,
collection_topic_tag_list
=
[],
topic_tag_list
=
[],
topic_user_id
=-
1
):
"""
:remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
...
...
@@ -480,7 +493,7 @@ class TopicUtils(object):
# "weight": 5000
# }
# )
if
len
(
topic_tag_list
)
!=
0
or
topic_user_id
!=
-
1
:
if
len
(
topic_tag_list
)
!=
0
or
topic_user_id
!=
-
1
:
query_function_score
=
{
"query"
:
{
"bool"
:
{
...
...
@@ -548,7 +561,8 @@ class TopicUtils(object):
# {"create_time": {"order": "desc"}}
# ]
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
index_type
,
query_body
=
q
,
size
=
size
,
routing
=
routing
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
index_type
,
query_body
=
q
,
size
=
size
,
routing
=
routing
)
topic_id_list
=
list
()
for
item
in
result_dict
[
"hits"
]:
...
...
@@ -691,7 +705,7 @@ class TopicUtils(object):
{
"term"
:
{
"is_deleted"
:
False
}},
]
logging
.
info
(
"get filters:
%
s"
%
filters
)
logging
.
info
(
"get filters:
%
s"
%
filters
)
if
not
filters
:
return
f
...
...
@@ -797,7 +811,10 @@ class TopicUtils(object):
return
nf
for
k
,
v
in
nfilters
.
items
():
pass
if
k
==
"is_his"
:
nf
.
append
({
"term"
:
{
k
:
v
},
})
return
nf
...
...
@@ -894,13 +911,14 @@ class TopicUtils(object):
}
@classmethod
def
business_topic_id
s
(
cls
,
filters
,
nfilters
,
sorts_by
,
offset
=
0
,
size
=
10
,
index_name
=
"topic"
,
filter_online
=
True
):
def
business_topic_id
(
cls
,
filters
,
nfilters
,
sorts_by
,
offset
=
0
,
size
=
10
,
index_name
=
"topic"
,
filter_online
=
True
):
must
=
cls
.
process_filters
(
filters
,
filter_online
=
filter_online
)
query
=
''
for
k
,
v
in
filters
.
items
():
if
k
==
"content"
:
query
=
filters
[
k
]
q
=
{}
q
[
"query"
]
=
{
"function_score"
:
{
...
...
@@ -915,7 +933,7 @@ class TopicUtils(object):
}],
"query"
:
{
"multi_match"
:
{
"fields"
:[
"content"
],
"fields"
:
[
"content"
],
"type"
:
"cross_fields"
,
"operator"
:
"and"
,
"query"
:
query
...
...
@@ -923,6 +941,7 @@ class TopicUtils(object):
}
}
}
}
if
query
==
''
:
q
[
"query"
]
=
{
...
...
@@ -930,8 +949,45 @@ class TopicUtils(object):
"must"
:
must
,
"must_not"
:
cls
.
process_nfilters
(
nfilters
),
}
}
if
sorts_by
:
sorts
=
cls
.
process_sort
(
sorts_by
)
if
sorts
:
q
[
"sort"
]
=
sorts
try
:
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
index_name
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
return
{
"hits"
:
result_dict
[
"hits"
],
"total_count"
:
result_dict
[
"total_count"
]
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"hits"
:
[],
"total_count"
:
0
}
@classmethod
def
business_topic_ids
(
cls
,
filters
,
nfilters
,
sorts_by
,
offset
=
0
,
size
=
10
,
index_name
=
"topic"
,
filter_online
=
True
):
must
=
cls
.
process_filters
(
filters
,
filter_online
=
filter_online
)
q
=
{
"query"
:
{
"bool"
:
{
"must"
:
must
,
"must_not"
:
cls
.
process_nfilters
(
nfilters
),
}
}
}
if
sorts_by
:
sorts
=
cls
.
process_sort
(
sorts_by
)
if
sorts
:
...
...
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