Skip to content

Commit 2b1da1e

Browse files
authored
Merge pull request #36299 from vespa-engine/arnej/allow-marking-hit-as-fulfilled
Add setUnfillable() API on Hit
2 parents c1d9031 + 8928816 commit 2b1da1e

5 files changed

Lines changed: 30 additions & 8 deletions

File tree

container-search/abi-spec.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8640,6 +8640,7 @@
86408640
"public void setCached(boolean)",
86418641
"public boolean isCached()",
86428642
"public void setFillable()",
8643+
"public void setUnfillable()",
86438644
"public void setFilled(java.lang.String)",
86448645
"public boolean isFillable()",
86458646
"public java.util.Set getFilled()",
@@ -8746,6 +8747,7 @@
87468747
"public void analyze()",
87478748
"public com.yahoo.search.result.HitGroup clone()",
87488749
"public void setFillable()",
8750+
"public void setUnfillable()",
87498751
"public void setFilled(java.lang.String)",
87508752
"public boolean isFillable()",
87518753
"public java.util.Set getFilled()",

container-search/src/main/java/com/yahoo/search/grouping/vespa/GroupingExecutor.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,8 @@ public void fill(Result result, String summaryClass, Execution execution) {
154154
Hit hit = it.next();
155155
if (hit.getSearcherSpecificMetaData(this) instanceof String metaDataString) {
156156
if (hit.isFilled(metaDataString)) {
157-
hit.setFilled(null);
158-
// TODO: the above should have been enough
159-
hit.setFilled(summaryClass);
160-
// we could in theory also clear SearcherSpecificMetaData here,
161-
// but there's no gain and some risk involved.
157+
// mark as fully filled:
158+
hit.setUnfillable();
162159
}
163160
}
164161
}

container-search/src/main/java/com/yahoo/search/result/Hit.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ public void setRelevance(double relevance) {
329329
* summaries. This also enables tracking of which summary classes
330330
* have been used for filling so far. Invoking this method
331331
* multiple times is allowed and will have no addition
332-
* effect. Note that a fillable hit may not be made unfillable.
332+
* effect. Call setUnfillable() if there is no more data fill()
333+
* can obtain for that hit.
333334
*/
334335
public void setFillable() {
335336
if (filled == null) {
@@ -339,6 +340,14 @@ public void setFillable() {
339340
}
340341
}
341342

343+
/**
344+
* Tag this hit as no longer fillable.
345+
*/
346+
public void setUnfillable() {
347+
filled = null;
348+
unmodifiableFilled = null;
349+
}
350+
342351
/**
343352
* Register that this hit has been filled with properties using
344353
* the given summary class. Note that this method will implicitly
@@ -354,7 +363,6 @@ public void setFilled(String summaryClass) {
354363
} else if (filled.size() == 1) {
355364
filled = new HashSet<>(filled);
356365
unmodifiableFilled = Collections.unmodifiableSet(filled);
357-
358366
filled.add(summaryClass);
359367
} else {
360368
filled.add(summaryClass);
@@ -600,7 +608,7 @@ public Object getSearcherSpecificMetaData(Searcher searcher) {
600608

601609
final void setFilledInternal(Set<String> filled) {
602610
this.filled = filled;
603-
unmodifiableFilled = (filled != null) ? Collections.unmodifiableSet(filled) : null;
611+
unmodifiableFilled = (filled == null) ? null : Collections.unmodifiableSet(filled);
604612
}
605613

606614
/**

container-search/src/main/java/com/yahoo/search/result/HitGroup.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,16 @@ public HitGroup clone() {
864864
return hitGroupClone;
865865
}
866866

867+
/** Ignored as this should always be derived from the content hits */
867868
@Override
868869
public void setFillable() {}
869870

871+
/** This does not make sense for a HitGroup, must be done on the content hits */
872+
@Override
873+
public void setUnfillable() {
874+
throw new IllegalArgumentException("calling setUnfillable() on a HitGroup does not make sense, it needs to be called on its individual hits");
875+
}
876+
870877
/** Ignored as this should always be derived from the content hits */
871878
@Override
872879
public void setFilled(String summaryClass) {}

container-search/src/test/java/com/yahoo/prelude/fastsearch/PartialSummaryHandlerTestCase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ void testFillNull() {
4343
assertTrue(hit1.isFilled(null));
4444
assertTrue(hit1.isFilled("default"));
4545
assertEquals(1, result.hits().getFilled().size());
46+
assertTrue(result.hits().isFilled(null));
47+
assertFalse(result.hits().isFilled("foobar"));
48+
hit2.setUnfillable();
49+
assertTrue(result.hits().isFilled("default"));
50+
assertTrue(result.hits().isFilled(null));
51+
assertFalse(result.hits().isFilled("foobar"));
52+
hit1.setUnfillable();
53+
assertTrue(result.hits().isFilled("foobar"));
4654
}
4755

4856
@Test

0 commit comments

Comments
 (0)