Skip to content

Commit

Permalink
Short circuit count=0 and cutoff=true
Browse files Browse the repository at this point in the history
Change-Id: If46ffeff677e8d28fedfd24a664d6a7833f810a0
  • Loading branch information
Akron committed Oct 28, 2024
1 parent 776976b commit 5a74896
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.63.3 2024-09-24
- [performance] Improve short circuit on count=0 and
cutoff=true (diewald)

0.63.2 2024-08-02
- [bugfix] Fix empty DocIdSetIterator (margaretha)
- [bugfix] Don't throw warnings on expansion failure (diewald)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<groupId>de.ids-mannheim.korap.krill</groupId>
<artifactId>Krill</artifactId>
<version>0.63.2</version>
<version>0.63.3</version>
<packaging>jar</packaging>

<name>Krill</name>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/ids_mannheim/korap/KrillIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,12 @@ public Result search (Krill ks) {
return kr;
};

if (cutoff && count == 0) {
kr.setTotalResults(-1);
kr.setTotalResources(-1);
return kr;
};

// Collect matches from atomic readers
final ArrayList<Match> atomicMatches = new ArrayList<Match>(
kr.getItemsPerPage());
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/de/ids_mannheim/korap/search/TestKrill.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,20 @@ public void searchIndex () throws IOException {
assertEquals(kr.getItemsPerPage(), 0);
assertEquals(kr.getMatches().size(), 0);

// Handle count=0 correctly
meta = ks.getMeta();
meta.setCount(0);
meta.setCutOff(true);

kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), -1);
assertEquals(kr.getItemsPerPage(), 0);
assertEquals(kr.getMatches().size(), 0);

// Handle tokens=true and
// snippet=false correctly
meta = ks.getMeta();
meta.setCutOff(false);
meta.setCount(1);
meta.setTokens(true);
meta.setSnippets(false);
Expand Down

0 comments on commit 5a74896

Please sign in to comment.