This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 904e918d7 fix(search): wrong upper bound in reverse scan for infinity
(#3124)
904e918d7 is described below
commit 904e918d7bf684fff723ff7935ceaccd185a7c48
Author: zhenghaoz <[email protected]>
AuthorDate: Tue Aug 19 16:21:51 2025 +0800
fix(search): wrong upper bound in reverse scan for infinity (#3124)
Co-authored-by: Twice <[email protected]>
---
src/search/executors/numeric_field_scan_executor.h | 2 ++
tests/gocase/unit/search/search_test.go | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/src/search/executors/numeric_field_scan_executor.h
b/src/search/executors/numeric_field_scan_executor.h
index 3139fa5c2..9b1b4b20e 100644
--- a/src/search/executors/numeric_field_scan_executor.h
+++ b/src/search/executors/numeric_field_scan_executor.h
@@ -79,6 +79,8 @@ struct NumericFieldScanExecutor : ExecutorNode {
ctx->storage->GetCFHandle(ColumnFamilyID::Search));
if (scan->order == SortByClause::ASC) {
iter->Seek(IndexKey(scan->range.l));
+ } else if (scan->range.r == std::numeric_limits<double>::infinity()) {
+ iter->SeekForPrev(IndexKey(scan->range.r));
} else {
iter->SeekForPrev(IndexKey(IntervalSet::PrevNum(scan->range.r)));
}
diff --git a/tests/gocase/unit/search/search_test.go
b/tests/gocase/unit/search/search_test.go
index fef82260f..ff22bc928 100644
--- a/tests/gocase/unit/search/search_test.go
+++ b/tests/gocase/unit/search/search_test.go
@@ -23,6 +23,7 @@ import (
"bytes"
"context"
"encoding/binary"
+ "math"
"testing"
"time"
@@ -287,3 +288,24 @@ func TestSearchTag(t *testing.T) {
require.Equal(t, "testidx_case_insensitive:k2",
res.Val().([]interface{})[1])
})
}
+
+func TestSearchNumeric(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("FT.SEARCH reverse scan DBL_MAX", func(t *testing.T) {
+ require.NoError(t, rdb.Do(ctx, "FT.CREATE", "testidx_dbl_max",
"ON", "HASH", "PREFIX", "1", "testidx_dbl_max:", "SCHEMA", "a",
"NUMERIC").Err())
+ require.NoError(t, rdb.Do(ctx, "HSET", "testidx_dbl_max:k1",
"a", math.MaxFloat64).Err())
+
+ res := rdb.Do(ctx, "FT.SEARCH", "testidx_dbl_max", "*",
"SORTBY", "a", "DESC")
+ require.NoError(t, res.Err())
+ // result should be [1 testidx_dbl_max:k1 [a
1.7976931348623157e+308]]
+ require.Equal(t, 3, len(res.Val().([]interface{})))
+ require.Equal(t, int64(1), res.Val().([]interface{})[0])
+ require.Equal(t, "testidx_dbl_max:k1",
res.Val().([]interface{})[1])
+ })
+}