summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java34
-rw-r--r--config-model/src/main/javacc/SDParser.jj15
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java78
3 files changed, 116 insertions, 11 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java
index c65e0fad1c7..f8562a1c1b9 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java
@@ -12,11 +12,19 @@ import java.util.Objects;
*/
public class RankingConstant {
+ public enum PathType {FILE, URI};
+
/** The search definition-unique name of this constant */
private final String name;
private TensorType tensorType = null;
- private String fileName = null;
- private String fileReference = "";
+ private String path = null;
+ private String fileRef = "";
+
+ public PathType getPathType() {
+ return pathType;
+ }
+
+ private PathType pathType = PathType.FILE;
public RankingConstant(String name) {
this.name = name;
@@ -31,7 +39,14 @@ public class RankingConstant {
public void setFileName(String fileName) {
Objects.requireNonNull(fileName, "Filename cannot be null");
- this.fileName = fileName;
+ this.path = fileName;
+ this.pathType = PathType.FILE;
+ }
+
+ public void setUri(String uri) {
+ Objects.requireNonNull(uri, "uri cannot be null");
+ this.path = uri;
+ this.pathType = PathType.URI;
}
/**
@@ -43,14 +58,15 @@ public class RankingConstant {
public void setType(TensorType tensorType) { this.tensorType = tensorType; }
public String getName() { return name; }
- public String getFileName() { return fileName; }
- public String getFileReference() { return fileReference; }
+ public String getFileName() { return path; }
+ public String getUri() { return path; }
+ public String getFileReference() { return fileRef; }
public TensorType getTensorType() { return tensorType; }
public String getType() { return tensorType.toString(); }
public void validate() {
- if (fileName == null || fileName.isEmpty())
- throw new IllegalArgumentException("Ranking constants must have a file.");
+ if (path == null || path.isEmpty())
+ throw new IllegalArgumentException("Ranking constants must have a file or uri.");
if (tensorType == null)
throw new IllegalArgumentException("Ranking constant '" + name + "' must have a type.");
}
@@ -58,8 +74,8 @@ public class RankingConstant {
public String toString() {
StringBuilder b = new StringBuilder();
b.append("constant '").append(name)
- .append("' from file '").append(fileName)
- .append("' with ref '").append(fileReference)
+ .append(pathType == PathType.FILE ? "' from file '" : " from uri ").append(path)
+ .append("' with ref '").append(fileRef)
.append("' of type '").append(tensorType)
.append("'");
return b.toString();
diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj
index 916a905dfcb..bf6376983a4 100644
--- a/config-model/src/main/javacc/SDParser.jj
+++ b/config-model/src/main/javacc/SDParser.jj
@@ -339,6 +339,7 @@ TOKEN :
| < RANKSCOREDROPLIMIT: "rank-score-drop-limit" >
| < CONSTANTS: "constants" >
| < FILE: "file" >
+| < URI: "uri" >
| < IDENTIFIER: ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_","-"])* >
| < QUOTEDSTRING: "\"" ( ~["\""] )* "\"" >
| < CONTEXT: ["a"-"z","A"-"Z"] (["a"-"z", "A"-"Z", "0"-"9"])* >
@@ -347,6 +348,8 @@ TOKEN :
| < LONG: ("-")? (["0"-"9"])+"L" >
| < STRING: (["a"-"z","A"-"Z","_","0"-"9","."])+ >
| < FILE_PATH: ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_","-", "/", "."])+ >
+| < HTTP: ["h","H"] ["t","T"] ["t","T"] ["p","P"] >
+| < URI_PATH: <HTTP> <COLON> ("//")? (["a"-"z","A"-"Z","0"-"9","_","-", "/", ".",":"])+ >
| < LESSTHAN: "<" >
| < GREATERTHAN: ">" >
| < VARIABLE: "$" <IDENTIFIER> >
@@ -1805,11 +1808,12 @@ void rankingConstant(Search search) :
*/
Object rankingConstantItem(RankingConstant constant) :
{
- String fileName = null;
+ String path = null;
TensorType type = null;
}
{
- ( (<FILE> <COLON> fileName = filePath() { } (<NL>)*) { constant.setFileName(fileName); }
+ ( (<FILE> <COLON> path = filePath() { } (<NL>)*) { constant.setFileName(path); }
+ | (<URI> <COLON> path = uriPath() { } (<NL>)*) { constant.setUri(path); }
| type = tensorTypeWithPrefix(rankingConstantErrorMessage(constant.getName())) (<NL>)* { constant.setType(type); }
)
{
@@ -1828,6 +1832,12 @@ String filePath() : { }
{ return token.image; }
}
+String uriPath() : { }
+{
+ ( <URI_PATH> )
+ { return token.image; }
+}
+
/**
* Consumes a rank-profile block of a search element.
*
@@ -2550,6 +2560,7 @@ String identifier() : { }
| <TRUE>
| <TYPE>
| <UCA>
+ | <URI>
| <UPPERBOUND>
| <USEDOCUMENT>
| <VARIABLE>
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java
index 2880af9e74f..df5f4f94ade 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition;
+import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -48,6 +49,7 @@ public class RankingConstantTest {
assertEquals(TENSOR_NAME, constant.getName());
assertEquals(TENSOR_FILE, constant.getFileName());
assertEquals(TENSOR_TYPE, constant.getType());
+ assertEquals(RankingConstant.PathType.FILE, constant.getPathType());
assertFalse(constantIterator.hasNext());
}
@@ -103,4 +105,80 @@ public class RankingConstantTest {
assertEquals("simplename", constant.getFileName());
}
+ @Test
+ public void constant_uri_is_allowed() throws Exception {
+ RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
+ SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry);
+ searchBuilder.importString(joinLines(
+ "search test {",
+ " document test { }",
+ " constant foo {",
+ " type: tensor(x{})",
+ " uri: http://somwhere.far.away/in/another-galaxy",
+ " }",
+ "}"
+ ));
+ searchBuilder.build();
+ Search search = searchBuilder.getSearch();
+ RankingConstant constant = search.getRankingConstants().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("http://somwhere.far.away/in/another-galaxy", constant.getUri());
+ }
+ @Test
+ public void constant_uri_with_port_is_allowed() throws Exception {
+ RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
+ SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry);
+ searchBuilder.importString(joinLines(
+ "search test {",
+ " document test { }",
+ " constant foo {",
+ " type: tensor(x{})",
+ " uri: http://somwhere.far.away:4080/in/another-galaxy",
+ " }",
+ "}"
+ ));
+ searchBuilder.build();
+ Search search = searchBuilder.getSearch();
+ RankingConstant constant = search.getRankingConstants().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("http://somwhere.far.away:4080/in/another-galaxy", constant.getUri());
+ }
+ @Test
+ public void constant_uri_no_dual_slashes_is_allowed() throws Exception {
+ RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
+ SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry);
+ searchBuilder.importString(joinLines(
+ "search test {",
+ " document test { }",
+ " constant foo {",
+ " type: tensor(x{})",
+ " uri: http:somwhere.far.away/in/another-galaxy",
+ " }",
+ "}"
+ ));
+ searchBuilder.build();
+ Search search = searchBuilder.getSearch();
+ RankingConstant constant = search.getRankingConstants().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("http:somwhere.far.away/in/another-galaxy", constant.getUri());
+ }
+ @Test
+ public void constant_uri_only_supports_http() throws Exception {
+ RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
+ SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry);
+ thrown.expect(ParseException.class);
+ thrown.expectMessage("Encountered \" <IDENTIFIER> \"ftp \"\" at line 5, column 10.\n" +
+ "Was expecting:\n" +
+ " <URI_PATH> ...");
+ searchBuilder.importString(joinLines(
+ "search test {",
+ " document test { }",
+ " constant foo {",
+ " type: tensor(x{})",
+ " uri: ftp:somwhere.far.away/in/another-galaxy",
+ " }",
+ "}"
+ ));
+ }
+
}