Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
VVAS-Match
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 7b18ab5b
authored
Jun 13, 2022
by
李乾广
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[chg]比对符合条件的数量优化
1 parent
24f11a6b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
24 deletions
src/main/java/com/viontech/match/service/PersonService.java
src/main/java/com/viontech/match/service/PersonService.java
View file @
7b18ab5
...
@@ -108,21 +108,39 @@ public class PersonService {
...
@@ -108,21 +108,39 @@ public class PersonService {
long
count
=
0
;
long
count
=
0
;
List
<
BodyFeature
>
bodyFeatures
=
person
.
getBodyFeatures
();
List
<
BodyFeature
>
bodyFeatures
=
person
.
getBodyFeatures
();
if
(
CollectionUtils
.
isEmpty
(
bodyFeatures
))
{
Double
[]
feature
=
null
;
log
.
info
(
"CountMatchPerson人体特征为空,PoolIds:[{}],count:{}"
,
poolIds
,
count
);
if
(
CollectionUtils
.
isEmpty
(
bodyFeatures
)
&&
null
==
person
.
getBodyMinScore
())
{
}
else
{
log
.
info
(
"CountMatchPerson人体特征为空并且最小分数为空,直接查数量,PoolIds:[{}],count:{}"
,
poolIds
,
count
);
Double
[]
feature
=
bodyFeatures
.
get
(
0
).
getFeature
();
}
else
if
(
CollectionUtils
.
isNotEmpty
(
bodyFeatures
)){
feature
=
bodyFeatures
.
get
(
0
).
getFeature
();
SearchSourceBuilder
builder
=
getSearchSourceBuilder
(
feature
,
person
,
1
);
if
(
feature
==
null
||
feature
.
length
<
Constant
.
BODY_FEATURE_DIMS_2048
)
{
ValueCountAggregationBuilder
countAggregationBuilder
=
AggregationBuilders
.
count
(
"countId"
).
field
(
"_id"
);
log
.
info
(
"人体特征维数小于2048,跳过比对"
);
builder
.
aggregation
(
countAggregationBuilder
);
ResponseVo
error
=
ResponseVo
.
error
(
rid
,
"人体特征维数小于2048,跳过比对"
);
request
.
source
(
builder
);
error
.
setCount
(
0
);
log
.
debug
(
"CountMatchPerson条件{}:{}"
,
indices
,
builder
.
toString
());
return
error
;
}
else
if
(
feature
.
length
==
Constant
.
BODY_FEATURE_DIMS_2110
)
{
feature
=
Utils
.
transferBodyFeature
(
feature
);
}
SearchResponse
response
=
client
.
search
(
request
,
RequestOptions
.
DEFAULT
);
if
(
feature
.
length
>
Constant
.
BODY_FEATURE_DIMS_2048
)
{
ParsedValueCount
countId
=
response
.
getAggregations
().
get
(
"countId"
);
feature
=
Arrays
.
copyOfRange
(
feature
,
3
,
Constant
.
BODY_FEATURE_DIMS_2048
+
3
);
count
=
countId
.
getValue
();
}
}
else
{
log
.
info
(
"参数错误"
);
ResponseVo
error
=
ResponseVo
.
error
(
rid
,
"参数错误"
);
error
.
setCount
(
0
);
return
error
;
}
}
SearchSourceBuilder
builder
=
getSearchSourceBuilder
(
feature
,
person
,
1
);
builder
.
size
(
0
);
ValueCountAggregationBuilder
countAggregationBuilder
=
AggregationBuilders
.
count
(
"countId"
).
field
(
"_id"
);
builder
.
aggregation
(
countAggregationBuilder
);
request
.
source
(
builder
);
log
.
debug
(
"CountMatchPerson条件{}:{}"
,
indices
,
builder
.
toString
());
SearchResponse
response
=
client
.
search
(
request
,
RequestOptions
.
DEFAULT
);
ParsedValueCount
countId
=
response
.
getAggregations
().
get
(
"countId"
);
count
=
countId
.
getValue
();
ResponseVo
result
=
ResponseVo
.
success
(
rid
,
"success"
);
ResponseVo
result
=
ResponseVo
.
success
(
rid
,
"success"
);
result
.
setCount
(
count
);
result
.
setCount
(
count
);
...
@@ -407,14 +425,14 @@ public class PersonService {
...
@@ -407,14 +425,14 @@ public class PersonService {
* @return
* @return
*/
*/
private
SearchSourceBuilder
getSearchSourceBuilder
(
Double
[]
feature
,
Person
person
,
int
type
)
{
private
SearchSourceBuilder
getSearchSourceBuilder
(
Double
[]
feature
,
Person
person
,
int
type
)
{
Script
script
;
Script
script
=
null
;
BoolQueryBuilder
boolQuery
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
boolQuery
=
QueryBuilders
.
boolQuery
();
if
(
type
==
0
)
{
if
(
null
!=
feature
&&
type
==
0
)
{
script
=
new
Script
(
script
=
new
Script
(
ScriptType
.
INLINE
,
Script
.
DEFAULT_SCRIPT_LANG
,
ScriptType
.
INLINE
,
Script
.
DEFAULT_SCRIPT_LANG
,
"(cosineSimilarity(params.face, 'data') + 1) / 2 * 100"
,
Collections
.
singletonMap
(
"face"
,
feature
));
"(cosineSimilarity(params.face, 'data') + 1) / 2 * 100"
,
Collections
.
singletonMap
(
"face"
,
feature
));
boolQuery
.
filter
(
QueryBuilders
.
existsQuery
(
"data"
));
boolQuery
.
filter
(
QueryBuilders
.
existsQuery
(
"data"
));
}
else
{
}
else
if
(
null
!=
feature
&&
type
==
1
)
{
script
=
new
Script
(
script
=
new
Script
(
ScriptType
.
INLINE
,
Script
.
DEFAULT_SCRIPT_LANG
,
ScriptType
.
INLINE
,
Script
.
DEFAULT_SCRIPT_LANG
,
"(cosineSimilarity(params.body, 'body') + 1) / 2 * 100"
,
Collections
.
singletonMap
(
"body"
,
feature
));
"(cosineSimilarity(params.body, 'body') + 1) / 2 * 100"
,
Collections
.
singletonMap
(
"body"
,
feature
));
...
@@ -455,14 +473,18 @@ public class PersonService {
...
@@ -455,14 +473,18 @@ public class PersonService {
if
(
counttimeGTE
!=
null
||
counttimeLTE
!=
null
)
{
if
(
counttimeGTE
!=
null
||
counttimeLTE
!=
null
)
{
boolQuery
.
filter
(
rangeQueryBuilder
);
boolQuery
.
filter
(
rangeQueryBuilder
);
}
}
SearchSourceBuilder
builder
;
ScriptScoreQueryBuilder
queryBuilder
=
QueryBuilders
.
scriptScoreQuery
(
boolQuery
,
script
);
if
(
null
==
script
)
{
SearchSourceBuilder
builder
=
new
SearchSourceBuilder
().
query
(
queryBuilder
);
builder
=
new
SearchSourceBuilder
().
query
(
boolQuery
);
//控制最小分数
}
else
{
if
(
0
==
type
&&
null
!=
person
.
getFaceMinScore
())
{
ScriptScoreQueryBuilder
queryBuilder
=
QueryBuilders
.
scriptScoreQuery
(
boolQuery
,
script
);
builder
.
minScore
(
person
.
getFaceMinScore
());
builder
=
new
SearchSourceBuilder
().
query
(
queryBuilder
);
}
else
if
(
1
==
type
&&
null
!=
person
.
getBodyMinScore
())
{
//控制最小分数,只有特征比对时才有分数
builder
.
minScore
(
person
.
getBodyMinScore
());
if
(
0
==
type
&&
null
!=
person
.
getFaceMinScore
())
{
builder
.
minScore
(
person
.
getFaceMinScore
());
}
else
if
(
1
==
type
&&
null
!=
person
.
getBodyMinScore
())
{
builder
.
minScore
(
person
.
getBodyMinScore
());
}
}
}
return
builder
;
return
builder
;
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment