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);
}
}
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);
}
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);
}
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());
}
Aggregations