Skip to content

Commit

Permalink
I think it makes sense to expose when a literal match is found. This …
Browse files Browse the repository at this point in the history
…might also help prevent false positives
  • Loading branch information
Dynom committed Jul 7, 2018
1 parent 9272acc commit f0b5c33
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion server/http.go
Expand Up @@ -40,6 +40,7 @@ type tySugRequest struct {
type tySugResponse struct {
Result string `json:"result"`
Score float64 `json:"score"`
Exact bool `json:"exact_match"`
}

type pprofConfig struct {
Expand Down Expand Up @@ -183,7 +184,7 @@ func createRequestHandler(logger *logrus.Logger, svc Service, validators []Valid
var res tySugResponse

start := time.Now()
res.Result, res.Score = svc.Find(ctx, req.Input)
res.Result, res.Score, res.Exact = svc.Find(ctx, req.Input)

ctxLogger.WithFields(logrus.Fields{
"input": req.Input,
Expand Down
2 changes: 1 addition & 1 deletion server/service.go
Expand Up @@ -4,5 +4,5 @@ import "context"

// Service is the type any service must implement
type Service interface {
Find(ctx context.Context, input string) (string, float64)
Find(ctx context.Context, input string) (string, float64, bool)
}
6 changes: 3 additions & 3 deletions server/service/domain.go
Expand Up @@ -33,9 +33,9 @@ type Service struct {
}

// Find returns the nearest reference
func (s Service) Find(ctx context.Context, input string) (string, float64) {
suggestion, score, _ := s.finder.FindCtx(ctx, input)
return suggestion, score
func (s Service) Find(ctx context.Context, input string) (string, float64, bool) {
suggestion, score, exact := s.finder.FindCtx(ctx, input)
return suggestion, score, exact
}

func algJaroWinkler() finder.Algorithm {
Expand Down
4 changes: 2 additions & 2 deletions server/service_registry_test.go
Expand Up @@ -8,8 +8,8 @@ import (
type stubSvc struct {
}

func (stubSvc) Find(ctx context.Context, input string) (string, float64) {
return "", 0
func (stubSvc) Find(ctx context.Context, input string) (string, float64, bool) {
return "", 0, true
}

func TestHasServiceForList(t *testing.T) {
Expand Down

0 comments on commit f0b5c33

Please sign in to comment.