Search in sources :

Example 11 with ScriptExpression

use of com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression in project vespa by vespa-engine.

the class CreatePositionZCurve method createZCurveField.

private SDField createZCurveField(SDField inputField, String fieldName, boolean validate) {
    if (validate && search.getConcreteField(fieldName) != null || search.getAttribute(fieldName) != null) {
        throw newProcessException(search, null, "Incompatible position attribute '" + fieldName + "' already created.");
    }
    boolean isArray = inputField.getDataType() instanceof ArrayDataType;
    SDField field = new SDField(fieldName, isArray ? DataType.getArray(DataType.LONG) : DataType.LONG);
    Attribute attribute = new Attribute(fieldName, Attribute.Type.LONG, isArray ? Attribute.CollectionType.ARRAY : Attribute.CollectionType.SINGLE);
    attribute.setPosition(true);
    attribute.setFastSearch(true);
    field.addAttribute(attribute);
    ScriptExpression script = inputField.getIndexingScript();
    script = (ScriptExpression) new RemoveSummary(inputField.getName()).convert(script);
    script = (ScriptExpression) new PerformZCurve(field, fieldName).convert(script);
    field.setIndexingScript(script);
    return field;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute) ArrayDataType(com.yahoo.document.ArrayDataType) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)

Example 12 with ScriptExpression

use of com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression in project vespa by vespa-engine.

the class SearchClusterTest method testSdConfigLogical.

@Test
public void testSdConfigLogical() throws IOException, SAXException {
    // sd1
    SDDocumentType sdt1 = new SDDocumentType("s1");
    Search search1 = new Search("s1", null);
    SDField f1 = new SDField("f1", DataType.STRING);
    f1.addAttribute(new Attribute("f1", DataType.STRING));
    f1.setIndexingScript(new ScriptExpression(new StatementExpression(new AttributeExpression("f1"))));
    sdt1.addField(f1);
    search1.addDocument(sdt1);
    // sd2
    SDDocumentType sdt2 = new SDDocumentType("s2");
    Search search2 = new Search("s2", null);
    SDField f2 = new SDField("f2", DataType.STRING);
    f2.addAttribute(new Attribute("f2", DataType.STRING));
    f2.setIndexingScript(new ScriptExpression(new StatementExpression(new AttributeExpression("f2"))));
    sdt2.addField(f2);
    search2.addDocument(sdt2);
    SearchBuilder builder = new SearchBuilder();
    builder.importRawSearch(search1);
    builder.importRawSearch(search2);
    builder.build();
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Attribute(com.yahoo.searchdefinition.document.Attribute) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) Search(com.yahoo.searchdefinition.Search) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) Test(org.junit.Test)

Example 13 with ScriptExpression

use of com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression in project vespa by vespa-engine.

the class ExpressionConverterTestCase method requireThatAllExpressionTypesCanBeTraversed.

