aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/federation
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorn.christian@seime.no>2022-12-02 14:52:26 +0100
committerGitHub <noreply@github.com>2022-12-02 14:52:26 +0100
commit81b884ac555806ae2f0a75773accfd8fe27ecbe1 (patch)
tree0f92b9ef73a90854cacc96796562d3f21ff1cff6 /container-search/src/main/java/com/yahoo/search/federation
parentc956ac4cb73b329243072aabe35f0da508c02d0f (diff)
Revert "Let list handling catch up with Java 17"
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/federation')
-rw-r--r--container-search/src/main/java/com/yahoo/search/federation/FederationResult.java11
-rw-r--r--container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java24
-rw-r--r--container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.java8
3 files changed, 34 insertions, 9 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/federation/FederationResult.java b/container-search/src/main/java/com/yahoo/search/federation/FederationResult.java
index 89c45fde6ae..f6cbb49f7d5 100644
--- a/container-search/src/main/java/com/yahoo/search/federation/FederationResult.java
+++ b/container-search/src/main/java/com/yahoo/search/federation/FederationResult.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.federation;
+import com.google.common.collect.ImmutableList;
import com.yahoo.search.Result;
import com.yahoo.search.searchchain.FutureResult;
@@ -26,9 +27,9 @@ class FederationResult {
* The remaining targets to wait for.
* Other targets are either complete, or should only be included if they are available when we complete
*/
- private final List<TargetResult> targetsToWaitFor;
+ private List<TargetResult> targetsToWaitFor;
- private FederationResult(List<TargetResult> targetResults) {
+ private FederationResult(ImmutableList<TargetResult> targetResults) {
this.targetResults = targetResults;
if (targetResults.stream().anyMatch(TargetResult::isMandatory))
@@ -93,7 +94,7 @@ class FederationResult {
public Optional<Result> getIfAvailable(long timeout) {
if (availableResult.isPresent()) return availableResult;
availableResult = futureResult.getIfAvailable(timeout, TimeUnit.MILLISECONDS);
- availableResult.ifPresent(target::modifyTargetResult);
+ availableResult.ifPresent(result -> target.modifyTargetResult(result));
return availableResult;
}
@@ -120,14 +121,14 @@ class FederationResult {
public static class Builder {
- private final List<TargetResult> results = new ArrayList<>();
+ private final ImmutableList.Builder<TargetResult> results = new ImmutableList.Builder();
public void add(FederationSearcher.Target target, FutureResult futureResult) {
results.add(new TargetResult(target, futureResult));
}
public FederationResult build() {
- return new FederationResult(List.copyOf(results));
+ return new FederationResult(results.build());
}
}
diff --git a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java
index 80a41ffdf22..21b4d1d538f 100644
--- a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java
+++ b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.federation;
+import com.google.common.collect.ImmutableList;
import com.yahoo.component.annotation.Inject;
import com.yahoo.collections.Pair;
import com.yahoo.component.ComponentId;
@@ -9,6 +10,7 @@ import com.yahoo.component.chain.Chain;
import com.yahoo.component.chain.dependencies.After;
import com.yahoo.component.chain.dependencies.Provides;
import com.yahoo.component.provider.ComponentRegistry;
+import com.yahoo.concurrent.CopyOnWriteHashMap;
import com.yahoo.errorhandling.Results;
import com.yahoo.errorhandling.Results.Builder;
import com.yahoo.prelude.IndexFacts;
@@ -26,6 +28,7 @@ import com.yahoo.search.federation.sourceref.SourceRefResolver;
import com.yahoo.search.federation.sourceref.SourcesTarget;
import com.yahoo.search.federation.sourceref.UnresolvedSearchChainException;
import com.yahoo.search.query.Properties;
+import com.yahoo.search.query.properties.SubProperties;
import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.result.Hit;
import com.yahoo.search.result.HitGroup;
@@ -74,9 +77,11 @@ public class FederationSearcher extends ForkingSearcher {
public final static CompoundName PROVIDERNAME = new CompoundName("providerName");
public static final String FEDERATION = "Federation";
public static final String LOG_COUNT_PREFIX = "count_";
+ private static final List<CompoundName> queryAndHits = ImmutableList.of(Query.OFFSET, Query.HITS);
private final SearchChainResolver searchChainResolver;
private final SourceRefResolver sourceRefResolver;
+ private final CopyOnWriteHashMap<CompoundKey, CompoundName> map = new CopyOnWriteHashMap<>();
private final TargetSelector<?> targetSelector;
private final Clock clock = Clock.systemUTC();
@@ -333,6 +338,22 @@ public class FederationSearcher extends ForkingSearcher {
return commentedSearchChains;
}
+ /**
+ * Returns the set of properties set for the source or provider given in the query (if any).
+ *
+ * If the query has not set sourceName or providerName, null will be returned
+ */
+ public static Properties getSourceProperties(Query query) {
+ String sourceName = query.properties().getString(SOURCENAME);
+ String providerName = query.properties().getString(PROVIDERNAME);
+ if (sourceName == null || providerName == null)
+ return null;
+ Properties sourceProperties = new SubProperties("source." + sourceName, query.properties());
+ Properties providerProperties = new SubProperties("provider." + providerName, query.properties());
+ sourceProperties.chain(providerProperties);
+ return sourceProperties;
+ }
+
@Override
public void fill(Result result, String summaryClass, Execution execution) {
UniqueExecutionsToResults uniqueExecutionsToResults = new UniqueExecutionsToResults();
@@ -641,8 +662,9 @@ public class FederationSearcher extends ForkingSearcher {
@Override
public boolean equals(Object o) {
if (o == this) return true;
- if ( ! (o instanceof StandardTarget other)) return false;
+ if ( ! ( o instanceof StandardTarget)) return false;
+ StandardTarget other = (StandardTarget)o;
if ( ! Objects.equals(other.chain.getId(), this.chain.getId())) return false;
if ( ! Objects.equals(other.target, this.target)) return false;
return true;
diff --git a/container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.java b/container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.java
index f432289d2c1..34eeb3ce82c 100644
--- a/container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.java
+++ b/container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.federation.sourceref;
+import com.google.common.collect.ImmutableList;
import com.yahoo.component.ComponentId;
import com.yahoo.search.searchchain.model.federation.FederationOptions;
@@ -23,7 +24,7 @@ public class SearchChainInvocationSpec implements Cloneable {
public final ComponentId provider;
public final FederationOptions federationOptions;
- public final List<String> documentTypes;
+ public final ImmutableList<String> documentTypes;
SearchChainInvocationSpec(ComponentId searchChainId,
ComponentId source, ComponentId provider, FederationOptions federationOptions,
@@ -32,7 +33,7 @@ public class SearchChainInvocationSpec implements Cloneable {
this.source = source;
this.provider = provider;
this.federationOptions = federationOptions;
- this.documentTypes = List.copyOf(documentTypes);
+ this.documentTypes = ImmutableList.copyOf(documentTypes);
}
@Override
@@ -43,8 +44,9 @@ public class SearchChainInvocationSpec implements Cloneable {
@Override
public boolean equals(Object o) {
if (o == this) return true;
- if ( ! (o instanceof SearchChainInvocationSpec other)) return false;
+ if ( ! ( o instanceof SearchChainInvocationSpec)) return false;
+ SearchChainInvocationSpec other = (SearchChainInvocationSpec)o;
if ( ! Objects.equals(this.searchChainId, other.searchChainId)) return false;
if ( ! Objects.equals(this.source, other.source)) return false;
if ( ! Objects.equals(this.provider, other.provider)) return false;