diff --git a/src/main/java/org/opensearch/knn/index/query/KNNWeight.java b/src/main/java/org/opensearch/knn/index/query/KNNWeight.java index d24075aa5..c166be3c2 100644 --- a/src/main/java/org/opensearch/knn/index/query/KNNWeight.java +++ b/src/main/java/org/opensearch/knn/index/query/KNNWeight.java @@ -116,7 +116,7 @@ public Scorer scorer(LeafReaderContext context) throws IOException { * . Hence, if filtered results are less than K and filter query is present we should shift to exact search. * This improves the recall. */ - if (filterWeight != null && canDoExactSearch(filterIdsArray.length, getTotalDocsInSegment(context))) { + if (filterWeight != null && canDoExactSearch(filterIdsArray.length)) { docIdsToScoreMap.putAll(doExactSearch(context, filterIdsArray)); } else { Map annResults = doANNSearch(context, filterIdsArray); @@ -380,10 +380,9 @@ private SpaceType getSpaceType(final FieldInfo fieldInfo) { ); } - private boolean canDoExactSearch(final int filterIdsCount, final int searchableDocs) { + private boolean canDoExactSearch(final int filterIdsCount) { log.debug( - "Info for doing exact search Live Docs: {}, filterIdsLength : {}, Threshold value: {}", - searchableDocs, + "Info for doing exact search filterIdsLength : {}, Threshold value: {}", filterIdsCount, KNNSettings.getFilteredExactSearchThreshold(knnQuery.getIndexName()) ); @@ -420,12 +419,4 @@ private boolean isExactSearchThresholdSettingSet(int filterThresholdValue) { private boolean canDoExactSearchAfterANNSearch(final int filterIdsCount, final int annResultCount) { return filterWeight != null && filterIdsCount >= knnQuery.getK() && knnQuery.getK() > annResultCount; } - - private int getTotalDocsInSegment(final LeafReaderContext context) { - // This means that there is no deleted documents, hence the live docs bitset is null - if (context.reader().getLiveDocs() == null) { - return context.reader().maxDoc(); - } - return context.reader().getLiveDocs().length(); - } } diff --git a/src/test/java/org/opensearch/knn/index/query/KNNWeightTests.java b/src/test/java/org/opensearch/knn/index/query/KNNWeightTests.java index 628bdf091..ba6675d3d 100644 --- a/src/test/java/org/opensearch/knn/index/query/KNNWeightTests.java +++ b/src/test/java/org/opensearch/knn/index/query/KNNWeightTests.java @@ -425,7 +425,6 @@ public void testANNWithFilterQuery_whenExactSearch_thenSuccess() { final Bits liveDocsBits = mock(Bits.class); when(reader.getLiveDocs()).thenReturn(liveDocsBits); when(liveDocsBits.get(filterDocId)).thenReturn(true); - when(liveDocsBits.length()).thenReturn(1000); final KNNWeight knnWeight = new KNNWeight(query, 0.0f, filterQueryWeight); final Map attributesMap = ImmutableMap.of(KNN_ENGINE, KNNEngine.FAISS.getName(), SPACE_TYPE, SpaceType.L2.name()); @@ -476,7 +475,6 @@ public void testANNWithFilterQuery_whenExactSearchAndThresholdComputations_thenS final Bits liveDocsBits = mock(Bits.class); when(reader.getLiveDocs()).thenReturn(liveDocsBits); when(liveDocsBits.get(filterDocId)).thenReturn(true); - when(liveDocsBits.length()).thenReturn(1000); final KNNWeight knnWeight = new KNNWeight(query, 0.0f, filterQueryWeight); final Map attributesMap = ImmutableMap.of(KNN_ENGINE, KNNEngine.FAISS.getName(), SPACE_TYPE, SpaceType.L2.name());