@SuppressWarnings("unchecked")
@Test
public void requireThatAllExpressionTypesCanBeTraversed() {
    assertConvertable(new ArithmeticExpression(new InputExpression("foo"), ArithmeticExpression.Operator.ADD, new InputExpression("bar")));
    assertConvertable(new AttributeExpression("foo"));
    assertConvertable(new Base64DecodeExpression());
    assertConvertable(new Base64EncodeExpression());
    assertConvertable(new CatExpression(new InputExpression("foo"), new IndexExpression("bar")));
    assertConvertable(new ClearStateExpression());
    assertConvertable(new EchoExpression());
    assertConvertable(new ForEachExpression(new IndexExpression("foo")));
    assertConvertable(new GetFieldExpression("foo"));
    assertConvertable(new GetVarExpression("foo"));
    assertConvertable(new GuardExpression(new IndexExpression("foo")));
    assertConvertable(new HexDecodeExpression());
    assertConvertable(new HexEncodeExpression());
    assertConvertable(new HostNameExpression());
    assertConvertable(new IfThenExpression(new InputExpression("foo"), IfThenExpression.Comparator.EQ, new InputExpression("bar"), new IndexExpression("baz"), new IndexExpression("cox")));
    assertConvertable(new IndexExpression("foo"));
    assertConvertable(new InputExpression("foo"));
    assertConvertable(new JoinExpression("foo"));
    assertConvertable(new LowerCaseExpression());
    assertConvertable(new NormalizeExpression(new SimpleLinguistics()));
    assertConvertable(new NowExpression());
    assertConvertable(new OptimizePredicateExpression());
    assertConvertable(new ParenthesisExpression(new InputExpression("foo")));
    assertConvertable(new RandomExpression(69));
    assertConvertable(new ScriptExpression(new StatementExpression(new InputExpression("foo"))));
    assertConvertable(new SelectInputExpression(new Pair<String, Expression>("foo", new IndexExpression("bar")), new Pair<String, Expression>("bar", new IndexExpression("foo"))));
    assertConvertable(new SetLanguageExpression());
    assertConvertable(new SetValueExpression(new IntegerFieldValue(69)));
    assertConvertable(new SetVarExpression("foo"));
    assertConvertable(new SplitExpression("foo"));
    assertConvertable(new StatementExpression(new InputExpression("foo")));
    assertConvertable(new SubstringExpression(6, 9));
    assertConvertable(new SummaryExpression("foo"));
    assertConvertable(new SwitchExpression(Collections.singletonMap("foo", (Expression) new IndexExpression("bar")), new InputExpression("baz")));
    assertConvertable(new ThisExpression());
    assertConvertable(new ToArrayExpression());
    assertConvertable(new ToByteExpression());
    assertConvertable(new ToDoubleExpression());
    assertConvertable(new ToFloatExpression());
    assertConvertable(new ToIntegerExpression());
    assertConvertable(new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig()));
    assertConvertable(new ToLongExpression());
    assertConvertable(new ToPositionExpression());
    assertConvertable(new ToStringExpression());
    assertConvertable(new ToWsetExpression(false, false));
    assertConvertable(new TrimExpression());
    assertConvertable(new ZCurveExpression());
}
Also used : SummaryExpression(com.yahoo.vespa.indexinglanguage.expressions.SummaryExpression) SwitchExpression(com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression) AnnotatorConfig(com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) OptimizePredicateExpression(com.yahoo.vespa.indexinglanguage.expressions.OptimizePredicateExpression) SplitExpression(com.yahoo.vespa.indexinglanguage.expressions.SplitExpression) ToPositionExpression(com.yahoo.vespa.indexinglanguage.expressions.ToPositionExpression) ThisExpression(com.yahoo.vespa.indexinglanguage.expressions.ThisExpression) ToByteExpression(com.yahoo.vespa.indexinglanguage.expressions.ToByteExpression) TokenizeExpression(com.yahoo.vespa.indexinglanguage.expressions.TokenizeExpression) IfThenExpression(com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression) ToStringExpression(com.yahoo.vespa.indexinglanguage.expressions.ToStringExpression) SubstringExpression(com.yahoo.vespa.indexinglanguage.expressions.SubstringExpression) EchoExpression(com.yahoo.vespa.indexinglanguage.expressions.EchoExpression) SetVarExpression(com.yahoo.vespa.indexinglanguage.expressions.SetVarExpression) HexDecodeExpression(com.yahoo.vespa.indexinglanguage.expressions.HexDecodeExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) InputExpression(com.yahoo.vespa.indexinglanguage.expressions.InputExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) ToArrayExpression(com.yahoo.vespa.indexinglanguage.expressions.ToArrayExpression) SetLanguageExpression(com.yahoo.vespa.indexinglanguage.expressions.SetLanguageExpression) LowerCaseExpression(com.yahoo.vespa.indexinglanguage.expressions.LowerCaseExpression) ToIntegerExpression(com.yahoo.vespa.indexinglanguage.expressions.ToIntegerExpression) ForEachExpression(com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) ToWsetExpression(com.yahoo.vespa.indexinglanguage.expressions.ToWsetExpression) Base64DecodeExpression(com.yahoo.vespa.indexinglanguage.expressions.Base64DecodeExpression) IndexExpression(com.yahoo.vespa.indexinglanguage.expressions.IndexExpression) GetFieldExpression(com.yahoo.vespa.indexinglanguage.expressions.GetFieldExpression) RandomExpression(com.yahoo.vespa.indexinglanguage.expressions.RandomExpression) TrimExpression(com.yahoo.vespa.indexinglanguage.expressions.TrimExpression) JoinExpression(com.yahoo.vespa.indexinglanguage.expressions.JoinExpression) HexEncodeExpression(com.yahoo.vespa.indexinglanguage.expressions.HexEncodeExpression) Pair(com.yahoo.collections.Pair) SetValueExpression(com.yahoo.vespa.indexinglanguage.expressions.SetValueExpression) NowExpression(com.yahoo.vespa.indexinglanguage.expressions.NowExpression) ToDoubleExpression(com.yahoo.vespa.indexinglanguage.expressions.ToDoubleExpression) ToLongExpression(com.yahoo.vespa.indexinglanguage.expressions.ToLongExpression) ToFloatExpression(com.yahoo.vespa.indexinglanguage.expressions.ToFloatExpression) Base64EncodeExpression(com.yahoo.vespa.indexinglanguage.expressions.Base64EncodeExpression) CatExpression(com.yahoo.vespa.indexinglanguage.expressions.CatExpression) GuardExpression(com.yahoo.vespa.indexinglanguage.expressions.GuardExpression) ParenthesisExpression(com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression) NormalizeExpression(com.yahoo.vespa.indexinglanguage.expressions.NormalizeExpression) ArithmeticExpression(com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression) HostNameExpression(com.yahoo.vespa.indexinglanguage.expressions.HostNameExpression) GetVarExpression(com.yahoo.vespa.indexinglanguage.expressions.GetVarExpression) ClearStateExpression(com.yahoo.vespa.indexinglanguage.expressions.ClearStateExpression) ZCurveExpression(com.yahoo.vespa.indexinglanguage.expressions.ZCurveExpression) Test(org.junit.Test)

