Skip to content

Commit 5e04c6a

Browse files
committed
Removed offset calculation in ObjectFieldDef and moved it to the AddDocumentHandler
1 parent a2d7cf4 commit 5e04c6a

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/main/java/com/yelp/nrtsearch/server/field/ObjectFieldDef.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ public void parseFieldWithChildren(
7676
int totalDocs = fieldValueMaps.size();
7777
List<Document> childDocuments = new ArrayList<>(totalDocs);
7878

79-
for (int i = 0; i < totalDocs; i++) {
80-
// Calculate offset as n-i (total docs minus current index)
81-
int offset = totalDocs - i;
82-
childDocuments.add(createChildDocument(fieldValueMaps.get(i), facetHierarchyPaths, offset));
79+
for (Map<String, Object> fieldValueMap : fieldValueMaps) {
80+
childDocuments.add(createChildDocument(fieldValueMap, facetHierarchyPaths));
8381
}
8482

8583
documentsContext.addChildDocuments(this.getName(), childDocuments);
@@ -91,18 +89,15 @@ public void parseFieldWithChildren(
9189
*
9290
* @param fieldValue the field value to include in the document
9391
* @param facetHierarchyPaths facet hierarchy paths
94-
* @param offset the offset value to set for this document (n-i)
9592
* @return lucene document
9693
*/
9794
private Document createChildDocument(
98-
Map<String, Object> fieldValue, List<List<String>> facetHierarchyPaths, int offset) {
95+
Map<String, Object> fieldValue, List<List<String>> facetHierarchyPaths) {
9996
Document document = new Document();
10097
parseFieldWithChildrenObject(document, List.of(fieldValue), facetHierarchyPaths);
10198
((IndexableFieldDef<?>) (IndexState.getMetaField(IndexState.NESTED_PATH)))
10299
.parseDocumentField(document, List.of(this.getName()), List.of());
103100

104-
((IndexableFieldDef<?>) (IndexState.getMetaField(IndexState.NESTED_DOCUMENT_OFFSET)))
105-
.parseDocumentField(document, List.of(String.valueOf(offset)), List.of());
106101
return document;
107102
}
108103

src/main/java/com/yelp/nrtsearch/server/handler/AddDocumentHandler.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,7 @@ private void updateNestedDocuments(
576576
e.getValue().stream().map(v -> handleFacets(indexState, shardState, v)).toList());
577577
}
578578

579-
// Add global offset calculation for all nested documents
580-
// addGlobalNestedDocumentOffsets(documents);
579+
addGlobalNestedDocumentOffsets(documents);
581580

582581
Document rootDoc = handleFacets(indexState, shardState, documentsContext.getRootDocument());
583582

@@ -612,8 +611,7 @@ private void addNestedDocuments(
612611
e.getValue().stream().map(v -> handleFacets(indexState, shardState, v)).toList());
613612
}
614613

615-
// Add global offset calculation for all nested documents
616-
// addGlobalNestedDocumentOffsets(documents);
614+
addGlobalNestedDocumentOffsets(documents);
617615

618616
Document rootDoc = handleFacets(indexState, shardState, documentsContext.getRootDocument());
619617
documents.add(rootDoc);
@@ -700,8 +698,13 @@ private Document handleFacets(IndexState indexState, ShardState shardState, Docu
700698
}
701699

702700
/**
703-
* Add global offset calculation for all nested documents This ensures unique offset values
704-
* across all nested fields in a document
701+
* Adds global offset values to nested documents for proper ordering and retrieval.
702+
*
703+
* <p>This method calculates and assigns a global offset to each nested document within a parent
704+
* document. The offset calculation uses reverse ordering (totalNestedDocs - currentIndex)
705+
*
706+
* @param nestedDocuments the list of nested documents to process; must not be null or empty
707+
* @throws IllegalArgumentException if nestedDocuments is null
705708
*/
706709
private void addGlobalNestedDocumentOffsets(List<Document> nestedDocuments) {
707710
int totalNestedDocs = nestedDocuments.size();

0 commit comments

Comments
 (0)