use of com.yahoo.vespa.configdefinition.IlscriptsConfig in project vespa by vespa-engine.
the class ScriptManagerTestCase method requireThatScriptsAreAppliedToSubType.
@Test
public void requireThatScriptsAreAppliedToSubType() throws ParseException {
DocumentTypeManager typeMgr = new DocumentTypeManager();
typeMgr.configure("file:src/test/cfg/documentmanager_inherit.cfg");
DocumentType docType = typeMgr.getDocumentType("newssummary");
assertNotNull(docType);
IlscriptsConfig.Builder config = new IlscriptsConfig.Builder();
config.ilscript(new IlscriptsConfig.Ilscript.Builder().doctype("newssummary").content("index"));
ScriptManager scriptMgr = new ScriptManager(typeMgr, new IlscriptsConfig(config), null);
assertNotNull(scriptMgr.getScript(typeMgr.getDocumentType("newsarticle")));
assertNull(scriptMgr.getScript(new DocumentType("unknown")));
}
use of com.yahoo.vespa.configdefinition.IlscriptsConfig in project vespa by vespa-engine.
the class ScriptManagerTestCase method requireThatEmptyConfigurationDoesNotThrow.
@Test
public void requireThatEmptyConfigurationDoesNotThrow() {
DocumentTypeManager typeMgr = new DocumentTypeManager();
typeMgr.configure("file:src/test/cfg/documentmanager_inherit.cfg");
ScriptManager scriptMgr = new ScriptManager(typeMgr, new IlscriptsConfig(new IlscriptsConfig.Builder()), null);
assertNull(scriptMgr.getScript(new DocumentType("unknown")));
}
use of com.yahoo.vespa.configdefinition.IlscriptsConfig 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.configdefinition.IlscriptsConfig in project vespa by vespa-engine.
the class DocumentDatabaseTestCase method requireThatWeCanHaveMultipleSearchDefinitions.
@Test
public void requireThatWeCanHaveMultipleSearchDefinitions() throws IOException, SAXException, ParseException {
final List<String> sds = Arrays.asList("type1", "type2", "type3");
VespaModel model = new VespaModelCreatorWithMockPkg(vespaHosts, createVespaServices(sds, "index"), ApplicationPackageUtils.generateSearchDefinitions(sds)).create();
IndexedSearchCluster indexedSearchCluster = (IndexedSearchCluster) model.getSearchClusters().get(0);
ContentSearchCluster contentSearchCluster = model.getContentClusters().get("test").getSearch();
String type1Id = "test/search/cluster.test/type1";
String type2Id = "test/search/cluster.test/type2";
String type3Id = "test/search/cluster.test/type3";
{
assertEquals(3, indexedSearchCluster.getDocumentDbs().size());
ProtonConfig proton = getProtonCfg(contentSearchCluster);
assertEquals(3, proton.documentdb().size());
assertEquals("type1", proton.documentdb(0).inputdoctypename());
assertEquals(type1Id, proton.documentdb(0).configid());
assertEquals("type2", proton.documentdb(1).inputdoctypename());
assertEquals(type2Id, proton.documentdb(1).configid());
assertEquals("type3", proton.documentdb(2).inputdoctypename());
assertEquals(type3Id, proton.documentdb(2).configid());
}
assertDocTypeConfig(model, type1Id, "f1", "f2");
assertDocTypeConfig(model, type2Id, "f3", "f4");
assertDocTypeConfig(model, type3Id, "f5", "f6");
{
IndexInfoConfig iicfg = model.getConfig(IndexInfoConfig.class, "test/search/cluster.test");
assertEquals(3, iicfg.indexinfo().size());
assertEquals("type1", iicfg.indexinfo().get(0).name());
assertEquals("type2", iicfg.indexinfo().get(1).name());
assertEquals("type3", iicfg.indexinfo().get(2).name());
}
{
AttributesConfig rac1 = model.getConfig(AttributesConfig.class, type1Id);
assertEquals(2, rac1.attribute().size());
assertEquals("f2", rac1.attribute(0).name());
assertEquals("f2_nfa", rac1.attribute(1).name());
AttributesConfig rac2 = model.getConfig(AttributesConfig.class, type2Id);
assertEquals(2, rac2.attribute().size());
assertEquals("f4", rac2.attribute(0).name());
assertEquals("f4_nfa", rac2.attribute(1).name());
}
{
IlscriptsConfig icfg = model.getConfig(IlscriptsConfig.class, "test/search/cluster.test");
assertEquals(3, icfg.ilscript().size());
assertEquals("type1", icfg.ilscript(0).doctype());
assertEquals("type2", icfg.ilscript(1).doctype());
assertEquals("type3", icfg.ilscript(2).doctype());
}
}
use of com.yahoo.vespa.configdefinition.IlscriptsConfig in project vespa by vespa-engine.
the class ScriptManagerTestCase method requireThatScriptsAreAppliedToSuperType.
@Test
public void requireThatScriptsAreAppliedToSuperType() throws ParseException {
DocumentTypeManager typeMgr = new DocumentTypeManager();
typeMgr.configure("file:src/test/cfg/documentmanager_inherit.cfg");
DocumentType docType = typeMgr.getDocumentType("newsarticle");
assertNotNull(docType);
IlscriptsConfig.Builder config = new IlscriptsConfig.Builder();
config.ilscript(new IlscriptsConfig.Ilscript.Builder().doctype("newsarticle").content("index"));
ScriptManager scriptMgr = new ScriptManager(typeMgr, new IlscriptsConfig(config), null);
assertNotNull(scriptMgr.getScript(typeMgr.getDocumentType("newssummary")));
assertNull(scriptMgr.getScript(new DocumentType("unknown")));
}
Aggregations