Skip to content

Commit b394fce

Browse files
Copilotanidotnet
andcommitted
Fix EqualsFilter to handle compound indexes correctly
The numeric path in applyOnIndex now properly handles both single-field indexes (List) and compound indexes (NavigableMap) using processIndexValue. This fixes the test failures in CollectionCompoundIndexTest.testIssue178 and RepositorySearchTest.testFindByEntityId. Co-authored-by: anidotnet <696662+anidotnet@users.noreply.github.com>
1 parent 69212c0 commit b394fce

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

nitrite/src/main/java/org/dizitart/no2/filters/EqualsFilter.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,25 @@ public boolean apply(Pair<NitriteId, Document> element) {
4343

4444
@Override
4545
public List<?> applyOnIndex(IndexMap indexMap) {
46-
List<NitriteId> nitriteIds = new ArrayList<>();
47-
4846
// If value is a Number, we need to check for numeric equivalents across types
4947
// Otherwise, use fast direct lookup
5048
if (getValue() instanceof Number) {
5149
// Scan for all numerically equivalent values
50+
List<java.util.NavigableMap<Comparable<?>, Object>> subMaps = new ArrayList<>();
51+
List<NitriteId> nitriteIds = new ArrayList<>();
52+
5253
for (Pair<Comparable<?>, ?> entry : indexMap.entries()) {
5354
if (deepEquals(getValue(), entry.getFirst())) {
5455
Object entryValue = entry.getSecond();
55-
if (entryValue instanceof List) {
56-
@SuppressWarnings("unchecked")
57-
List<NitriteId> result = (List<NitriteId>) entryValue;
58-
nitriteIds.addAll(result);
59-
}
56+
// Handle both single-field indexes (List) and compound indexes (NavigableMap)
57+
processIndexValue(entryValue, subMaps, nitriteIds);
6058
}
6159
}
60+
61+
// Return sub-maps for compound indexes, or nitrite IDs for single-field indexes
62+
if (!subMaps.isEmpty()) {
63+
return subMaps;
64+
}
6265
return nitriteIds;
6366
}
6467

0 commit comments

Comments
 (0)