From 6bb1f79d494ccb35347b785421e54bccb588c42a Mon Sep 17 00:00:00 2001 From: congqixia Date: Mon, 8 Apr 2024 17:27:10 +0800 Subject: [PATCH] fix: Pass index type for Scalar indexes (#696) Related to #694 #695 --------- Signed-off-by: Congqi Xia --- entity/index_scalar.go | 6 +++++- entity/index_scalar_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/entity/index_scalar.go b/entity/index_scalar.go index a8c43a4a..ffaa5de9 100644 --- a/entity/index_scalar.go +++ b/entity/index_scalar.go @@ -7,7 +7,11 @@ type indexScalar struct { } func (i *indexScalar) Params() map[string]string { - return map[string]string{} + result := make(map[string]string) + if i.baseIndex.it != "" { + result[tIndexType] = string(i.baseIndex.it) + } + return result } func NewScalarIndex() Index { diff --git a/entity/index_scalar_test.go b/entity/index_scalar_test.go index 4107e8ff..5442f0d3 100644 --- a/entity/index_scalar_test.go +++ b/entity/index_scalar_test.go @@ -10,8 +10,16 @@ func TestScalarIndex(t *testing.T) { oldScalarIdx := NewScalarIndex() assert.EqualValues(t, "", oldScalarIdx.IndexType(), "use AUTO index when index type not provided") + _, has := oldScalarIdx.Params()[tIndexType] + assert.False(t, has) idxWithType := NewScalarIndexWithType(Sorted) assert.EqualValues(t, Sorted, idxWithType.IndexType()) + assert.EqualValues(t, Sorted, idxWithType.Params()[tIndexType]) + + idxWithType = NewScalarIndexWithType(Trie) + + assert.EqualValues(t, Trie, idxWithType.IndexType()) + assert.EqualValues(t, Trie, idxWithType.Params()[tIndexType]) }