forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com>
- Loading branch information
1 parent
444eefd
commit 6c480be
Showing
12 changed files
with
201 additions
and
154 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
89 changes: 89 additions & 0 deletions
89
core/src/main/java/org/opensearch/sql/expression/ScoreExpression.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,89 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.expression; | ||
|
||
import lombok.Getter; | ||
import org.opensearch.sql.common.utils.StringUtils; | ||
import org.opensearch.sql.data.model.ExprNullValue; | ||
import org.opensearch.sql.data.model.ExprTupleValue; | ||
import org.opensearch.sql.data.model.ExprValue; | ||
import org.opensearch.sql.data.model.ExprValueUtils; | ||
import org.opensearch.sql.data.type.ExprCoreType; | ||
import org.opensearch.sql.data.type.ExprType; | ||
import org.opensearch.sql.expression.env.Environment; | ||
import org.opensearch.sql.expression.function.BuiltinFunctionName; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Score Expression. | ||
*/ | ||
@Getter | ||
public class ScoreExpression extends FunctionExpression { | ||
|
||
private final Expression relevanceQueryExpr; | ||
|
||
/** | ||
* ScoreExpression Constructor. | ||
* @param relevanceQueryExpr : relevanceQueryExpr for expression. | ||
*/ | ||
public ScoreExpression(Expression relevanceQueryExpr) { | ||
super(BuiltinFunctionName.SCORE.getName(), List.of(relevanceQueryExpr)); | ||
this.relevanceQueryExpr = relevanceQueryExpr; | ||
} | ||
|
||
/** | ||
* Return collection value matching relevance query expression. | ||
* @param valueEnv : Dataset to parse value from. | ||
* @return : collection value of relevance query expression. | ||
*/ | ||
@Override | ||
public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) { | ||
// String refName = "_highlight"; | ||
// // Not a wilcard expression | ||
// if (this.type == ExprCoreType.ARRAY) { | ||
// refName += "." + StringUtils.unquoteText(getHighlightField().toString()); | ||
// } | ||
// ExprValue value = valueEnv.resolve(DSL.ref(refName, ExprCoreType.STRING)); | ||
// | ||
// // In the event of multiple returned highlights and wildcard being | ||
// // used in conjunction with other highlight calls, we need to ensure | ||
// // only wildcard regex matching is mapped to wildcard call. | ||
// if (this.type == ExprCoreType.STRUCT && value.type() == ExprCoreType.STRUCT) { | ||
// value = new ExprTupleValue( | ||
// new LinkedHashMap<String, ExprValue>(value.tupleValue() | ||
// .entrySet() | ||
// .stream() | ||
// .filter(s -> matchesHighlightRegex(s.getKey(), | ||
// StringUtils.unquoteText(highlightField.toString()))) | ||
// .collect(Collectors.toMap( | ||
// e -> e.getKey(), | ||
// e -> e.getValue())))); | ||
// if (value.tupleValue().isEmpty()) { | ||
// value = ExprValueUtils.missingValue(); | ||
// } | ||
// } | ||
|
||
// TODO: this is where we visit relevance function nodes and update BOOST values as necessary | ||
// Otherwise, this is a no-op | ||
|
||
return ExprNullValue.of(); | ||
} | ||
|
||
@Override | ||
public <T, C> T accept(ExpressionNodeVisitor<T, C> visitor, C context) { | ||
return visitor.visitScore(this, context); | ||
} | ||
|
||
@Override | ||
public ExprType type() { | ||
return ExprCoreType.UNDEFINED; | ||
} | ||
} |
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.