use of com.yahoo.search.query.profile.QueryProfile 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.QueryProfile in project vespa by vespa-engine.
the class QueryProfileXMLReader method readFields.
private void readFields(Element element, QueryProfile profile, QueryProfileRegistry registry, DimensionValues dimensionValues, String sourceDescription) {
List<KeyValue> references = new ArrayList<>();
List<KeyValue> properties = new ArrayList<>();
for (Element field : XML.getChildren(element, "field")) {
String name = field.getAttribute("name");
if (name == null || name.equals(""))
throw new IllegalArgumentException("A field in " + sourceDescription + " has no 'name' attribute");
try {
Boolean overridable = getBooleanAttribute("overridable", null, field);
if (overridable != null)
profile.setOverridable(name, overridable, null);
Object fieldValue = readFieldValue(field, name, sourceDescription, registry);
if (fieldValue instanceof QueryProfile)
references.add(new KeyValue(name, fieldValue));
else
properties.add(new KeyValue(name, fieldValue));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid field '" + name + "' in " + sourceDescription, e);
}
}
// Must set references before properties
for (KeyValue keyValue : references) profile.set(keyValue.getKey(), keyValue.getValue(), dimensionValues, registry);
for (KeyValue keyValue : properties) profile.set(keyValue.getKey(), keyValue.getValue(), dimensionValues, registry);
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfileXMLReader method readInherited.
private void readInherited(Element element, QueryProfile profile, QueryProfileRegistry registry, DimensionValues dimensionValues, String sourceDescription) {
String inheritedString = element.getAttribute("inherits");
if (inheritedString == null || inheritedString.equals(""))
return;
for (String inheritedId : inheritedString.split(" ")) {
inheritedId = inheritedId.trim();
if (inheritedId.equals(""))
continue;
QueryProfile inheritedProfile = registry.getComponent(inheritedId);
if (inheritedProfile == null)
throw new IllegalArgumentException("Could not resolve inherited query profile '" + inheritedId + "' in " + sourceDescription);
profile.addInherited(inheritedProfile, dimensionValues);
}
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class FederationSearcherTestCase method testQueryProfileNestedReferencing.
@Test
public void testQueryProfileNestedReferencing() {
addChained(new MockSearcher(), "mySource1");
addChained(new MockSearcher(), "mySource2");
Chain<Searcher> mainChain = new Chain<>("default", createFederationSearcher());
QueryProfile defaultProfile = new QueryProfile("default");
defaultProfile.set("source.mySource1.hits", "%{hits}", null);
defaultProfile.freeze();
Query q = new Query(QueryTestCase.httpEncode("?query=test"), defaultProfile.compile(null));
Result result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(q);
assertNull(result.hits().getError());
assertEquals("source:mySource1", result.hits().get(0).getId().stringValue());
assertEquals("source:mySource2", result.hits().get(1).getId().stringValue());
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryTestCase method testQueryPropertyListingThreeLevel.
@Test
public void testQueryPropertyListingThreeLevel() {
QueryProfile defaultProfile = new QueryProfile("default");
defaultProfile.setDimensions(new String[] { "x" });
defaultProfile.set("a.b.c", "a.b.c-x1-value", new String[] { "x1" }, null);
defaultProfile.set("a.b.c", "a.b.c-x2-value", new String[] { "x2" }, null);
defaultProfile.freeze();
{
Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null));
Map<String, Object> propertyList = q.properties().listProperties();
assertEquals(3, propertyList.size());
assertEquals("a.b.c-x1-value", propertyList.get("a.b.c"));
}
{
Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null));
Map<String, Object> propertyList = q.properties().listProperties("a");
assertEquals(1, propertyList.size());
assertEquals("a.b.c-x1-value", propertyList.get("b.c"));
}
{
Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null));
Map<String, Object> propertyList = q.properties().listProperties("a.b");
assertEquals(1, propertyList.size());
assertEquals("a.b.c-x1-value", propertyList.get("c"));
}
{
Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x2"), defaultProfile.compile(null));
Map<String, Object> propertyList = q.properties().listProperties();
assertEquals(3, propertyList.size());
assertEquals("a.b.c-x2-value", propertyList.get("a.b.c"));
}
}
Aggregations