From 40105e6b7e251dc3f4a0647e3418f733e59800bc Mon Sep 17 00:00:00 2001 From: tidwall Date: Tue, 30 Mar 2021 11:49:01 -0700 Subject: [PATCH] Include "distance" to output when user specifically requests fixes #599 --- internal/server/fence.go | 11 ++++++----- internal/server/scanner.go | 5 +++-- internal/server/search.go | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/server/fence.go b/internal/server/fence.go index fdb1dbeb..6cf11faf 100644 --- a/internal/server/fence.go +++ b/internal/server/fence.go @@ -172,11 +172,12 @@ func fenceMatch( sw.fullFields = true sw.msg.OutputType = JSON sw.writeObject(ScanWriterParams{ - id: details.id, - o: details.obj, - fields: details.fields, - noLock: true, - distance: distance, + id: details.id, + o: details.obj, + fields: details.fields, + noLock: true, + distance: distance, + distOutput: fence.distance, }) if sw.wr.Len() == 0 { diff --git a/internal/server/scanner.go b/internal/server/scanner.go index 994ec82e..7742b89d 100644 --- a/internal/server/scanner.go +++ b/internal/server/scanner.go @@ -66,6 +66,7 @@ type ScanWriterParams struct { o geojson.Object fields []float64 distance float64 + distOutput bool // query or fence requested distance output noLock bool ignoreGlobMatch bool clip geojson.Object @@ -433,7 +434,7 @@ func (sw *scanWriter) writeObject(opts ScanWriterParams) bool { wr.WriteString(jsfields) - if opts.distance > 0 { + if opts.distOutput || opts.distance > 0 { wr.WriteString(`,"distance":` + strconv.FormatFloat(opts.distance, 'f', -1, 64)) } @@ -496,7 +497,7 @@ func (sw *scanWriter) writeObject(opts ScanWriterParams) bool { vals = append(vals, resp.ArrayValue(fvals)) } } - if opts.distance > 0 { + if opts.distOutput || opts.distance > 0 { vals = append(vals, resp.FloatValue(opts.distance)) } diff --git a/internal/server/search.go b/internal/server/search.go index 96f9d461..f37961f7 100644 --- a/internal/server/search.go +++ b/internal/server/search.go @@ -380,6 +380,7 @@ func (server *Server) cmdNearby(msg *Message) (res resp.Value, err error) { o: o, fields: fields, distance: meters, + distOutput: s.distance, noLock: true, ignoreGlobMatch: true, skipTesting: true,