Example 14 with ScriptExpression

use of com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression in project vespa by vespa-engine.

the class ExpressionSearcherTestCase method requireThatExpressionsCanBeFound.

@Test
public void requireThatExpressionsCanBeFound() {
    IndexExpression exp = new IndexExpression("foo");
    assertFound(exp, new ArithmeticExpression(exp, ArithmeticExpression.Operator.ADD, new AttributeExpression("foo")));
    assertFound(exp, new ArithmeticExpression(new AttributeExpression("foo"), ArithmeticExpression.Operator.ADD, exp));
    assertFound(exp, new CatExpression(exp));
    assertFound(exp, new CatExpression(new AttributeExpression("foo"), exp));
    assertFound(exp, new ForEachExpression(exp));
    assertFound(exp, new GuardExpression(exp));
    assertFound(exp, new IfThenExpression(exp, IfThenExpression.Comparator.EQ, new AttributeExpression("foo"), new AttributeExpression("bar"), new AttributeExpression("baz")));
    assertFound(exp, new IfThenExpression(new AttributeExpression("foo"), IfThenExpression.Comparator.EQ, exp, new AttributeExpression("bar"), new AttributeExpression("baz")));
    assertFound(exp, new IfThenExpression(new AttributeExpression("foo"), IfThenExpression.Comparator.EQ, new AttributeExpression("bar"), exp, new AttributeExpression("baz")));
    assertFound(exp, new IfThenExpression(new AttributeExpression("foo"), IfThenExpression.Comparator.EQ, new AttributeExpression("bar"), new AttributeExpression("baz"), exp));
    assertFound(exp, new ParenthesisExpression(exp));
    assertFound(exp, new ScriptExpression(new StatementExpression(exp)));
    assertFound(exp, new ScriptExpression(new StatementExpression(new AttributeExpression("foo")), new StatementExpression(exp)));
    assertFound(exp, new SelectInputExpression(Arrays.asList(new Pair<String, Expression>("foo", exp), new Pair<String, Expression>("bar", new AttributeExpression("bar")))));
    assertFound(exp, new SelectInputExpression(Arrays.asList(new Pair<String, Expression>("foo", new AttributeExpression("bar")), new Pair<String, Expression>("bar", exp))));
    assertFound(exp, new StatementExpression(exp));
    assertFound(exp, new StatementExpression(new AttributeExpression("foo"), exp));
    assertFound(exp, new SwitchExpression(Collections.singletonMap("foo", exp), new AttributeExpression("bar")));
    assertFound(exp, new SwitchExpression(Collections.singletonMap("foo", new AttributeExpression("bar")), exp));
}
Also used : SwitchExpression(com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) CatExpression(com.yahoo.vespa.indexinglanguage.expressions.CatExpression) GuardExpression(com.yahoo.vespa.indexinglanguage.expressions.GuardExpression) ParenthesisExpression(com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression) IndexExpression(com.yahoo.vespa.indexinglanguage.expressions.IndexExpression) ArithmeticExpression(com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) IfThenExpression(com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression) SwitchExpression(com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) CatExpression(com.yahoo.vespa.indexinglanguage.expressions.CatExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) IndexExpression(com.yahoo.vespa.indexinglanguage.expressions.IndexExpression) ForEachExpression(com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression) Expression(com.yahoo.vespa.indexinglanguage.expressions.Expression) ParenthesisExpression(com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression) GuardExpression(com.yahoo.vespa.indexinglanguage.expressions.GuardExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) ArithmeticExpression(com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression) ForEachExpression(com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression) IfThenExpression(com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) Test(org.junit.Test)

