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 d16d3a99
authored
Nov 07, 2024
by
姚冰
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[chg] 标注平台分支,添加聚合,匹配数量修改
1 parent
fa91890d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
15 deletions
src/main/java/com/viontech/match/service/PersonService.java
src/main/java/com/viontech/match/service/PersonService.java
View file @
d16d3a9
...
@@ -14,6 +14,7 @@ import co.elastic.clients.elasticsearch.core.search.SourceConfig;
...
@@ -14,6 +14,7 @@ import co.elastic.clients.elasticsearch.core.search.SourceConfig;
import
co.elastic.clients.elasticsearch.indices.DeleteIndexResponse
;
import
co.elastic.clients.elasticsearch.indices.DeleteIndexResponse
;
import
co.elastic.clients.elasticsearch.ingest.simulate.Document
;
import
co.elastic.clients.elasticsearch.ingest.simulate.Document
;
import
co.elastic.clients.json.JsonData
;
import
co.elastic.clients.json.JsonData
;
import
co.elastic.clients.util.NamedValue
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.fasterxml.jackson.annotation.JsonValue
;
import
com.fasterxml.jackson.annotation.JsonValue
;
...
@@ -274,7 +275,7 @@ public class PersonService {
...
@@ -274,7 +275,7 @@ public class PersonService {
// "counttime", personCountTime == null ? null : Constant.DATE_FORMAT.get().format(personCountTime),
// "counttime", personCountTime == null ? null : Constant.DATE_FORMAT.get().format(personCountTime),
// "channelSerialNum", personChannelSerialNum, "gateId", gateId, "direction", direction);
// "channelSerialNum", personChannelSerialNum, "gateId", gateId, "direction", direction);
// bulkRequest.add(indexRequest);
// bulkRequest.add(indexRequest);
operationList
.
add
(
new
BulkOperation
.
Builder
().
index
(
new
IndexOperation
.
Builder
<
PersonInfo
>().
index
(
poolId
).
document
(
new
PersonInfo
(
unid
,
personId
,
feature
,
null
,
age
,
gender
,
bodyType
,
personCountTime
,
fid
,
personChannelSerialNum
,
gateId
,
direction
,
personType
)).
build
()).
build
());
operationList
.
add
(
new
BulkOperation
.
Builder
().
index
(
new
IndexOperation
.
Builder
<
PersonInfo
>().
index
(
poolId
).
document
(
new
PersonInfo
(
unid
,
personId
,
null
,
feature
,
age
,
gender
,
bodyType
,
personCountTime
,
fid
,
personChannelSerialNum
,
gateId
,
direction
,
personType
)).
build
()).
build
());
}
}
}
}
}
}
...
@@ -402,7 +403,7 @@ public class PersonService {
...
@@ -402,7 +403,7 @@ public class PersonService {
feature
=
Arrays
.
copyOfRange
(
feature
,
3
,
Constant
.
BODY_FEATURE_DIMS_2048
+
3
);
feature
=
Arrays
.
copyOfRange
(
feature
,
3
,
Constant
.
BODY_FEATURE_DIMS_2048
+
3
);
}
}
SearchRequest
searchRequest
=
getSearchRequest
(
rid
,
poolId
,
1
,
feature
,
person
,
1
,
agg
);
SearchRequest
searchRequest
=
getSearchRequest
(
rid
,
poolId
,
size
,
feature
,
person
,
1
,
agg
);
matchResult
.
addAll
(
match0
(
searchRequest
,
agg
));
matchResult
.
addAll
(
match0
(
searchRequest
,
agg
));
}
}
...
@@ -473,6 +474,7 @@ public class PersonService {
...
@@ -473,6 +474,7 @@ public class PersonService {
KnnQuery
.
Builder
knnQuery
=
new
KnnQuery
.
Builder
();
KnnQuery
.
Builder
knnQuery
=
new
KnnQuery
.
Builder
();
if
(
null
!=
feature
&&
type
==
0
)
{
if
(
null
!=
feature
&&
type
==
0
)
{
knnQuery
.
field
(
"data"
).
queryVector
(
getFeature
(
feature
)).
numCandidates
(
Constant
.
FACE_MATCH_RESULT_SIZE
);
knnQuery
.
field
(
"data"
).
queryVector
(
getFeature
(
feature
)).
numCandidates
(
Constant
.
FACE_MATCH_RESULT_SIZE
);
queries
.
add
(
new
Query
.
Builder
().
exists
(
s
->
s
.
field
(
"data"
).
boost
(
1.0f
)).
build
());
}
else
if
(
null
!=
feature
&&
type
==
1
){
}
else
if
(
null
!=
feature
&&
type
==
1
){
knnQuery
.
field
(
"body"
).
queryVector
(
getFeature
(
feature
)).
numCandidates
(
Constant
.
BODY_MATCH_RESULT_SIZE
);
knnQuery
.
field
(
"body"
).
queryVector
(
getFeature
(
feature
)).
numCandidates
(
Constant
.
BODY_MATCH_RESULT_SIZE
);
queries
.
add
(
new
Query
.
Builder
().
exists
(
s
->
s
.
field
(
"body"
).
boost
(
1.0f
)).
build
());
queries
.
add
(
new
Query
.
Builder
().
exists
(
s
->
s
.
field
(
"body"
).
boost
(
1.0f
)).
build
());
...
@@ -517,26 +519,25 @@ public class PersonService {
...
@@ -517,26 +519,25 @@ public class PersonService {
private
SearchRequest
getSearchRequest
(
String
rid
,
String
poolId
,
Integer
matchResultSize
,
Double
[]
feature
,
Person
person
,
int
type
,
Boolean
agg
)
{
private
SearchRequest
getSearchRequest
(
String
rid
,
String
poolId
,
Integer
matchResultSize
,
Double
[]
feature
,
Person
person
,
int
type
,
Boolean
agg
)
{
// BoolQuery.Builder builder = getSearchSourceBuilder(feature, person, type);
// BoolQuery.Builder builder = getSearchSourceBuilder(feature, person, type);
Query
scriptScoreQuery
=
getScriptScoreQuery
(
feature
,
person
,
1
);
Query
scriptScoreQuery
=
getScriptScoreQuery
(
feature
,
person
,
1
);
SourceConfig
sourceConfig
=
new
SourceConfig
.
Builder
().
filter
(
s
->
s
.
includes
(
Arrays
.
asList
(
FETCH_SOURCE
))).
build
();
SearchRequest
.
Builder
searchRequest
=
new
SearchRequest
.
Builder
().
index
(
poolId
).
query
(
scriptScoreQuery
);
if
(
agg
)
{
if
(
agg
)
{
// AggregationBuilders.max("max_score", s -> s.field("_score").script(new Script.Builder().source("_score").build()));
// Aggregation aggregation = AggregationBuilders.max(s -> s.field("max_score").script(new Script.Builder().source("_score").build()));
// Aggregation termsAgg = AggregationBuilders.terms("by_personId", TermsAggregationDefinition.builder("by_personId").field("personId").order("max_score", false));
// Aggregation termsAgg2 = AggregationBuilders.terms(s -> s.field("personId").size(matchResultSize).size(matchResultSize));
// MaxAggregation.Builder maxBucketAggregation = new MaxAggregation.Builder().field("max_score").script(new Script.Builder().source("_score").build());
// TermsAggregation termsAgg = new TermsAggregation.Builder().field("personId").format("by_personId").size(matchResultSize).child(maxBucketAggregation);
// MetricAg
// termsAgg2.subAggregation(aggregation);
// termsAgg2.order(BucketOrder.aggregation("max_score", false));
// termsAgg.size(matchResultSize);
// MaxAggregationBuilder maxScoreAgg = AggregationBuilders.max("max_score").script(new Script("_score"));
// MaxAggregationBuilder maxScoreAgg = AggregationBuilders.max("max_score").script(new Script("_score"));
// TermsAggregationBuilder personIdAgg = AggregationBuilders.terms("by_personId").field("personId");
// TermsAggregationBuilder personIdAgg = AggregationBuilders.terms("by_personId").field("personId");
// personIdAgg.subAggregation(maxScoreAgg);
// personIdAgg.subAggregation(maxScoreAgg);
// personIdAgg.order(BucketOrder.aggregation("max_score", false));
// personIdAgg.order(BucketOrder.aggregation("max_score", false));
// personIdAgg.size(matchResultSize);
// personIdAgg.size(matchResultSize);
// builder.aggregation(personIdAgg);
// builder.aggregation(personIdAgg);
Script
script
=
new
Script
.
Builder
().
source
(
"_score"
).
build
();
Aggregation
maxAgg
=
AggregationBuilders
.
max
(
f
->
f
.
field
(
"_score"
).
script
(
script
));
Aggregation
termsAgg
=
new
Aggregation
.
Builder
()
.
terms
(
t
->
t
.
field
(
"personId"
).
size
(
matchResultSize
))
.
aggregations
(
"max_score"
,
maxAgg
)
.
build
();
searchRequest
.
aggregations
(
"by_personId"
,
termsAgg
).
size
(
0
);
}
else
{
}
else
{
// builder.size(matchResultSize);
// builder.size(matchResultSize);
searchRequest
.
source
(
sourceConfig
).
size
(
matchResultSize
);
}
}
Float
matchScore
=
null
;
Float
matchScore
=
null
;
Map
<
String
,
Float
>
poolMatchScoreMap
=
person
.
getPoolMatchScoreMap
();
Map
<
String
,
Float
>
poolMatchScoreMap
=
person
.
getPoolMatchScoreMap
();
...
@@ -546,11 +547,17 @@ public class PersonService {
...
@@ -546,11 +547,17 @@ public class PersonService {
if
(
matchScore
==
null
)
{
if
(
matchScore
==
null
)
{
matchScore
=
person
.
getBodyMinScore
();
matchScore
=
person
.
getBodyMinScore
();
}
}
SourceConfig
sourceConfig
=
new
SourceConfig
.
Builder
().
filter
(
s
->
s
.
includes
(
Arrays
.
asList
(
FETCH_SOURCE
))).
build
();
// log.debug("rid:{} poolId:{} 匹配时参数:{}", rid, poolId, scriptScoreQuery.toString());
// log.debug("rid:{} poolId:{} 匹配时参数:{}", rid, poolId, scriptScoreQuery.toString());
// KnnSearch knnQuery = getKnnSearch(feature, person, type);
// KnnSearch knnQuery = getKnnSearch(feature, person, type);
// ScriptScoreQuery scriptScoreQuery = getScriptScoreQuery(feature, person, type);
// ScriptScoreQuery scriptScoreQuery = getScriptScoreQuery(feature, person, type);
return
new
SearchRequest
.
Builder
().
index
(
poolId
).
query
(
scriptScoreQuery
).
source
(
sourceConfig
).
size
(
matchResultSize
).
minScore
(
matchScore
.
doubleValue
()/
100
).
build
();
double
minScore
=
0.0
;
if
(
type
==
0
)
{
minScore
=
person
.
getFaceMinScore
().
doubleValue
()/
100
;
}
else
if
(
type
==
1
)
{
minScore
=
person
.
getBodyMinScore
().
doubleValue
()/
100
;
}
return
searchRequest
.
minScore
(
minScore
).
build
();
}
}
private
List
<
Person
>
match0
(
SearchRequest
searchRequest
,
Boolean
agg
)
throws
Exception
{
private
List
<
Person
>
match0
(
SearchRequest
searchRequest
,
Boolean
agg
)
throws
Exception
{
...
...
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