use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class QueryProfileConfigurationTestCase method testVariant2ConfigurationThroughQueryLookup.
@Test
public void testVariant2ConfigurationThroughQueryLookup() {
QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profile-variants2.cfg");
CompiledQueryProfileRegistry registry = configurer.getCurrentRegistry().compile();
Query query = new Query(QueryTestCase.httpEncode("?query=heh&queryProfile=multi&myindex=default&myquery=lo ve&tracelevel=5"), registry.findQueryProfile("multi"));
assertEquals("love", query.properties().get("model.queryString"));
assertEquals("default", query.properties().get("model.defaultIndex"));
assertEquals("-20", query.properties().get("ranking.features.query(scorelimit)"));
assertEquals("-20", query.getRanking().getFeatures().get("query(scorelimit)"));
query.properties().set("rankfeature.query(scorelimit)", -30);
assertEquals("-30", query.properties().get("ranking.features.query(scorelimit)"));
assertEquals("-30", query.getRanking().getFeatures().get("query(scorelimit)"));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class XmlReadingTestCase method testValid.
@Test
public void testValid() {
QueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/validxml");
CompiledQueryProfileRegistry cRegistry = registry.compile();
QueryProfileType rootType = registry.getType("rootType");
assertEquals(1, rootType.inherited().size());
assertEquals("native", rootType.inherited().get(0).getId().getName());
assertTrue(rootType.isStrict());
assertTrue(rootType.getMatchAsPath());
FieldDescription timeField = rootType.getField("time");
assertTrue(timeField.isMandatory());
assertEquals("long", timeField.getType().toInstanceDescription());
FieldDescription userField = rootType.getField("user");
assertFalse(userField.isMandatory());
assertEquals("reference to a query profile of type 'user'", userField.getType().toInstanceDescription());
QueryProfileType user = registry.getType("user");
assertEquals(0, user.inherited().size());
assertFalse(user.isStrict());
assertFalse(user.getMatchAsPath());
assertTrue(userField.isOverridable());
FieldDescription ageField = user.getField("age");
assertTrue(ageField.isMandatory());
assertEquals("integer", ageField.getType().toInstanceDescription());
FieldDescription robotField = user.getField("robot");
assertFalse(robotField.isMandatory());
assertFalse(robotField.isOverridable());
assertEquals("boolean", robotField.getType().toInstanceDescription());
CompiledQueryProfile defaultProfile = cRegistry.getComponent("default");
assertNull(defaultProfile.getType());
assertEquals("20", defaultProfile.get("hits"));
assertFalse(defaultProfile.isOverridable(new CompoundName("hits"), null));
assertFalse(defaultProfile.isOverridable(new CompoundName("user.trusted"), null));
assertEquals("false", defaultProfile.get("user.trusted"));
CompiledQueryProfile referencingProfile = cRegistry.getComponent("referencingModelSettings");
assertNull(referencingProfile.getType());
assertEquals("some query", referencingProfile.get("model.queryString"));
assertEquals("aDefaultIndex", referencingProfile.get("model.defaultIndex"));
// Request parameters here should be ignored
HttpRequest request = HttpRequest.createTestRequest("?query=foo&user.trusted=true&default-index=title", Method.GET);
Query query = new Query(request, defaultProfile);
assertEquals("false", query.properties().get("user.trusted"));
assertEquals("default", query.getModel().getDefaultIndex());
assertEquals("default", query.properties().get("default-index"));
CompiledQueryProfile rootProfile = cRegistry.getComponent("root");
assertEquals("rootType", rootProfile.getType().getId().getName());
assertEquals(30, rootProfile.get("hits"));
assertEquals(3, rootProfile.get("traceLevel"));
assertTrue(rootProfile.isOverridable(new CompoundName("hits"), null));
QueryProfile someUser = registry.getComponent("someUser");
assertEquals("5", someUser.get("sub.test"));
assertEquals(18, someUser.get("age"));
// aliases
assertEquals(18, someUser.get("alder"));
assertEquals(18, someUser.get("anno"));
assertEquals(18, someUser.get("aLdER"));
assertEquals(18, someUser.get("ANNO"));
// Only aliases are case insensitive
assertNull(someUser.get("Age"));
Map<String, String> context = new HashMap<>();
context.put("x", "x1");
assertEquals(37, someUser.get("alder", context, null));
assertEquals(37, someUser.get("anno", context, null));
assertEquals(37, someUser.get("aLdER", context, null));
assertEquals(37, someUser.get("ANNO", context, null));
assertEquals("male", someUser.get("gender", context, null));
assertEquals("male", someUser.get("sex", context, null));
assertEquals("male", someUser.get("Sex", context, null));
// Only aliases are case insensitive
assertNull(someUser.get("Gender", context, null));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class XmlReadingTestCase method testVersionRefs.
@Test
public void testVersionRefs() {
CompiledQueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/versionrefs").compile();
Query query = new Query(HttpRequest.createTestRequest("?query=test", Method.GET), registry.getComponent("default"));
assertEquals("MyProfile:1.0.2", query.properties().get("profile1.name"));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class XmlReadingTestCase method testSystemtest.
/**
* Tests a subset of the configuration in the system test of this
*/
@Test
public void testSystemtest() {
String queryString = "?query=test";
QueryProfileXMLReader reader = new QueryProfileXMLReader();
CompiledQueryProfileRegistry registry = reader.read("src/test/java/com/yahoo/search/query/profile/config/test/systemtest/").compile();
HttpRequest request = HttpRequest.createTestRequest(queryString, Method.GET);
CompiledQueryProfile profile = registry.findQueryProfile("default");
Query query = new Query(request, profile);
Properties p = query.properties();
assertEquals("test", query.getModel().getQueryString());
assertEquals("test", p.get("query"));
assertEquals("test", p.get("QueRY"));
assertEquals("test", p.get("model.queryString"));
assertEquals("bar", p.get("foo"));
assertEquals(5, p.get("hits"));
assertEquals("tit", p.get("subst"));
assertEquals("le", p.get("subst.end"));
assertEquals("title", p.get("model.defaultIndex"));
Map<String, Object> ps = p.listProperties();
assertEquals(6, ps.size());
assertEquals("bar", ps.get("foo"));
assertEquals("5", ps.get("hits"));
assertEquals("tit", ps.get("subst"));
assertEquals("le", ps.get("subst.end"));
assertEquals("title", ps.get("model.defaultIndex"));
assertEquals("test", ps.get("model.queryString"));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class XmlReadingTestCase method testQueryProfileVariants.
@Test
public void testQueryProfileVariants() {
String query = "?query=test&dim1=yahoo&dim2=uk&dim3=test";
QueryProfileXMLReader reader = new QueryProfileXMLReader();
CompiledQueryProfileRegistry registry = reader.read("src/test/java/com/yahoo/search/query/profile/config/test/news/").compile();
HttpRequest request = HttpRequest.createTestRequest(query, Method.GET);
CompiledQueryProfile profile = registry.findQueryProfile("default");
Query q = new Query(request, profile);
assertEquals("c", q.properties().get("a.c"));
assertEquals("b", q.properties().get("a.b"));
}
Aggregations