@@ -39,23 +39,14 @@ public class SegmentDocLookup implements Map<String, LoadedDocValues<?>> {
39
39
private final Function <String , FieldDef > fieldDefLookup ;
40
40
private final LeafReaderContext context ;
41
41
private final Map <String , LoadedDocValues <?>> loaderCache = new HashMap <>();
42
- private final String queryNestedPath ;
43
42
44
43
private int docId = -1 ;
45
44
private int parentDocId = -1 ;
46
45
private SegmentDocLookup parentLookup = null ;
47
46
48
47
public SegmentDocLookup (Function <String , FieldDef > fieldDefLookup , LeafReaderContext context ) {
49
- this (fieldDefLookup , context , null );
50
- }
51
-
52
- public SegmentDocLookup (
53
- Function <String , FieldDef > fieldDefLookup ,
54
- LeafReaderContext context ,
55
- String queryNestedPath ) {
56
48
this .fieldDefLookup = fieldDefLookup ;
57
49
this .context = context ;
58
- this .queryNestedPath = queryNestedPath ;
59
50
}
60
51
61
52
/**
@@ -82,7 +73,7 @@ public boolean isEmpty() {
82
73
83
74
/**
84
75
* Check if a given field name is capable of having doc values. This does not mean there is data
85
- * present, just that there can be.
76
+ * present, just that there can be. Handles "_PARENT." prefix for parent field access.
86
77
*
87
78
* @param key field name
88
79
* @return if this field may have stored doc values
@@ -94,6 +85,10 @@ public boolean containsKey(Object key) {
94
85
}
95
86
String fieldName = key .toString ();
96
87
88
+ if (fieldName .startsWith ("_PARENT." )) {
89
+ fieldName = fieldName .substring ("_PARENT." .length ());
90
+ }
91
+
97
92
try {
98
93
FieldDef field = fieldDefLookup .apply (fieldName );
99
94
return field instanceof IndexableFieldDef && ((IndexableFieldDef <?>) field ).hasDocValues ();
@@ -112,7 +107,7 @@ public boolean containsValue(Object value) {
112
107
* cache. The data is loaded for the current set document id.
113
108
*
114
109
* <p>The system automatically determines if a field requires parent document access based on the
115
- * current nested path . Fields are resolved automatically without requiring explicit notation .
110
+ * "_PARENT." prefix in the field name . Fields with this prefix will access the parent document .
116
111
*
117
112
* @param key field name
118
113
* @return {@link LoadedDocValues} implementation for the given field
@@ -125,18 +120,16 @@ public LoadedDocValues<?> get(Object key) {
125
120
Objects .requireNonNull (key );
126
121
String fieldName = key .toString ();
127
122
128
- if ((!IndexState .ROOT .equals (queryNestedPath ))) {
129
- int parentLevels = computeParentLevels (queryNestedPath , fieldName );
130
- if (parentLevels > 0 ) {
131
- SegmentDocLookup currentLookup = getParentLookup ();
132
- if (currentLookup == null ) {
133
- throw new IllegalArgumentException (
134
- "Could not access parent field: "
135
- + fieldName
136
- + " (document may not be nested or parent field may not exist)" );
137
- }
138
- return currentLookup .get (fieldName );
123
+ if (fieldName .startsWith ("_PARENT." )) {
124
+ String actualFieldName = fieldName .substring ("_PARENT." .length ());
125
+ SegmentDocLookup parentLookup = getParentLookup ();
126
+ if (parentLookup == null ) {
127
+ throw new IllegalArgumentException (
128
+ "Could not access parent field: "
129
+ + fieldName
130
+ + " (document may not be nested or parent field may not exist)" );
139
131
}
132
+ return parentLookup .get (actualFieldName );
140
133
}
141
134
142
135
LoadedDocValues <?> docValues = loaderCache .get (fieldName );
@@ -222,52 +215,6 @@ private int getParentDocId() {
222
215
return docId + offset ;
223
216
}
224
217
225
- /** Computes the number of parent levels to traverse to access a field. */
226
- private static int computeParentLevels (String currentNestedPath , String targetFieldPath ) {
227
- if (currentNestedPath == null
228
- || currentNestedPath .isEmpty ()
229
- || IndexState .ROOT .equals (currentNestedPath )) {
230
- return -1 ; // Field is at current level or below
231
- }
232
-
233
- if (targetFieldPath .startsWith (currentNestedPath + "." )
234
- || targetFieldPath .equals (currentNestedPath )) {
235
- return -1 ; // Field is at current level or below
236
- }
237
-
238
- String [] currentPathParts = currentNestedPath .split ("\\ ." );
239
- String [] targetPathParts = targetFieldPath .split ("\\ ." );
240
-
241
- // Find common prefix
242
- int commonPrefixLength = 0 ;
243
- int minLength = Math .min (currentPathParts .length , targetPathParts .length );
244
- for (int i = 0 ; i < minLength ; i ++) {
245
- if (currentPathParts [i ].equals (targetPathParts [i ])) {
246
- commonPrefixLength ++;
247
- } else {
248
- break ;
249
- }
250
- }
251
-
252
- int levelsUp = currentPathParts .length - commonPrefixLength ;
253
-
254
- // TODO - Enable support for more than one level of nesting
255
- if (levelsUp > 1 ) {
256
- throw new IllegalArgumentException (
257
- "Field access requires "
258
- + levelsUp
259
- + " parent levels, but only 1 level of nesting is supported. "
260
- + "Field: "
261
- + targetFieldPath
262
- + ", Current path: "
263
- + currentNestedPath );
264
- }
265
-
266
- // If we need to go up to access the field, return the number of levels
267
- // If levelsUp is 0, it means the field is at the same level or below
268
- return levelsUp > 0 ? levelsUp : -1 ;
269
- }
270
-
271
218
@ Override
272
219
public LoadedDocValues <?> put (String key , LoadedDocValues <?> value ) {
273
220
throw new UnsupportedOperationException ();
0 commit comments