Skip to content

Commit f8ded2f

Browse files
committed
fix: handle @NumericIndexed in nested classes within metamodel generator (#613)
1 parent a8b6af6 commit f8ded2f

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

redis-om-spring/src/main/java/com/redis/om/spring/metamodel/MetamodelGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,9 @@ private List<Triple<ObjectGraphFieldSpec, FieldSpec, CodeBlock>> processNestedIn
636636

637637
enclosedFields.forEach((field, getter) -> {
638638
boolean fieldIsIndexed = (field.getAnnotation(Indexed.class) != null) || (field.getAnnotation(
639-
Searchable.class) != null);
639+
Searchable.class) != null) || (field.getAnnotation(NumericIndexed.class) != null) || (field.getAnnotation(
640+
TagIndexed.class) != null) || (field.getAnnotation(TextIndexed.class) != null) || (field.getAnnotation(
641+
GeoIndexed.class) != null) || (field.getAnnotation(VectorIndexed.class) != null);
640642
boolean generateMetamodel = field.getAnnotation(Metamodel.class) != null;
641643

642644
if (fieldIsIndexed || generateMetamodel) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.redis.om.spring.annotations.document;
2+
3+
import com.redis.om.spring.AbstractBaseDocumentTest;
4+
import com.redis.om.spring.fixtures.document.model.AddressWithNumericIndexed;
5+
import com.redis.om.spring.fixtures.document.model.ValidDocumentIndexedNestedWithNumericIndexed;
6+
import com.redis.om.spring.fixtures.document.model.ValidDocumentIndexedNestedWithNumericIndexed$;
7+
import com.redis.om.spring.fixtures.document.repository.ValidDocumentIndexedNestedWithNumericIndexedRepository;
8+
import com.redis.om.spring.search.stream.EntityStream;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
13+
import java.util.List;
14+
import java.util.stream.Collectors;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
class NumericIndexedNestedTest extends AbstractBaseDocumentTest {
19+
20+
@Autowired
21+
ValidDocumentIndexedNestedWithNumericIndexedRepository repository;
22+
23+
@Autowired
24+
EntityStream entityStream;
25+
26+
@BeforeEach
27+
void setup() {
28+
repository.deleteAll();
29+
}
30+
31+
@Test
32+
void testNestedNumericIndexedMetamodelGeneration() {
33+
// Test that the metamodel is generated correctly for nested @NumericIndexed fields
34+
35+
// Create test data
36+
ValidDocumentIndexedNestedWithNumericIndexed doc = ValidDocumentIndexedNestedWithNumericIndexed.of("doc1");
37+
AddressWithNumericIndexed address = new AddressWithNumericIndexed();
38+
address.setStreet("123 Main St");
39+
address.setCity("Anytown");
40+
address.setZipCode(12345);
41+
doc.setAddress(address);
42+
43+
repository.save(doc);
44+
45+
// Test that we can query using the metamodel
46+
// This should work if the metamodel is generated correctly
47+
List<ValidDocumentIndexedNestedWithNumericIndexed> results = entityStream
48+
.of(ValidDocumentIndexedNestedWithNumericIndexed.class)
49+
.filter(ValidDocumentIndexedNestedWithNumericIndexed$.ADDRESS_ZIP_CODE.eq(12345))
50+
.collect(Collectors.toList());
51+
52+
assertThat(results).hasSize(1);
53+
assertThat(results.get(0).getAddress().getZipCode()).isEqualTo(12345);
54+
}
55+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.redis.om.spring.fixtures.document.model;
2+
3+
import com.redis.om.spring.annotations.NumericIndexed;
4+
import lombok.Data;
5+
6+
@Data
7+
public class AddressWithNumericIndexed {
8+
private String street;
9+
private String city;
10+
11+
@NumericIndexed
12+
private Integer zipCode;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.redis.om.spring.fixtures.document.model;
2+
3+
import com.redis.om.spring.annotations.Document;
4+
import com.redis.om.spring.annotations.Indexed;
5+
import lombok.Data;
6+
import lombok.NonNull;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.data.annotation.Id;
9+
10+
@Data
11+
@RequiredArgsConstructor(staticName = "of")
12+
@Document
13+
public class ValidDocumentIndexedNestedWithNumericIndexed {
14+
15+
@Id
16+
@NonNull
17+
private String id;
18+
19+
@Indexed
20+
private AddressWithNumericIndexed address;
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.redis.om.spring.fixtures.document.repository;
2+
3+
import com.redis.om.spring.fixtures.document.model.ValidDocumentIndexedNestedWithNumericIndexed;
4+
import com.redis.om.spring.repository.RedisDocumentRepository;
5+
6+
public interface ValidDocumentIndexedNestedWithNumericIndexedRepository extends RedisDocumentRepository<ValidDocumentIndexedNestedWithNumericIndexed, String> {
7+
}

0 commit comments

Comments
 (0)