Skip to content

Commit 19c328e

Browse files
committed
Details of Normalization
Signed-off-by: Varun Jain <varunudr@amazon.com>
1 parent 8999dfd commit 19c328e

24 files changed

+2031
-38
lines changed

server/src/main/java/org/opensearch/node/Node.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@
239239
import org.opensearch.search.deciders.ConcurrentSearchRequestDecider;
240240
import org.opensearch.search.fetch.FetchPhase;
241241
import org.opensearch.search.pipeline.SearchPipelineService;
242-
import org.opensearch.search.query.HybridQueryExecutor;
243242
import org.opensearch.search.query.QueryPhase;
244243
import org.opensearch.snapshots.InternalSnapshotsInfoService;
245244
import org.opensearch.snapshots.RestoreService;
@@ -1053,7 +1052,7 @@ protected Node(
10531052
// Add the telemetryAwarePlugin components to the existing pluginComponents collection.
10541053
pluginComponents.addAll(telemetryAwarePluginComponents);
10551054

1056-
//HybridQueryExecutor.initialize(threadPool);
1055+
// HybridQueryExecutor.initialize(threadPool);
10571056
List<IdentityAwarePlugin> identityAwarePlugins = pluginsService.filterPlugins(IdentityAwarePlugin.class);
10581057
identityService.initializeIdentityAwarePlugins(identityAwarePlugins);
10591058

server/src/main/java/org/opensearch/search/SearchModule.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@
261261
import org.opensearch.search.query.HybridQueryPhaseSearcher;
262262
import org.opensearch.search.query.QueryPhase;
263263
import org.opensearch.search.query.QueryPhaseSearcher;
264-
import org.opensearch.search.query.QueryPhaseSearcherWrapper;
265264
import org.opensearch.search.rescore.QueryRescorerBuilder;
266265
import org.opensearch.search.rescore.RescorerBuilder;
267266
import org.opensearch.search.sort.FieldSortBuilder;
@@ -1175,9 +1174,7 @@ private void registerQueryParsers(List<SearchPlugin> plugins) {
11751174
registerQuery(
11761175
new QuerySpec<>(MatchBoolPrefixQueryBuilder.NAME, MatchBoolPrefixQueryBuilder::new, MatchBoolPrefixQueryBuilder::fromXContent)
11771176
);
1178-
registerQuery(
1179-
new QuerySpec<>(HybridQueryBuilder.NAME, HybridQueryBuilder::new, HybridQueryBuilder::fromXContent)
1180-
);
1177+
registerQuery(new QuerySpec<>(HybridQueryBuilder.NAME, HybridQueryBuilder::new, HybridQueryBuilder::fromXContent));
11811178
registerQuery(new QuerySpec<>(TemplateQueryBuilder.NAME, TemplateQueryBuilder::new, TemplateQueryBuilder::fromXContent));
11821179
if (ShapesAvailability.JTS_AVAILABLE && ShapesAvailability.SPATIAL4J_AVAILABLE) {
11831180
registerQuery(new QuerySpec<>(GeoShapeQueryBuilder.NAME, GeoShapeQueryBuilder::new, GeoShapeQueryBuilder::fromXContent));
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.search.pipeline;
10+
11+
import org.opensearch.action.search.SearchPhaseContext;
12+
import org.opensearch.action.search.SearchPhaseResults;
13+
import org.opensearch.search.SearchPhaseResult;
14+
import org.opensearch.search.internal.SearchContext;
15+
16+
import java.util.Optional;
17+
18+
/**
19+
* Base class for all score hybridization processors. This class is responsible for executing the score hybridization process.
20+
* It is a pipeline processor that is executed after the query phase and before the fetch phase.
21+
*/
22+
public abstract class AbstractScoreHybridizationProcessor implements SearchPhaseResultsProcessor {
23+
/**
24+
* Method abstracts functional aspect of score normalization and score combination. Exact methods for each processing stage
25+
* are set as part of class constructor. This method is called when there is no pipeline context
26+
* @param searchPhaseResult {@link SearchPhaseResults} DTO that has query search results. Results will be mutated as part of this method execution
27+
* @param searchPhaseContext {@link SearchContext}
28+
*/
29+
@Override
30+
public <Result extends SearchPhaseResult> void process(
31+
final SearchPhaseResults<Result> searchPhaseResult,
32+
final SearchPhaseContext searchPhaseContext
33+
) {
34+
hybridizeScores(searchPhaseResult, searchPhaseContext, Optional.empty());
35+
}
36+
37+
/**
38+
* Method abstracts functional aspect of score normalization and score combination. Exact methods for each processing stage
39+
* are set as part of class constructor. This method is called when there is pipeline context
40+
* @param searchPhaseResult {@link SearchPhaseResults} DTO that has query search results. Results will be mutated as part of this method execution
41+
* @param searchPhaseContext {@link SearchContext}
42+
* @param requestContext {@link PipelineProcessingContext} processing context of search pipeline
43+
* @param <Result>
44+
*/
45+
@Override
46+
public <Result extends SearchPhaseResult> void process(
47+
final SearchPhaseResults<Result> searchPhaseResult,
48+
final SearchPhaseContext searchPhaseContext,
49+
final PipelineProcessingContext requestContext
50+
) {
51+
hybridizeScores(searchPhaseResult, searchPhaseContext, Optional.ofNullable(requestContext));
52+
}
53+
54+
/**
55+
* Method abstracts functional aspect of score normalization and score combination. Exact methods for each processing stage
56+
* are set as part of class constructor
57+
* @param searchPhaseResult
58+
* @param searchPhaseContext
59+
* @param requestContextOptional
60+
* @param <Result>
61+
*/
62+
abstract <Result extends SearchPhaseResult> void hybridizeScores(
63+
SearchPhaseResults<Result> searchPhaseResult,
64+
SearchPhaseContext searchPhaseContext,
65+
Optional<PipelineProcessingContext> requestContextOptional
66+
);
67+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.search.pipeline;
10+
11+
import org.apache.logging.log4j.LogManager;
12+
import org.apache.logging.log4j.Logger;
13+
import org.apache.lucene.search.Sort;
14+
import org.opensearch.common.Nullable;
15+
import org.opensearch.search.query.QuerySearchResult;
16+
17+
import java.util.List;
18+
19+
import reactor.util.annotation.NonNull;
20+
21+
public class CombineScoresDto {
22+
private static final Logger log = LogManager.getLogger(CombineScoresDto.class);
23+
24+
public CombineScoresDto(
25+
@NonNull List<CompoundTopDocs> queryTopDocs,
26+
@NonNull ScoreCombinationTechnique scoreCombinationTechnique,
27+
@NonNull List<QuerySearchResult> querySearchResults,
28+
@Nullable Sort sort,
29+
int fromValueForSingleShard
30+
) {
31+
this.queryTopDocs = queryTopDocs;
32+
this.fromValueForSingleShard = fromValueForSingleShard;
33+
this.sort = sort;
34+
this.querySearchResults = querySearchResults;
35+
this.scoreCombinationTechnique = scoreCombinationTechnique;
36+
}
37+
38+
public int getFromValueForSingleShard() {
39+
return fromValueForSingleShard;
40+
}
41+
42+
@Nullable
43+
public Sort getSort() {
44+
return sort;
45+
}
46+
47+
@NonNull
48+
public List<QuerySearchResult> getQuerySearchResults() {
49+
return querySearchResults;
50+
}
51+
52+
@NonNull
53+
public ScoreCombinationTechnique getScoreCombinationTechnique() {
54+
return scoreCombinationTechnique;
55+
}
56+
57+
@NonNull
58+
public List<CompoundTopDocs> getQueryTopDocs() {
59+
return queryTopDocs;
60+
}
61+
62+
@NonNull
63+
private List<CompoundTopDocs> queryTopDocs;
64+
@NonNull
65+
private ScoreCombinationTechnique scoreCombinationTechnique;
66+
@NonNull
67+
private List<QuerySearchResult> querySearchResults;
68+
@Nullable
69+
private Sort sort;
70+
private int fromValueForSingleShard;
71+
72+
public static CombineScoresDtoBuilder builder() {
73+
return new CombineScoresDtoBuilder();
74+
}
75+
76+
public static class CombineScoresDtoBuilder {
77+
private List<CompoundTopDocs> queryTopDocs;
78+
private ScoreCombinationTechnique scoreCombinationTechnique;
79+
private List<QuerySearchResult> querySearchResults;
80+
private Sort sort;
81+
private int fromValueForSingleShard;
82+
83+
public CombineScoresDtoBuilder scoreCombinationTechnique(ScoreCombinationTechnique scoreCombinationTechnique) {
84+
this.scoreCombinationTechnique = scoreCombinationTechnique;
85+
return this;
86+
}
87+
88+
public CombineScoresDtoBuilder querySearchResults(@NonNull List<QuerySearchResult> querySearchResults) {
89+
this.querySearchResults = querySearchResults;
90+
return this;
91+
}
92+
93+
public CombineScoresDtoBuilder sort(@Nullable Sort sort) {
94+
this.sort = sort;
95+
return this;
96+
}
97+
98+
public CombineScoresDtoBuilder fromValueForSingleShard(int fromValueForSingleShard) {
99+
this.fromValueForSingleShard = fromValueForSingleShard;
100+
return this;
101+
}
102+
103+
public CombineScoresDtoBuilder queryTopDocs(List<CompoundTopDocs> queryTopDocs) {
104+
this.queryTopDocs = queryTopDocs;
105+
return this;
106+
}
107+
108+
public CombineScoresDto build() {
109+
return new CombineScoresDto(queryTopDocs, scoreCombinationTechnique, querySearchResults, sort, fromValueForSingleShard);
110+
}
111+
}
112+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.search.pipeline;
10+
11+
public class CombinedExplanationDetails {
12+
public CombinedExplanationDetails(ExplanationDetails normalizationExplanations, ExplanationDetails combinationExplanations) {
13+
this.normalizationExplanations = normalizationExplanations;
14+
this.combinationExplanations = combinationExplanations;
15+
}
16+
17+
public ExplanationDetails getNormalizationExplanations() {
18+
return normalizationExplanations;
19+
}
20+
21+
public ExplanationDetails getCombinationExplanations() {
22+
return combinationExplanations;
23+
}
24+
25+
private ExplanationDetails normalizationExplanations;
26+
private ExplanationDetails combinationExplanations;
27+
28+
public static CombineExplanationDetailsBuilder builder() {
29+
return new CombineExplanationDetailsBuilder();
30+
}
31+
32+
public static class CombineExplanationDetailsBuilder {
33+
private ExplanationDetails normalizationExplanations;
34+
private ExplanationDetails combinationExplanations;
35+
36+
public CombineExplanationDetailsBuilder normalizationExplanations(ExplanationDetails normalizationExplanations) {
37+
this.normalizationExplanations = normalizationExplanations;
38+
return this;
39+
}
40+
41+
public CombineExplanationDetailsBuilder combinationExplanations(ExplanationDetails combinationExplanations) {
42+
this.combinationExplanations = combinationExplanations;
43+
return this;
44+
}
45+
46+
public CombinedExplanationDetails build() {
47+
return new CombinedExplanationDetails(normalizationExplanations, combinationExplanations);
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)