Fix exact matches to match previous behavior
This commit is contained in:
parent
a2765b0582
commit
f54b4b1d9d
31
BasicMap.go
31
BasicMap.go
@ -41,17 +41,8 @@ func (b *basicMapStorage) atleast(kind goimagehash.Kind, maxDistance int, search
|
||||
return matchingHashes
|
||||
}
|
||||
|
||||
func (b *basicMapStorage) GetMatches(hashes []Hash, max int, exactOnly bool) ([]Result, error) {
|
||||
var (
|
||||
foundMatches []Result
|
||||
tl timeLog
|
||||
)
|
||||
tl.resetTime()
|
||||
defer tl.logTime(fmt.Sprintf("Search Complete: max: %v ExactOnly: %v", max, exactOnly))
|
||||
b.hashMutex.RLock()
|
||||
defer b.hashMutex.RUnlock()
|
||||
|
||||
if exactOnly { // exact matches are also found by partial matches. Don't bother with exact matches so we don't have to de-duplicate
|
||||
func (b *basicMapStorage) exactMatches(hashes []Hash, max int) []Result {
|
||||
var foundMatches []Result
|
||||
for _, hash := range hashes {
|
||||
mappedIds := map[*[]ID]bool{}
|
||||
|
||||
@ -73,11 +64,27 @@ func (b *basicMapStorage) GetMatches(hashes []Hash, max int, exactOnly bool) ([]
|
||||
}
|
||||
|
||||
}
|
||||
return foundMatches
|
||||
}
|
||||
|
||||
func (b *basicMapStorage) GetMatches(hashes []Hash, max int, exactOnly bool) ([]Result, error) {
|
||||
var (
|
||||
foundMatches []Result
|
||||
tl timeLog
|
||||
)
|
||||
tl.resetTime()
|
||||
defer tl.logTime(fmt.Sprintf("Search Complete: max: %v ExactOnly: %v", max, exactOnly))
|
||||
b.hashMutex.RLock()
|
||||
defer b.hashMutex.RUnlock()
|
||||
|
||||
if exactOnly { // exact matches are also found by partial matches. Don't bother with exact matches so we don't have to de-duplicate
|
||||
foundMatches = b.exactMatches(hashes, max)
|
||||
|
||||
tl.logTime("Search Exact")
|
||||
|
||||
if len(foundMatches) > 0 {
|
||||
return foundMatches, nil
|
||||
}
|
||||
}
|
||||
|
||||
foundHashes := make(map[uint64]struct{})
|
||||
totalPartialHashes := 0
|
||||
|
9
map.go
9
map.go
@ -23,8 +23,13 @@ func (m *MapStorage) GetMatches(hashes []Hash, max int, exactOnly bool) ([]Resul
|
||||
m.hashMutex.RLock()
|
||||
defer m.hashMutex.RUnlock()
|
||||
|
||||
if exactOnly {
|
||||
return m.basicMapStorage.GetMatches(hashes, max, exactOnly)
|
||||
if exactOnly { // exact matches are also found by partial matches. Don't bother with exact matches so we don't have to de-duplicate
|
||||
foundMatches = m.exactMatches(hashes, max)
|
||||
|
||||
tl.logTime("Search Exact")
|
||||
if len(foundMatches) > 0 {
|
||||
return foundMatches, nil
|
||||
}
|
||||
}
|
||||
tl.resetTime()
|
||||
defer tl.logTime("Search Complete")
|
||||
|
@ -150,8 +150,11 @@ func (s *sqliteStorage) GetMatches(hashes []Hash, max int, exactOnly bool) ([]Re
|
||||
})
|
||||
}
|
||||
|
||||
tl.logTime("Search Exact")
|
||||
if len(foundMatches) > 0 {
|
||||
return foundMatches, nil
|
||||
}
|
||||
}
|
||||
|
||||
foundHashes := make(map[uint64]struct{})
|
||||
|
||||
|
@ -69,7 +69,7 @@ func (v *VPTree) GetMatches(hashes []Hash, max int, exactOnly bool) ([]Result, e
|
||||
}
|
||||
}
|
||||
}
|
||||
if exactOnly {
|
||||
if exactOnly && len(exactMatches) > 0 {
|
||||
return exactMatches, nil
|
||||
}
|
||||
exactMatches = append(exactMatches, matches...)
|
||||
|
Loading…
x
Reference in New Issue
Block a user