-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from Bit-Quill/dev-relevancy-improvements-rb1
Refactor RelevanceQuery -- add SingleFieldQuery and MultiFieldQuery base classes.
- Loading branch information
Showing
18 changed files
with
284 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MultiFieldQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Map; | ||
import org.opensearch.index.query.QueryBuilder; | ||
import org.opensearch.sql.expression.NamedArgumentExpression; | ||
|
||
/** | ||
* Base class to represent relevance queries that search multiple fields. | ||
* @param <T> The builder class for the OpenSearch query. | ||
*/ | ||
abstract class MultiFieldQuery<T extends QueryBuilder> extends RelevanceQuery<T> { | ||
|
||
public MultiFieldQuery(Map<String, QueryBuilderStep<T>> queryBuildActions) { | ||
super(queryBuildActions); | ||
} | ||
|
||
@Override | ||
public T createQueryBuilder(NamedArgumentExpression fields, NamedArgumentExpression queryExpr) { | ||
var fieldsAndWeights = fields | ||
.getValue() | ||
.valueOf(null) | ||
.tupleValue() | ||
.entrySet() | ||
.stream() | ||
.collect(ImmutableMap.toImmutableMap(e -> e.getKey(), e -> e.getValue().floatValue())); | ||
var query = queryExpr.getValue().valueOf(null).stringValue(); | ||
return createBuilder(fieldsAndWeights, query); | ||
} | ||
|
||
protected abstract T createBuilder(ImmutableMap<String, Float> fields, String query); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.