From 4f2994d9301034e943620e106540fa80a6c3f01e Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 21 Apr 2022 15:56:41 +0200 Subject: Resolve rank profile inputs --- .../java/com/yahoo/search/config/RankProfile.java | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 container-search/src/main/java/com/yahoo/search/config/RankProfile.java (limited to 'container-search/src/main/java/com/yahoo/search/config/RankProfile.java') diff --git a/container-search/src/main/java/com/yahoo/search/config/RankProfile.java b/container-search/src/main/java/com/yahoo/search/config/RankProfile.java new file mode 100644 index 00000000000..944a23f2964 --- /dev/null +++ b/container-search/src/main/java/com/yahoo/search/config/RankProfile.java @@ -0,0 +1,94 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.search.config; + +import com.yahoo.tensor.TensorType; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Information about a rank profile + * + * @author bratseth + */ +public class RankProfile { + + private final String name; + private final boolean hasSummaryFeatures; + private final boolean hasRankFeatures; + private final Map inputs; + + private RankProfile(Builder builder) { + this.name = builder.name; + this.hasSummaryFeatures = builder.hasSummaryFeatures; + this.hasRankFeatures = builder.hasRankFeatures; + this.inputs = Map.copyOf(builder.inputs); + } + + public String name() { return name; } + + /** Returns true if this rank profile has summary features. */ + public boolean hasSummaryFeatures() { return hasSummaryFeatures; } + + /** Returns true if this rank profile has rank features. */ + public boolean hasRankFeatures() { return hasRankFeatures; } + + /** Returns the inputs explicitly declared in this rank profile. */ + public Map inputs() { return inputs; } + + @Override + public boolean equals(Object o) { + if (o == this) return true; + if ( ! (o instanceof RankProfile)) return false; + RankProfile other = (RankProfile)o; + if ( ! other.name.equals(this.name)) return false; + if ( other.hasSummaryFeatures != this.hasSummaryFeatures) return false; + if ( other.hasRankFeatures != this.hasRankFeatures) return false; + if ( ! other.inputs.equals(this.inputs)) return false; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(name, hasSummaryFeatures, hasRankFeatures, inputs); + } + + @Override + public String toString() { + return "rank profile '" + name + "'"; + } + + public static class Builder { + + private final String name; + private boolean hasSummaryFeatures = true; + private boolean hasRankFeatures = true; + private final Map inputs = new HashMap<>(); + + public Builder(String name) { + this.name = Objects.requireNonNull(name); + } + + public Builder setHasSummaryFeatures(boolean hasSummaryFeatures) { + this.hasSummaryFeatures = hasSummaryFeatures; + return this; + } + + public Builder setHasRankFeatures(boolean hasRankFeatures) { + this.hasRankFeatures = hasRankFeatures; + return this; + } + + public Builder addInput(String name, TensorType type) { + inputs.put(name, type); + return this; + } + + public RankProfile build() { + return new RankProfile(this); + } + + } + +} -- cgit v1.2.3