aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java')
-rw-r--r--config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java131
1 files changed, 77 insertions, 54 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java b/config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java
index df71e30c7d9..4026341464f 100644
--- a/config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java
@@ -3,49 +3,58 @@ package com.yahoo.schema;
import com.yahoo.search.query.ranking.Diversity;
import com.yahoo.schema.parser.ParseException;
+import com.yahoo.vespa.model.test.utils.DeployLoggerStub;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author baldersheim
*/
public class DiversityTestCase {
- @Test
- void testDiversity() throws ParseException {
+ private static void verifyDiversity(DeployLoggerStub logger, boolean atRankProfile, boolean atMatchPhase) throws ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
- ApplicationBuilder builder = new ApplicationBuilder(rankProfileRegistry);
+ ApplicationBuilder builder = new ApplicationBuilder(logger, rankProfileRegistry);
+ String diversitySpec = """
+ diversity {
+ attribute: b
+ min-groups: 74
+ cutoff-factor: 17.3
+ cutoff-strategy: strict
+ }
+ """;
builder.addSchema(
- "search test {\n" +
- " document test { \n" +
- " field a type int { \n" +
- " indexing: attribute \n" +
- " attribute: fast-search\n" +
- " }\n" +
- " field b type int {\n" +
- " indexing: attribute \n" +
- " }\n" +
- " }\n" +
- " \n" +
- " rank-profile parent {\n" +
- " match-phase {\n" +
- " diversity {\n" +
- " attribute: b\n" +
- " min-groups: 74\n" +
- " cutoff-factor: 17.3\n" +
- " cutoff-strategy: strict" +
- " }\n" +
- " attribute: a\n" +
- " max-hits: 120\n" +
- " max-filter-coverage: 0.065" +
- " }\n" +
- " }\n" +
- "}\n");
+ """
+ search test {
+ document test {
+ field a type int {
+ indexing: attribute
+ attribute: fast-search
+ }
+ field b type int {
+ indexing: attribute
+ }
+ }
+ rank-profile parent {
+ match-phase {""" +
+ (atMatchPhase ? diversitySpec : "") +
+ """
+ attribute: a
+ max-hits: 120
+ max-filter-coverage: 0.065
+ }""" +
+ (atRankProfile ? diversitySpec : "") +
+ """
+ }
+ }
+ """);
builder.build(true);
Schema s = builder.getSchema();
- RankProfile.MatchPhaseSettings matchPhase = rankProfileRegistry.get(s, "parent").getMatchPhaseSettings();
- RankProfile.DiversitySettings diversity = matchPhase.getDiversity();
+ RankProfile parent = rankProfileRegistry.get(s, "parent");
+ RankProfile.MatchPhaseSettings matchPhase = parent.getMatchPhase();
+ RankProfile.DiversitySettings diversity = parent.getDiversity();
assertEquals("b", diversity.getAttribute());
assertEquals(74, diversity.getMinGroups());
assertEquals(17.3, diversity.getCutoffFactor(), 1e-16);
@@ -54,6 +63,21 @@ public class DiversityTestCase {
assertEquals("a", matchPhase.getAttribute());
assertEquals(0.065, matchPhase.getMaxFilterCoverage(), 1e-16);
}
+ @Test
+ void testDiversity() throws ParseException {
+ DeployLoggerStub logger = new DeployLoggerStub();
+ verifyDiversity(logger, true, false);
+ assertTrue(logger.entries.isEmpty());
+ verifyDiversity(logger, false, true);
+ assertEquals(1, logger.entries.size());
+ assertEquals("'diversity is deprecated inside 'match-phase'. Specify it at 'rank-profile' level.", logger.entries.get(0).message);
+ try {
+ verifyDiversity(logger, true, true);
+ fail("Should throw.");
+ } catch (Exception e) {
+ assertEquals("rank-profile 'parent' error: already has diversity", e.getMessage());
+ }
+ }
private static String getMessagePrefix() {
return "In search definition 'test', rank-profile 'parent': diversity attribute 'b' ";
@@ -82,30 +106,29 @@ public class DiversityTestCase {
assertEquals(getMessagePrefix() + "must be single value numeric, or enumerated attribute, but it is 'Array<int>'", e.getMessage());
}
}
- private ApplicationBuilder getSearchBuilder(String diversity) throws ParseException {
- RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
- ApplicationBuilder builder = new ApplicationBuilder(rankProfileRegistry);
- builder.addSchema(
- "search test {\n" +
- " document test { \n" +
- " field a type int { \n" +
- " indexing: attribute \n" +
- " attribute: fast-search\n" +
- " }\n" +
- diversity +
- " }\n" +
- " \n" +
- " rank-profile parent {\n" +
- " match-phase {\n" +
- " diversity {\n" +
- " attribute: b\n" +
- " min-groups: 74\n" +
- " }\n" +
- " attribute: a\n" +
- " max-hits: 120\n" +
- " }\n" +
- " }\n" +
- "}\n");
+ private ApplicationBuilder getSearchBuilder(String diversityField) throws ParseException {
+ ApplicationBuilder builder = new ApplicationBuilder(new RankProfileRegistry());
+ builder.addSchema("""
+ search test {
+ document test {
+ field a type int {
+ indexing: attribute
+ attribute: fast-search
+ }""" +
+ diversityField +
+ """
+ }
+ rank-profile parent {
+ match-phase {
+ attribute: a
+ max-hits: 120
+ }
+ diversity {
+ attribute: b
+ min-groups: 74
+ }
+ }
+ }""");
return builder;
}
}