Skip to content

Commit 85f21b6

Browse files
authored
search: Return a default_score with ft.info index definition (#5941)
* search: Add default_score with hardcoded value to ft.info Some clients expect this field to be present. Default score is not a part of data structures within the search family, but returning a value of 1 is a sensible default. * search: Add index_options field to FT.Info Signed-off-by: Abhijat Malviya <[email protected]>
1 parent 4e7b907 commit 85f21b6

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/server/search/search_family.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,20 +1203,25 @@ void SearchFamily::FtInfo(CmdArgList args, const CommandContext& cmd_cntx) {
12031203
const auto& info = infos.front();
12041204
const auto& schema = info.base_index.schema;
12051205

1206-
rb->StartCollection(4, RedisReplyBuilder::MAP);
1206+
rb->StartCollection(5, RedisReplyBuilder::MAP);
12071207

12081208
rb->SendSimpleString("index_name");
12091209
rb->SendSimpleString(idx_name);
12101210

12111211
rb->SendSimpleString("index_definition");
12121212
{
1213-
rb->StartCollection(2, RedisReplyBuilder::MAP);
1213+
rb->StartCollection(3, RedisReplyBuilder::MAP);
12141214
rb->SendSimpleString("key_type");
12151215
rb->SendSimpleString(info.base_index.type == DocIndex::JSON ? "JSON" : "HASH");
12161216
rb->SendSimpleString("prefix");
12171217
rb->SendSimpleString(info.base_index.prefix);
1218+
rb->SendSimpleString("default_score");
1219+
rb->SendLong(1);
12181220
}
12191221

1222+
rb->SendSimpleString("index_options");
1223+
rb->SendEmptyArray();
1224+
12201225
rb->SendSimpleString("attributes");
12211226
rb->StartArray(schema.fields.size());
12221227
for (const auto& [field_ident, field_info] : schema.fields) {

src/server/search/search_family_test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ TEST_F(SearchFamilyTest, InfoIndex) {
291291

292292
auto info = Run({"ft.info", "idx-1"});
293293
EXPECT_THAT(info,
294-
IsArray(_, _, _, IsArray("key_type", "HASH", "prefix", "doc-"), "attributes",
294+
IsArray(_, _, _, IsArray("key_type", "HASH", "prefix", "doc-", "default_score", 1),
295+
"index_options", RespArray(IsEmpty()), "attributes",
295296
IsArray(IsArray("identifier", "name", "attribute", "name", "type", "TEXT")),
296297
"num_docs", IntArg(15)));
297298
}
@@ -2773,7 +2774,7 @@ TEST_F(SearchFamilyTest, BlockSizeOptionFtCreate) {
27732774

27742775
// Verify that the index was created successfully
27752776
resp = Run({"FT.INFO", "index"});
2776-
EXPECT_THAT(resp, IsArray(_, _, _, _, "attributes",
2777+
EXPECT_THAT(resp, IsArray(_, _, _, _, _, _, "attributes",
27772778
IsUnordArray(IsArray("identifier", "number1", "attribute", "number1",
27782779
"type", "NUMERIC", "blocksize", "2"),
27792780
IsArray("identifier", "number2", "attribute", "number2",

tests/dragonfly/search_test.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
Search correctness should be ensured with unit tests.
44
"""
55

6-
import pytest
7-
from redis import asyncio as aioredis
8-
from .utility import *
9-
from . import dfly_args
106
import copy
117

128
import numpy as np
13-
14-
from redis.commands.search.query import Query
159
from redis.commands.search.field import TextField, NumericField, TagField, VectorField
1610
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
11+
from redis.commands.search.query import Query
12+
13+
from . import dfly_args
14+
from .utility import *
1715

1816
TEST_DATA = [
1917
{
@@ -130,15 +128,15 @@ async def test_management(async_client: aioredis.Redis):
130128
assert sorted(await async_client.execute_command("FT._LIST")) == ["i1", "i2"]
131129

132130
i1info = await i1.info()
133-
assert i1info["index_definition"] == ["key_type", "HASH", "prefix", "p1"]
131+
assert i1info["index_definition"] == ["key_type", "HASH", "prefix", "p1", "default_score", 1]
134132
assert i1info["num_docs"] == 10
135133
assert sorted(i1info["attributes"]) == [
136134
["identifier", "f1", "attribute", "f1", "type", "TEXT"],
137135
["identifier", "f2", "attribute", "f2", "type", "NUMERIC", "SORTABLE", "blocksize", "7000"],
138136
]
139137

140138
i2info = await i2.info()
141-
assert i2info["index_definition"] == ["key_type", "HASH", "prefix", "p2"]
139+
assert i2info["index_definition"] == ["key_type", "HASH", "prefix", "p2", "default_score", 1]
142140
assert i2info["num_docs"] == 15
143141
assert sorted(i2info["attributes"]) == [
144142
[

0 commit comments

Comments
 (0)