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
15416a2f
Commit
15416a2f
authored
Feb 18, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dlis' into 'master'
add See merge request
alpha/physical!117
parents
ca25c64a
cdf3d891
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
6 deletions
+130
-6
app_conf.xml
app_conf.xml
+1
-0
contrast_similar.py
search/views/contrast_similar.py
+105
-0
trans2es_data2es_parallel.py
trans2es/management/commands/trans2es_data2es_parallel.py
+2
-2
topic.py
trans2es/models/topic.py
+22
-4
user.py
trans2es/models/user.py
+0
-0
No files found.
app_conf.xml
View file @
15416a2f
...
...
@@ -14,5 +14,6 @@
<element
value=
"search.views.user"
/>
<element
value=
"search.views.tag"
/>
<element
value=
"injection.data_sync.tasks"
/>
<element
value=
"search.views.contrast_similar"
/>
</config>
</gm_rpcd_config>
search/views/contrast_similar.py
0 → 100644
View file @
15416a2f
# -*- coding: UTF-8 -*-
# !/usr/bin/env python
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
from
gm_rpcd.all
import
bind
import
logging
import
traceback
import
json
from
search.utils.topic
import
TopicUtils
from
libs.es
import
ESPerform
from
libs.cache
import
redis_client
from
search.utils.common
import
*
from
gm_rpcd.all
import
bind
import
functools
import
logging
import
traceback
from
libs.es
import
ESPerform
logger
=
logging
.
getLogger
(
__name__
)
MAX_LOAD
=
100
GROUP_SIZE
=
10
@bind
(
'physical/search/query_contrast_similar'
)
def
contrast_similar
(
user_id
,
offset
=
0
,
size
=
10
):
try
:
if
isinstance
(
user_id
,
int
):
contrast_topic_id_list
=
get_all_topic_id_list
(
user_id
,
offset
,
size
)
return
{
"contrast_similar_topic_id"
:
contrast_topic_id_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"contrast_similar_topic_id"
:
[]}
def
get_all_topic_id_list
(
user_id
,
offset
,
size
):
try
:
if
user_id
:
redis_key
=
"physical:user_similar:participant_user_id:"
+
str
(
user_id
)
redis_field_val_list
=
redis_client
.
get
(
redis_key
)
have_read_topic_id_list
=
json
.
loads
(
redis_field_val_list
)
if
redis_field_val_list
else
[]
read_topic_id_list
=
list
()
if
len
(
have_read_topic_id_list
)
>
0
:
for
i
in
have_read_topic_id_list
:
read_topic_id_list
.
append
(
i
.
get
(
"contrast_user_id"
))
q
=
{
"query"
:
{
"function_score"
:
{
"query"
:
{
"bool"
:
{
"must"
:
[{
"term"
:
{
"is_online"
:
True
}
},
{
"term"
:
{
"is_deleted"
:
False
}
},
{
"terms"
:
{
"content_level"
:
[
3
,
4
,
5
]
}
}],
"minimum_should_match"
:
1
,
"should"
:
{
"terms"
:
{
"user_id"
:
read_topic_id_list
}
}
}
}
}
}
}
logging
.
info
(
'contrast_similar,as q:
%
s'
%
str
(
q
)
.
encode
(
'utf-8'
))
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
contrast_topic_ids
=
[]
if
len
(
result_dict
[
'hits'
])
>
0
:
res_hit
=
result_dict
[
'hits'
]
for
item
in
res_hit
:
topic_id
=
item
[
'_source'
][
'id'
]
contrast_topic_ids
.
append
(
topic_id
)
logging
.
info
(
'contrast_similar_topic_id:
%
s'
%
contrast_topic_ids
)
return
contrast_topic_ids
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"contrast_similar_topic_id"
:
[]}
trans2es/management/commands/trans2es_data2es_parallel.py
View file @
15416a2f
...
...
@@ -73,8 +73,8 @@ class SyncDataToRedis(object):
redis_key
=
redis_key_prefix
+
str
(
participant_user_id
)
similar_result_items
=
FaceUserContrastSimilar
.
objects
.
filter
(
is_online
=
True
,
is_deleted
=
False
,
participant_user_id
=
participant_user_id
,
similarity__gt
=
0.
4
)
.
order_by
(
"-similarity"
)
.
limit
(
100
)
similarity__gt
=
0.
3
)
.
order_by
(
"-similarity"
)
item_list
=
list
()
for
item
in
similar_result_items
:
...
...
trans2es/models/topic.py
View file @
15416a2f
...
...
@@ -105,18 +105,36 @@ class Topic(models.Model):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_tag_name_list
(
self
,
tag_id_list
):
def
get_tag_name_list
(
self
,
tag_id_list
):
try
:
tag_name_list
=
list
()
query_results
=
Tag
.
objects
.
filter
(
id__in
=
tag_id_list
)
.
values_list
(
"name"
,
flat
=
True
)
for
item
in
query_results
:
tag_name_list
.
append
(
item
)
logging
.
info
(
"get tag_id_list :
%
s"
%
tag_id_list
)
if
len
(
tag_id_list
)
>
100
:
lens
=
int
(
len
(
tag_id_list
)
/
100
)
for
i
in
range
(
lens
+
1
):
if
i
!=
0
:
tag_id_100
=
tag_id_list
[
i
*
100
:
i
*
100
+
100
]
if
i
==
0
:
tag_id_100
=
tag_id_list
[
i
:
i
+
100
]
if
i
*
100
==
lens
*
100
and
len
(
tag_id_list
[
lens
*
100
:])
>
0
:
tag_id_100
=
tag_id_list
[
lens
*
100
:]
if
tag_id_100
:
logging
.
info
(
"get tag_id_100 :
%
s"
%
tag_id_100
)
query_results
=
Tag
.
objects
.
filter
(
id__in
=
tag_id_100
)
.
values_list
(
"name"
,
flat
=
True
)
for
item
in
query_results
:
tag_name_list
.
append
(
item
)
else
:
query_results
=
Tag
.
objects
.
filter
(
id__in
=
tag_id_list
)
.
values_list
(
"name"
,
flat
=
True
)
for
item
in
query_results
:
tag_name_list
.
append
(
item
)
return
tag_name_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_topic_offline_score
(
self
):
try
:
offline_score
=
0.0
...
...
trans2es/models/user.py
View file @
15416a2f
This diff is collapsed.
Click to expand it.
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