Example 15 with ScriptExpression

use of com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression in project vespa by vespa-engine.

the class ScriptParserTestCase method requireThatScriptParserBacksUpStream.

@Test
public void requireThatScriptParserBacksUpStream() throws ParseException {
    ScriptParserContext config = newContext("{ input foo }{ input bar }");
    assertEquals(new ScriptExpression(new StatementExpression(new InputExpression("foo"))), ScriptParser.parseScript(config));
    assertEquals(new ScriptExpression(new StatementExpression(new InputExpression("bar"))), ScriptParser.parseScript(config));
}
Also used : StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) InputExpression(com.yahoo.vespa.indexinglanguage.expressions.InputExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) Test(org.junit.Test)

Aggregations

ScriptExpression (com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)16 StatementExpression (com.yahoo.vespa.indexinglanguage.expressions.StatementExpression)9 Test (org.junit.Test)8 InputExpression (com.yahoo.vespa.indexinglanguage.expressions.InputExpression)7 SDField (com.yahoo.searchdefinition.document.SDField)6 AttributeExpression (com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression)5 EchoExpression (com.yahoo.vespa.indexinglanguage.expressions.EchoExpression)5 ArithmeticExpression (com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression)4 CatExpression (com.yahoo.vespa.indexinglanguage.expressions.CatExpression)4 ForEachExpression (com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression)4 GuardExpression (com.yahoo.vespa.indexinglanguage.expressions.GuardExpression)4 IfThenExpression (com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression)4 IndexExpression (com.yahoo.vespa.indexinglanguage.expressions.IndexExpression)4 ParenthesisExpression (com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression)4 SelectInputExpression (com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression)4 SwitchExpression (com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression)4 Base64DecodeExpression (com.yahoo.vespa.indexinglanguage.expressions.Base64DecodeExpression)3 Base64EncodeExpression (com.yahoo.vespa.indexinglanguage.expressions.Base64EncodeExpression)3 ClearStateExpression (com.yahoo.vespa.indexinglanguage.expressions.ClearStateExpression)3 GetFieldExpression (com.yahoo.vespa.indexinglanguage.expressions.GetFieldExpression)3