Skip to content

Commit

Permalink
[patch] fix duplicated search result
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
  • Loading branch information
kpango committed Sep 25, 2020
1 parent 583f275 commit 0c72ab7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/gateway/vald/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,13 @@ func (s *server) search(ctx context.Context, cfg *payload.Search_Config,
return nil
}
id := dist.GetId()
mu.RLock()
mu.Lock()
if !visited[id] {
mu.RUnlock()
mu.Lock()
visited[id] = true
mu.Unlock()
dch <- dist
} else {
mu.RUnlock()
mu.Unlock()
}
// if !cl.Exists(id) {
// dch <- dist
Expand Down Expand Up @@ -219,9 +217,12 @@ func (s *server) search(ctx context.Context, cfg *payload.Search_Config,
}
return res, nil
case dist := <-dch:
if len(res.GetResults()) >= num &&
dist.GetDistance() < math.Float32frombits(atomic.LoadUint32(&maxDist)) {
atomic.StoreUint32(&maxDist, math.Float32bits(dist.GetDistance()))
if len(res.GetResults()) >= num {
if dist.GetDistance() < math.Float32frombits(atomic.LoadUint32(&maxDist)) {
atomic.StoreUint32(&maxDist, math.Float32bits(dist.GetDistance()))
} else {
continue
}
}
switch len(res.GetResults()) {
case 0:
Expand Down

0 comments on commit 0c72ab7

Please sign in to comment.