use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class RankingExpressionConstantsTestCase method test3.
@Test
public void test3() throws ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
SearchBuilder builder = new SearchBuilder(rankProfileRegistry);
builder.importString("search test {\n" + " document test { \n" + " field rating_yelp type int {" + " indexing: attribute" + " }" + " }\n" + " \n" + " rank-profile test {\n" + " macro rank_default(){\n" + " expression: 0.5+50*(attribute(rating_yelp)-3)\n\n" + " }\n" + " }\n" + "\n" + "}\n");
builder.build();
Search s = builder.getSearch();
RankProfile profile = rankProfileRegistry.getRankProfile(s, "test");
assertEquals("0.5 + 50 * (attribute(rating_yelp) - 3)", profile.compile(new QueryProfileRegistry()).getMacros().get("rank_default").getRankingExpression().getRoot().toString());
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class RankingExpressionConstantsTestCase method testConstantDivisorInMacro.
@Test
public void testConstantDivisorInMacro() throws ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
SearchBuilder builder = new SearchBuilder(rankProfileRegistry);
builder.importString("search test {\n" + " document test { \n" + " }\n" + " \n" + " rank-profile test {\n" + " macro rank_default(){\n" + " expression: k1 + (k2 + k3) / 100000000.0\n\n" + " }\n" + " }\n" + "\n" + "}\n");
builder.build();
Search s = builder.getSearch();
RankProfile profile = rankProfileRegistry.getRankProfile(s, "test");
assertEquals("k1 + (k2 + k3) / 100000000.0", profile.compile(new QueryProfileRegistry()).getMacros().get("rank_default").getRankingExpression().getRoot().toString());
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class RankingExpressionShadowingTestCase method testNeuralNetworkSetup.
@Test
public void testNeuralNetworkSetup() throws ParseException {
// Note: the type assigned to query profile and constant tensors here is not the correct type
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
QueryProfileRegistry queryProfiles = queryProfileWith("query(q)", "tensor(x[])");
SearchBuilder builder = new SearchBuilder(rankProfileRegistry, queryProfiles);
builder.importString("search test {\n" + " document test { \n" + " field a type string { \n" + " indexing: index \n" + " }\n" + " }\n" + " \n" + " rank-profile test {\n" + // relu is a built in function, redefined here
" macro relu(x) {\n" + " expression: max(1.0, x)\n" + " }\n" + " macro hidden_layer() {\n" + " expression: relu(sum(query(q) * constant(W_hidden), input) + constant(b_input))\n" + " }\n" + " macro final_layer() {\n" + " expression: sigmoid(sum(hidden_layer * constant(W_final), hidden) + constant(b_final))\n" + " }\n" + " second-phase {\n" + " expression: sum(final_layer)\n" + " }\n" + " }\n" + " constant W_hidden {\n" + " type: tensor(x[])\n" + " file: ignored.json\n" + " }\n" + " constant b_input {\n" + " type: tensor(x[])\n" + " file: ignored.json\n" + " }\n" + " constant W_final {\n" + " type: tensor(x[])\n" + " file: ignored.json\n" + " }\n" + " constant b_final {\n" + " type: tensor(x[])\n" + " file: ignored.json\n" + " }\n" + "}\n");
builder.build();
Search s = builder.getSearch();
RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(queryProfiles);
List<Pair<String, String>> testRankProperties = new RawRankProfile(test, queryProfiles, new AttributeFields(s)).configProperties();
assertEquals("(rankingExpression(relu).rankingScript,max(1.0,x))", testRankProperties.get(0).toString());
assertEquals("(rankingExpression(relu@).rankingScript,max(1.0,reduce(query(q) * constant(W_hidden), sum, input) + constant(b_input)))", censorBindingHash(testRankProperties.get(1).toString()));
assertEquals("(rankingExpression(hidden_layer).rankingScript,rankingExpression(relu@))", censorBindingHash(testRankProperties.get(2).toString()));
assertEquals("(rankingExpression(final_layer).rankingScript,sigmoid(reduce(rankingExpression(hidden_layer) * constant(W_final), sum, hidden) + constant(b_final)))", testRankProperties.get(3).toString());
assertEquals("(vespa.rank.secondphase,rankingExpression(secondphase))", testRankProperties.get(4).toString());
assertEquals("(rankingExpression(secondphase).rankingScript,reduce(rankingExpression(final_layer), sum))", testRankProperties.get(5).toString());
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class RankingExpressionShadowingTestCase method queryProfileWith.
private QueryProfileRegistry queryProfileWith(String field, String type) {
QueryProfileType queryProfileType = new QueryProfileType("root");
queryProfileType.addField(new FieldDescription(field, type));
QueryProfileRegistry queryProfileRegistry = new QueryProfileRegistry();
queryProfileRegistry.getTypeRegistry().register(queryProfileType);
QueryProfile profile = new QueryProfile("default");
profile.setType(queryProfileType);
queryProfileRegistry.register(profile);
return queryProfileRegistry;
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class SearchImporterTestCase method testSimpleImporting.
@Test
public void testSimpleImporting() throws IOException, ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
SearchBuilder sb = new UnprocessingSearchBuilder(rankProfileRegistry, new QueryProfileRegistry());
sb.importFile("src/test/examples/simple.sd");
sb.build();
Search search = sb.getSearch();
assertEquals("simple", search.getName());
assertTrue(search.hasDocument());
SDDocumentType document = search.getDocument();
assertEquals("simple", document.getName());
assertEquals(12, document.getFieldCount());
SDField field;
Attribute attribute;
new MakeAliases(search, new BaseDeployLogger(), rankProfileRegistry, new QueryProfiles()).process(true);
// First field
field = (SDField) document.getField("title");
assertEquals(DataType.STRING, field.getDataType());
assertEquals("{ summary | index; }", field.getIndexingScript().toString());
assertTrue(!search.getIndex("default").isPrefix());
assertTrue(search.getIndex("title").isPrefix());
Iterator<String> titleAliases = search.getIndex("title").aliasIterator();
assertEquals("aliaz", titleAliases.next());
assertEquals("analias.totitle", titleAliases.next());
assertEquals("analias.todefault", search.getIndex("default").aliasIterator().next());
assertEquals(RankType.IDENTITY, field.getRankType());
assertTrue(field.getAttributes().size() == 0);
assertNull(field.getStemming());
assertTrue(field.getNormalizing().doRemoveAccents());
assertTrue(field.isHeader());
// Second field
field = (SDField) document.getField("description");
assertEquals(RankType.ABOUT, field.getRankType());
assertEquals(SummaryTransform.NONE, field.getSummaryField("description").getTransform());
assertEquals(SummaryTransform.DYNAMICTEASER, field.getSummaryField("dyndesc").getTransform());
assertNull(field.getStemming());
assertTrue(field.getNormalizing().doRemoveAccents());
assertEquals("hallo", search.getIndex("description").aliasIterator().next());
// Third field
field = (SDField) document.getField("chatter");
assertEquals(RankType.ABOUT, field.getRankType());
assertNull(field.getStemming());
assertTrue(field.getNormalizing().doRemoveAccents());
// Fourth field
field = (SDField) document.getField("category");
assertEquals(0, field.getAttributes().size());
assertEquals(Stemming.NONE, field.getStemming());
assertTrue(!field.getNormalizing().doRemoveAccents());
// Fifth field
field = (SDField) document.getField("popularity");
assertEquals("{ attribute; }", field.getIndexingScript().toString());
// Sixth field
field = (SDField) document.getField("measurement");
assertEquals(DataType.INT, field.getDataType());
assertEquals(RankType.EMPTY, field.getRankType());
assertEquals(1, field.getAttributes().size());
// Seventh field
field = search.getConcreteField("categories");
assertEquals("{ input categories_src | lowercase | normalize | index; }", field.getIndexingScript().toString());
assertTrue(!field.isHeader());
// Eight field
field = search.getConcreteField("categoriesagain");
assertEquals("{ input categoriesagain_src | lowercase | normalize | index; }", field.getIndexingScript().toString());
assertTrue(field.isHeader());
// Ninth field
field = search.getConcreteField("exactemento");
assertEquals("{ input exactemento_src | lowercase | index | summary; }", field.getIndexingScript().toString());
// Tenth field
field = search.getConcreteField("category_arr");
assertEquals(1, field.getAttributes().size());
attribute = field.getAttributes().get("category_arr");
assertNotNull(attribute);
assertEquals("category_arr", attribute.getName());
assertEquals(Attribute.Type.STRING, attribute.getType());
assertEquals(Attribute.CollectionType.ARRAY, attribute.getCollectionType());
assertTrue(field.isHeader());
// Eleventh field
field = search.getConcreteField("measurement_arr");
assertEquals(1, field.getAttributes().size());
attribute = field.getAttributes().get("measurement_arr");
assertEquals("measurement_arr", attribute.getName());
assertEquals(Attribute.Type.INTEGER, attribute.getType());
assertEquals(Attribute.CollectionType.ARRAY, attribute.getCollectionType());
// Rank Profiles
RankProfile profile = rankProfileRegistry.getRankProfile(search, "default");
assertNotNull(profile);
assertNull(profile.getInheritedName());
assertEquals(null, profile.getDeclaredRankSetting("measurement", RankProfile.RankSetting.Type.RANKTYPE));
assertEquals(RankType.EMPTY, profile.getRankSetting("measurement", RankProfile.RankSetting.Type.RANKTYPE).getValue());
profile = rankProfileRegistry.getRankProfile(search, "experimental");
assertNotNull(profile);
assertEquals("default", profile.getInheritedName());
assertEquals(RankType.IDENTITY, profile.getDeclaredRankSetting("measurement", RankProfile.RankSetting.Type.RANKTYPE).getValue());
profile = rankProfileRegistry.getRankProfile(search, "other");
assertNotNull(profile);
assertEquals("experimental", profile.getInheritedName());
// The extra-document field
SDField exact = search.getConcreteField("exact");
assertNotNull("Extra field was parsed", exact);
assertEquals("exact", exact.getName());
assertEquals(Stemming.NONE, exact.getStemming());
assertTrue(!exact.getNormalizing().doRemoveAccents());
assertEquals("{ input title . \" \" . input category | summary | index; }", exact.getIndexingScript().toString());
assertEquals(RankType.IDENTITY, exact.getRankType());
}
Aggregations