Search in sources :

Example 1 with ScriptParserContext

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

the class SDField method parseIndexingScript.

public void parseIndexingScript(String script, Linguistics linguistics) {
    try {
        ScriptParserContext config = new ScriptParserContext(linguistics);
        config.setInputStream(new IndexingInput(script));
        setIndexingScript(ScriptExpression.newInstance(config));
    } catch (ParseException e) {
        throw new RuntimeException("Failed to parser script '" + script + "'.", e);
    }
}
Also used : IndexingInput(com.yahoo.vespa.indexinglanguage.parser.IndexingInput) ParseException(com.yahoo.vespa.indexinglanguage.parser.ParseException) ScriptParserContext(com.yahoo.vespa.indexinglanguage.ScriptParserContext)

Example 2 with ScriptParserContext

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

the class IndexingOperation method fromStream.

public static IndexingOperation fromStream(SimpleCharStream input, boolean multiLine, Linguistics linguistics) throws ParseException {
    ScriptParserContext config = new ScriptParserContext(linguistics);
    config.setAnnotatorConfig(new AnnotatorConfig());
    config.setInputStream(input);
    ScriptExpression exp;
    try {
        if (multiLine) {
            exp = ScriptExpression.newInstance(config);
        } else {
            exp = new ScriptExpression(StatementExpression.newInstance(config));
        }
    } catch (com.yahoo.vespa.indexinglanguage.parser.ParseException e) {
        ParseException t = new ParseException("Error reported by IL parser: " + e.getMessage());
        t.initCause(e);
        throw t;
    }
    return new IndexingOperation(exp);
}
Also used : AnnotatorConfig(com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig) ParseException(com.yahoo.searchdefinition.parser.ParseException) ScriptParserContext(com.yahoo.vespa.indexinglanguage.ScriptParserContext) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)

Example 3 with ScriptParserContext

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

the class ScriptManager method createScriptsMap.

private static Map<String, Map<String, DocumentScript>> createScriptsMap(DocumentTypeManager docTypeMgr, IlscriptsConfig config, Linguistics linguistics) {
    Map<String, Map<String, DocumentScript>> documentFieldScripts = new HashMap<>(config.ilscript().size());
    ScriptParserContext parserContext = new ScriptParserContext(linguistics);
    parserContext.getAnnotatorConfig().setMaxTermOccurrences(config.maxtermoccurrences());
    parserContext.getAnnotatorConfig().setMaxTokenLength(config.fieldmatchmaxlength());
    for (IlscriptsConfig.Ilscript ilscript : config.ilscript()) {
        InputExpression.FieldPathOptimizer fieldPathOptimizer = new InputExpression.FieldPathOptimizer(docTypeMgr.getDocumentType(ilscript.doctype()));
        List<StatementExpression> expressions = new ArrayList<>(ilscript.content().size());
        Map<String, DocumentScript> fieldScripts = new HashMap<>(ilscript.content().size());
        for (String content : ilscript.content()) {
            expressions.add(parse(ilscript.doctype(), parserContext, content));
            StatementExpression statement = parse(ilscript.doctype(), parserContext, content);
            InputExpression.InputFieldNameExtractor inputFieldNameExtractor = new InputExpression.InputFieldNameExtractor();
            statement.select(inputFieldNameExtractor, inputFieldNameExtractor);
            statement.select(fieldPathOptimizer, fieldPathOptimizer);
            if (inputFieldNameExtractor.getInputFieldNames().size() == 1) {
                String fieldName = inputFieldNameExtractor.getInputFieldNames().get(0);
                ScriptExpression script;
                if (fieldScripts.containsKey(fieldName)) {
                    DocumentScript prev = fieldScripts.get(fieldName);
                    List<StatementExpression> appendedList = new ArrayList<>(((ScriptExpression) prev.getExpression()).asList());
                    appendedList.add(statement);
                    script = new ScriptExpression(appendedList);
                    log.log(Level.FINE, "Appending script for field '" + fieldName + "' = " + statement);
                    log.log(Level.FINE, "Full script for field '" + fieldName + "' = " + appendedList);
                } else {
                    script = new ScriptExpression(statement);
                    log.log(Level.FINE, "Setting script for field '" + fieldName + "' = " + statement);
                }
                DocumentScript documentScript = new DocumentScript(ilscript.doctype(), inputFieldNameExtractor.getInputFieldNames(), script);
                fieldScripts.put(fieldName, documentScript);
            } else {
                log.log(Level.FINE, "Non single(" + inputFieldNameExtractor.getInputFieldNames().size() + ") inputs = " + inputFieldNameExtractor.getInputFieldNames() + ". Script = " + statement);
            }
        }
        ScriptExpression script = new ScriptExpression(expressions);
        script.select(fieldPathOptimizer, fieldPathOptimizer);
        fieldScripts.put(FULL, new DocumentScript(ilscript.doctype(), ilscript.docfield(), script));
        documentFieldScripts.put(ilscript.doctype(), Collections.unmodifiableMap(fieldScripts));
    }
    return Collections.unmodifiableMap(documentFieldScripts);
}
Also used : StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) InputExpression(com.yahoo.vespa.indexinglanguage.expressions.InputExpression) ScriptParserContext(com.yahoo.vespa.indexinglanguage.ScriptParserContext) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) IlscriptsConfig(com.yahoo.vespa.configdefinition.IlscriptsConfig)

Example 4 with ScriptParserContext

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

the class DefaultFieldNameTestCase method requireThatDefaultFieldNameIsAppliedWhenArgumentIsMissing.

@Test
public void requireThatDefaultFieldNameIsAppliedWhenArgumentIsMissing() throws ParseException {
    IndexingInput input = new IndexingInput("input");
    InputExpression exp = (InputExpression) Expression.newInstance(new ScriptParserContext(new SimpleLinguistics()).setInputStream(input).setDefaultFieldName("foo"));
    assertEquals("foo", exp.getFieldName());
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) InputExpression(com.yahoo.vespa.indexinglanguage.expressions.InputExpression) ScriptParserContext(com.yahoo.vespa.indexinglanguage.ScriptParserContext) Test(org.junit.Test)

Aggregations

ScriptParserContext (com.yahoo.vespa.indexinglanguage.ScriptParserContext)4 InputExpression (com.yahoo.vespa.indexinglanguage.expressions.InputExpression)2 ScriptExpression (com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)2 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)1 ParseException (com.yahoo.searchdefinition.parser.ParseException)1 IlscriptsConfig (com.yahoo.vespa.configdefinition.IlscriptsConfig)1 StatementExpression (com.yahoo.vespa.indexinglanguage.expressions.StatementExpression)1 AnnotatorConfig (com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig)1 IndexingInput (com.yahoo.vespa.indexinglanguage.parser.IndexingInput)1 ParseException (com.yahoo.vespa.indexinglanguage.parser.ParseException)1 Test (org.junit.Test)1