From 8eb9e9386596876d6ac0c6b643ba510f8e42df58 Mon Sep 17 00:00:00 2001 From: seakider Date: Tue, 21 Jan 2025 23:29:27 +0800 Subject: [PATCH] Fixed - search error with nocontent param Signed-off-by: seakider --- .../protocol/decoder/SearchResultDecoder.java | 10 ++++++--- .../java/org/redisson/RedissonSearchTest.java | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/redisson/src/main/java/org/redisson/client/protocol/decoder/SearchResultDecoder.java b/redisson/src/main/java/org/redisson/client/protocol/decoder/SearchResultDecoder.java index 8597fe573..300c92e4e 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/decoder/SearchResultDecoder.java +++ b/redisson/src/main/java/org/redisson/client/protocol/decoder/SearchResultDecoder.java @@ -40,10 +40,14 @@ public class SearchResultDecoder implements MultiDecoder { Long total = (Long) parts.get(0); List docs = new ArrayList<>(); if (total > 0) { - for (int i = 1; i < parts.size(); i += 2) { + for (int i = 1; i < parts.size(); i++) { String id = (String) parts.get(i); - Map attrs = (Map) parts.get(i + 1); - docs.add(new Document(id, attrs)); + if ((i + 1) < parts.size() && parts.get(i + 1) instanceof Map) { + Map attrs = (Map) parts.get(++i); + docs.add(new Document(id, attrs)); + } else { + docs.add(new Document(id)); + } } } diff --git a/redisson/src/test/java/org/redisson/RedissonSearchTest.java b/redisson/src/test/java/org/redisson/RedissonSearchTest.java index 14c98878e..cb70e5cac 100644 --- a/redisson/src/test/java/org/redisson/RedissonSearchTest.java +++ b/redisson/src/test/java/org/redisson/RedissonSearchTest.java @@ -49,6 +49,28 @@ public class RedissonSearchTest extends DockerRedisStackTest { } } + @Test + public void testSearchNoContent() { + RMap m = redisson.getMap("doc:1", new CompositeCodec(StringCodec.INSTANCE, redisson.getConfig().getCodec())); + m.put("t1", new SimpleObject("name1")); + m.put("t2", new SimpleObject("name2")); + + RMap m2 = redisson.getMap("doc:2", new CompositeCodec(StringCodec.INSTANCE, redisson.getConfig().getCodec())); + m2.put("t1", new SimpleObject("name3")); + m2.put("t2", new SimpleObject("name4")); + + RSearch s = redisson.getSearch(); + assertThat(s.getIndexes()).isEmpty(); + + s.createIndex("idx:1", IndexOptions.defaults() + .on(IndexType.HASH) + .prefix(Arrays.asList("doc:")), + FieldIndex.text("t1"), + FieldIndex.text("t2")); + + s.search("idx:1", "*", QueryOptions.defaults().noContent(true)); + } + @Test public void testMapAggregateWithCursor() { RMap m = redisson.getMap("doc:1", new CompositeCodec(StringCodec.INSTANCE, redisson.getConfig().getCodec()));