Skip to content

Commit

Permalink
Fix disabling phash distance checks
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash committed Jan 14, 2025
1 parent c9fc7ec commit 5ec5613
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/sqlx/querybuilder_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ func (qb *sceneQueryBuilder) FindByFullFingerprints(fingerprints []*models.Finge
JOIN scene_fingerprints SFP ON SFP.fingerprint_id = FP.id
`

distance := config.GetPHashDistance()

var phashes []int64
var hashes []string
for _, fp := range fingerprints {
if fp.Algorithm == models.FingerprintAlgorithmPhash {
if fp.Algorithm == models.FingerprintAlgorithmPhash && distance > 0 {
// Postgres only supports signed integers, so we parse
// as uint64 and cast to int64 to ensure values are the same.
value, err := strconv.ParseUint(fp.Hash, 16, 64)
Expand All @@ -215,7 +217,7 @@ func (qb *sceneQueryBuilder) FindByFullFingerprints(fingerprints []*models.Finge
arg := map[string]interface{}{
"phashes": phashes,
"hashes": hashes,
"distance": config.GetPHashDistance(),
"distance": distance,
}

query := `
Expand Down Expand Up @@ -275,10 +277,12 @@ func (qb *sceneQueryBuilder) FindIdsBySceneFingerprints(fingerprints []*models.F
GROUP BY scene_id, phash
`

distance := config.GetPHashDistance()

var phashes []int64
var hashes []string
for _, fp := range fingerprints {
if fp.Algorithm == models.FingerprintAlgorithmPhash {
if fp.Algorithm == models.FingerprintAlgorithmPhash && distance > 0 {
// Postgres only supports signed integers, so we parse
// as uint64 and cast to int64 to ensure values are the same.
value, err := strconv.ParseUint(fp.Hash, 16, 64)
Expand All @@ -304,7 +308,7 @@ func (qb *sceneQueryBuilder) FindIdsBySceneFingerprints(fingerprints []*models.F
arg := map[string]interface{}{
"phashes": phashes,
"hashes": hashes,
"distance": config.GetPHashDistance(),
"distance": distance,
}

query := strings.Join(clauses, " UNION ")
Expand Down

0 comments on commit 5ec5613

Please sign in to comment.