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
|
return matchingHashes
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *basicMapStorage) GetMatches(hashes []Hash, max int, exactOnly bool) ([]Result, error) {
|
func (b *basicMapStorage) exactMatches(hashes []Hash, max int) []Result {
|
||||||
var (
|
var foundMatches []Result
|
||||||
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
|
|
||||||
for _, hash := range hashes {
|
for _, hash := range hashes {
|
||||||
mappedIds := map[*[]ID]bool{}
|
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")
|
tl.logTime("Search Exact")
|
||||||
|
if len(foundMatches) > 0 {
|
||||||
return foundMatches, nil
|
return foundMatches, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foundHashes := make(map[uint64]struct{})
|
foundHashes := make(map[uint64]struct{})
|
||||||
totalPartialHashes := 0
|
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()
|
m.hashMutex.RLock()
|
||||||
defer m.hashMutex.RUnlock()
|
defer m.hashMutex.RUnlock()
|
||||||
|
|
||||||
if 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
|
||||||
return m.basicMapStorage.GetMatches(hashes, max, exactOnly)
|
foundMatches = m.exactMatches(hashes, max)
|
||||||
|
|
||||||
|
tl.logTime("Search Exact")
|
||||||
|
if len(foundMatches) > 0 {
|
||||||
|
return foundMatches, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tl.resetTime()
|
tl.resetTime()
|
||||||
defer tl.logTime("Search Complete")
|
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
|
return foundMatches, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foundHashes := make(map[uint64]struct{})
|
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
|
return exactMatches, nil
|
||||||
}
|
}
|
||||||
exactMatches = append(exactMatches, matches...)
|
exactMatches = append(exactMatches, matches...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user