From a1d2d8c438ac22df82c32ad1400fbdd86d232a45 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Sun, 12 Feb 2017 20:18:33 +0200 Subject: Argh, none of these were inherited.... --- .../com/yahoo/searchdefinition/RankProfile.java | 28 +++++++++++++++------- .../searchdefinition/RankProfileTestCase.java | 11 ++++++--- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'config-model') diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java index 84504361d1f..c828f6beba3 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -55,7 +55,7 @@ public class RankProfile implements Serializable, Cloneable { private int minHitsPerThread = -1; private int numSearchPartitions = -1; - private double termwiseLimit = 1.0; + private Double termwiseLimit = null; /** The drop limit used to drop hits with rank score less than or equal to this value */ private double rankScoreDropLimit = -Double.MAX_VALUE; @@ -426,13 +426,15 @@ public class RankProfile implements Serializable, Cloneable { } public int getRerankCount() { - if (rerankCount>=0) return rerankCount; - if (getInherited()!=null) return getInherited().getRerankCount(); - return -1; + return (rerankCount < 0 && (getInherited() != null)) + ? getInherited().getRerankCount() + : rerankCount; } public int getNumThreadsPerSearch() { - return numThreadsPerSearch; + return (numThreadsPerSearch < 0 && (getInherited() != null)) + ? getInherited().getNumThreadsPerSearch() + : numThreadsPerSearch; } public void setNumThreadsPerSearch(int numThreads) { @@ -440,7 +442,9 @@ public class RankProfile implements Serializable, Cloneable { } public int getMinHitsPerThread() { - return minHitsPerThread; + return (minHitsPerThread < 0 && (getInherited() != null)) + ? getInherited().getMinHitsPerThread() + : minHitsPerThread; } public void setMinHitsPerThread(int minHits) { @@ -451,9 +455,17 @@ public class RankProfile implements Serializable, Cloneable { this.numSearchPartitions = numSearchPartitions; } - public int getNumSearchPartitions() { return numSearchPartitions; } + public int getNumSearchPartitions() { + return (numSearchPartitions < 0 && (getInherited() != null)) + ? getInherited().getNumSearchPartitions() + : numSearchPartitions; + } - public double getTermwiseLimit() { return termwiseLimit; } + public double getTermwiseLimit() { + return ((termwiseLimit == null) && (getInherited() != null)) + ? getInherited().getTermwiseLimit() + : (termwiseLimit != null) ? termwiseLimit : 1.0; + } public void setTermwiseLimit(double termwiseLimit) { this.termwiseLimit = termwiseLimit; } /** Sets the rerank count. Set to -1 to use inherited */ diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java index b2968eb4a85..b1bd5fd8a8d 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java @@ -58,7 +58,7 @@ public class RankProfileTestCase extends SearchDefinitionTestCase { } @Test - public void testTermwiseLimitAndSomeMore() throws ParseException { + public void testTermwiseLimitAndSomeMoreIncludingInheritance() throws ParseException { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); SearchBuilder builder = new SearchBuilder(rankProfileRegistry); builder.importString( @@ -75,16 +75,21 @@ public class RankProfileTestCase extends SearchDefinitionTestCase { " min-hits-per-thread:70\n" + " num-search-partitions:1200\n" + " }\n" + + " rank-profile child inherits parent { }" + "\n" + "}\n"); builder.build(); Search search = builder.getSearch(); - RankProfile rankProfile = rankProfileRegistry.getRankProfile(search, "parent"); + AttributeFields attributeFields = new AttributeFields(search); + verifyRankProfile(rankProfileRegistry.getRankProfile(search, "parent"), attributeFields); + verifyRankProfile(rankProfileRegistry.getRankProfile(search, "child"), attributeFields); + } + + private void verifyRankProfile(RankProfile rankProfile, AttributeFields attributeFields) { assertEquals(0.78, rankProfile.getTermwiseLimit(), 0.000001); assertEquals(8, rankProfile.getNumThreadsPerSearch()); assertEquals(70, rankProfile.getMinHitsPerThread()); assertEquals(1200, rankProfile.getNumSearchPartitions()); - AttributeFields attributeFields = new AttributeFields(search); RawRankProfile rawRankProfile = new RawRankProfile(rankProfile, attributeFields); assertTrue(findProperty(rawRankProfile.configProperties(), "vespa.matching.termwise_limit").isPresent()); assertEquals("0.78", findProperty(rawRankProfile.configProperties(), "vespa.matching.termwise_limit").get()); -- cgit v1.2.3