Search in sources :

Example 6 with Properties

use of com.yahoo.search.query.Properties in project vespa by vespa-engine.

the class QueryProfileVariantsTestCase method testListVariantPropertiesCompounds2.

public void testListVariantPropertiesCompounds2() {
    QueryProfile parent1 = new QueryProfile("parent1");
    // Defined everywhere
    parent1.set("p1.a", "parent1-a", (QueryProfileRegistry) null);
    // Defined everywhere, but no variants
    parent1.set("p1.b", "parent1-b", (QueryProfileRegistry) null);
    // Defined in both parents only
    parent1.set("p1.c", "parent1-c", (QueryProfileRegistry) null);
    QueryProfile parent2 = new QueryProfile("parent2");
    parent2.set("p1.a", "parent2-a", (QueryProfileRegistry) null);
    parent2.set("p1.b", "parent2-b", (QueryProfileRegistry) null);
    parent2.set("p1.c", "parent2-c", (QueryProfileRegistry) null);
    // Defined in second parent only
    parent2.set("p1.d", "parent2-d", (QueryProfileRegistry) null);
    QueryProfile main = new QueryProfile("main");
    main.setDimensions(new String[] { "x", "y" });
    main.addInherited(parent1);
    main.addInherited(parent2);
    main.set("p1.a", "main-a", (QueryProfileRegistry) null);
    main.set("p1.a", "main-a-x1", new String[] { "x1" }, null);
    // Defined in two variants only
    main.set("p1.e", "main-e-x1", new String[] { "x1" }, null);
    // Defined in one variants only
    main.set("p1.f", "main-f-x1", new String[] { "x1" }, null);
    main.set("p1.a", "main-a-x1.y1", new String[] { "x1", "y1" }, null);
    main.set("p1.a", "main-a-x1.y2", new String[] { "x1", "y2" }, null);
    main.set("p1.e", "main-e-x1.y2", new String[] { "x1", "y2" }, null);
    // Defined in one variant only
    main.set("p1.g", "main-g-x1.y2", new String[] { "x1", "y2" }, null);
    main.set("p1.b", "main-b", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant1 = new QueryProfile("inheritedVariant1");
    inheritedVariant1.set("p1.a", "inheritedVariant1-a", (QueryProfileRegistry) null);
    // Only defined in two inherited variants
    inheritedVariant1.set("p1.h", "inheritedVariant1-h", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant2 = new QueryProfile("inheritedVariant2");
    inheritedVariant2.set("p1.a", "inheritedVariant2-a", (QueryProfileRegistry) null);
    // Only defined in two inherited variants
    inheritedVariant2.set("p1.h", "inheritedVariant2-h", (QueryProfileRegistry) null);
    // Only defined in one inherited variant
    inheritedVariant2.set("p1.i", "inheritedVariant2-i", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant3 = new QueryProfile("inheritedVariant3");
    // Only defined in one inherited variant, but inherited twice
    inheritedVariant3.set("p1.j", "inheritedVariant3-j", (QueryProfileRegistry) null);
    main.addInherited(inheritedVariant1, new String[] { "x1" });
    main.addInherited(inheritedVariant3, new String[] { "x1" });
    main.addInherited(inheritedVariant2, new String[] { "x1", "y2" });
    main.addInherited(inheritedVariant3, new String[] { "x1", "y2" });
    Properties properties = new QueryProfileProperties(main.compile(null));
    int expectedBaseSize = 4;
    // No context
    Map<String, Object> listed = properties.listProperties();
    assertEquals(expectedBaseSize, listed.size());
    assertEquals("main-a", listed.get("p1.a"));
    assertEquals("main-b", listed.get("p1.b"));
    assertEquals("parent1-c", listed.get("p1.c"));
    assertEquals("parent2-d", listed.get("p1.d"));
    // Context x=x1
    listed = properties.listProperties(toMap(main, new String[] { "x1" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1", listed.get("p1.a"));
    assertEquals("main-b", listed.get("p1.b"));
    assertEquals("parent1-c", listed.get("p1.c"));
    assertEquals("parent2-d", listed.get("p1.d"));
    assertEquals("main-e-x1", listed.get("p1.e"));
    assertEquals("main-f-x1", listed.get("p1.f"));
    assertEquals("inheritedVariant1-h", listed.get("p1.h"));
    assertEquals("inheritedVariant3-j", listed.get("p1.j"));
    // Context x=x1,y=y1
    listed = properties.listProperties(toMap(main, new String[] { "x1", "y1" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1.y1", listed.get("p1.a"));
    assertEquals("main-b", listed.get("p1.b"));
    assertEquals("parent1-c", listed.get("p1.c"));
    assertEquals("parent2-d", listed.get("p1.d"));
    assertEquals("main-e-x1", listed.get("p1.e"));
    assertEquals("main-f-x1", listed.get("p1.f"));
    assertEquals("inheritedVariant1-h", listed.get("p1.h"));
    assertEquals("inheritedVariant3-j", listed.get("p1.j"));
    // Context x=x1,y=y2
    listed = properties.listProperties(toMap(main, new String[] { "x1", "y2" }));
    assertEquals(expectedBaseSize + 6, listed.size());
    assertEquals("main-a-x1.y2", listed.get("p1.a"));
    assertEquals("main-b", listed.get("p1.b"));
    assertEquals("parent1-c", listed.get("p1.c"));
    assertEquals("parent2-d", listed.get("p1.d"));
    assertEquals("main-e-x1.y2", listed.get("p1.e"));
    assertEquals("main-f-x1", listed.get("p1.f"));
    assertEquals("main-g-x1.y2", listed.get("p1.g"));
    assertEquals("inheritedVariant2-h", listed.get("p1.h"));
    assertEquals("inheritedVariant2-i", listed.get("p1.i"));
    assertEquals("inheritedVariant3-j", listed.get("p1.j"));
    // Context x=x1,y=y3
    listed = properties.listProperties(toMap(main, new String[] { "x1", "y3" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1", listed.get("p1.a"));
    assertEquals("main-b", listed.get("p1.b"));
    assertEquals("parent1-c", listed.get("p1.c"));
    assertEquals("parent2-d", listed.get("p1.d"));
    assertEquals("main-e-x1", listed.get("p1.e"));
    assertEquals("main-f-x1", listed.get("p1.f"));
    assertEquals("inheritedVariant1-h", listed.get("p1.h"));
    assertEquals("inheritedVariant3-j", listed.get("p1.j"));
    // Context x=x2,y=y1
    listed = properties.listProperties(toMap(main, new String[] { "x2", "y1" }));
    assertEquals(expectedBaseSize, listed.size());
    assertEquals("main-a", listed.get("p1.a"));
    assertEquals("main-b", listed.get("p1.b"));
    assertEquals("parent1-c", listed.get("p1.c"));
    assertEquals("parent2-d", listed.get("p1.d"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) BackedOverridableQueryProfile(com.yahoo.search.query.profile.BackedOverridableQueryProfile) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties) Properties(com.yahoo.search.query.Properties) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties)

Example 7 with Properties

use of com.yahoo.search.query.Properties in project vespa by vespa-engine.

the class QueryProfileVariantsTestCase method testListVariantPropertiesNoCompounds.

public void testListVariantPropertiesNoCompounds() {
    QueryProfile parent1 = new QueryProfile("parent1");
    // Defined everywhere
    parent1.set("a", "parent1-a", (QueryProfileRegistry) null);
    // Defined everywhere, but no variants
    parent1.set("b", "parent1-b", (QueryProfileRegistry) null);
    // Defined in both parents only
    parent1.set("c", "parent1-c", (QueryProfileRegistry) null);
    QueryProfile parent2 = new QueryProfile("parent2");
    parent2.set("a", "parent2-a", (QueryProfileRegistry) null);
    parent2.set("b", "parent2-b", (QueryProfileRegistry) null);
    parent2.set("c", "parent2-c", (QueryProfileRegistry) null);
    // Defined in second parent only
    parent2.set("d", "parent2-d", (QueryProfileRegistry) null);
    QueryProfile main = new QueryProfile("main");
    main.setDimensions(new String[] { "x", "y" });
    main.addInherited(parent1);
    main.addInherited(parent2);
    main.set("a", "main-a", (QueryProfileRegistry) null);
    main.set("a", "main-a-x1", new String[] { "x1" }, null);
    // Defined in two variants only
    main.set("e", "main-e-x1", new String[] { "x1" }, null);
    // Defined in one variants only
    main.set("f", "main-f-x1", new String[] { "x1" }, null);
    main.set("a", "main-a-x1.y1", new String[] { "x1", "y1" }, null);
    main.set("a", "main-a-x1.y2", new String[] { "x1", "y2" }, null);
    main.set("e", "main-e-x1.y2", new String[] { "x1", "y2" }, null);
    // Defined in one variant only
    main.set("g", "main-g-x1.y2", new String[] { "x1", "y2" }, null);
    main.set("b", "main-b", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant1 = new QueryProfile("inheritedVariant1");
    inheritedVariant1.set("a", "inheritedVariant1-a", (QueryProfileRegistry) null);
    // Only defined in two inherited variants
    inheritedVariant1.set("h", "inheritedVariant1-h", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant2 = new QueryProfile("inheritedVariant2");
    inheritedVariant2.set("a", "inheritedVariant2-a", (QueryProfileRegistry) null);
    // Only defined in two inherited variants
    inheritedVariant2.set("h", "inheritedVariant2-h", (QueryProfileRegistry) null);
    // Only defined in one inherited variant
    inheritedVariant2.set("i", "inheritedVariant2-i", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant3 = new QueryProfile("inheritedVariant3");
    // Only defined in one inherited variant, but inherited twice
    inheritedVariant3.set("j", "inheritedVariant3-j", (QueryProfileRegistry) null);
    main.addInherited(inheritedVariant1, new String[] { "x1" });
    main.addInherited(inheritedVariant3, new String[] { "x1" });
    main.addInherited(inheritedVariant2, new String[] { "x1", "y2" });
    main.addInherited(inheritedVariant3, new String[] { "x1", "y2" });
    // Runtime-ify
    Properties properties = new QueryProfileProperties(main.compile(null));
    int expectedBaseSize = 4;
    // No context
    Map<String, Object> listed = properties.listProperties();
    assertEquals(expectedBaseSize, listed.size());
    assertEquals("main-a", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    // Context x=x1
    listed = properties.listProperties(toMap(main, new String[] { "x1" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    assertEquals("main-e-x1", listed.get("e"));
    assertEquals("main-f-x1", listed.get("f"));
    assertEquals("inheritedVariant1-h", listed.get("h"));
    assertEquals("inheritedVariant3-j", listed.get("j"));
    // Context x=x1,y=y1
    listed = properties.listProperties(toMap(main, new String[] { "x1", "y1" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1.y1", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    assertEquals("main-e-x1", listed.get("e"));
    assertEquals("main-f-x1", listed.get("f"));
    assertEquals("inheritedVariant1-h", listed.get("h"));
    assertEquals("inheritedVariant3-j", listed.get("j"));
    // Context x=x1,y=y2
    listed = properties.listProperties(toMap(main, new String[] { "x1", "y2" }));
    assertEquals(expectedBaseSize + 6, listed.size());
    assertEquals("main-a-x1.y2", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    assertEquals("main-e-x1.y2", listed.get("e"));
    assertEquals("main-f-x1", listed.get("f"));
    assertEquals("main-g-x1.y2", listed.get("g"));
    assertEquals("inheritedVariant2-h", listed.get("h"));
    assertEquals("inheritedVariant2-i", listed.get("i"));
    assertEquals("inheritedVariant3-j", listed.get("j"));
    // Context x=x1,y=y3
    listed = properties.listProperties(toMap(main, new String[] { "x1", "y3" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    assertEquals("main-e-x1", listed.get("e"));
    assertEquals("main-f-x1", listed.get("f"));
    assertEquals("inheritedVariant1-h", listed.get("h"));
    assertEquals("inheritedVariant3-j", listed.get("j"));
    // Context x=x2,y=y1
    listed = properties.listProperties(toMap(main, new String[] { "x2", "y1" }));
    assertEquals(expectedBaseSize, listed.size());
    assertEquals("main-a", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) BackedOverridableQueryProfile(com.yahoo.search.query.profile.BackedOverridableQueryProfile) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties) Properties(com.yahoo.search.query.Properties) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties)

Example 8 with Properties

use of com.yahoo.search.query.Properties in project vespa by vespa-engine.

the class Query method init.

private void init(Map<String, String> requestMap, CompiledQueryProfile queryProfile) {
    startTime = System.currentTimeMillis();
    if (queryProfile != null) {
        // Move all request parameters to the query profile just to validate that the parameter settings are legal
        Properties queryProfileProperties = new QueryProfileProperties(queryProfile);
        properties().chain(queryProfileProperties);
        // TODO: Just checking legality rather than actually setting would be faster
        // Adds errors to the query for illegal set attempts
        setPropertiesFromRequestMap(requestMap, properties());
        // Create the full chain
        properties().chain(new QueryProperties(this, queryProfile.getRegistry())).chain(new ModelObjectMap()).chain(new RequestContextProperties(requestMap)).chain(queryProfileProperties).chain(new DefaultProperties());
        // Pass the values from the query profile which maps through a field in the Query object model
        // through the property chain to cause those values to be set in the Query object model
        setFieldsFrom(queryProfileProperties, requestMap);
    } else {
        // bypass these complications if there is no query profile to get values from and validate against
        properties().chain(new QueryProperties(this, CompiledQueryProfileRegistry.empty)).chain(new PropertyMap()).chain(new DefaultProperties());
        setPropertiesFromRequestMap(requestMap, properties());
    }
    properties().setParentQuery(this);
    traceProperties();
}
Also used : DefaultProperties(com.yahoo.search.query.properties.DefaultProperties) RequestContextProperties(com.yahoo.search.query.properties.RequestContextProperties) PropertyMap(com.yahoo.search.query.properties.PropertyMap) QueryProperties(com.yahoo.search.query.properties.QueryProperties) QueryProperties(com.yahoo.search.query.properties.QueryProperties) Properties(com.yahoo.search.query.Properties) RequestContextProperties(com.yahoo.search.query.properties.RequestContextProperties) DefaultProperties(com.yahoo.search.query.properties.DefaultProperties) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties) ModelObjectMap(com.yahoo.search.query.profile.ModelObjectMap) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties)

Example 9 with Properties

use of com.yahoo.search.query.Properties in project vespa by vespa-engine.

the class GetSearcher method getDocumentIds.

private List<String> getDocumentIds(Query query) throws Exception {
    Properties properties = query.properties();
    List<String> docIds = new ArrayList<>();
    // First check for regular "id=XX" syntax. If found, return vector with that
    // document id only
    String singleId = properties.getString(ID);
    int index = 0;
    if (singleId != null) {
        docIds.add(singleId);
    } else {
        // at 0 and are always increased by 1.
        while (true) {
            String docId = properties.getString("id[" + index + "]");
            if (docId == null) {
                break;
            }
            docIds.add(docId);
            ++index;
        }
        postValidateDocumentIdParameters(properties, index);
    }
    handleData(query.getHttpRequest(), docIds);
    return docIds;
}
Also used : Properties(com.yahoo.search.query.Properties)

Example 10 with Properties

use of com.yahoo.search.query.Properties in project vespa by vespa-engine.

the class QueryProfileVariantsTestCase method testDimensionsInSuperTypeRuntime.

public void testDimensionsInSuperTypeRuntime() {
    QueryProfile parent = new QueryProfile("parent");
    parent.setDimensions(new String[] { "x", "y" });
    QueryProfile child = new QueryProfile("child");
    child.addInherited(parent);
    child.set("a", "a.default", (QueryProfileRegistry) null);
    child.set("a", "a.x1.y1", new String[] { "x1", "y1" }, null);
    child.set("a", "a.x1.y2", new String[] { "x1", "y2" }, null);
    Properties overridable = new QueryProfileProperties(child.compile(null));
    assertEquals("a.default", child.get("a"));
    assertEquals("a.x1.y1", overridable.get("a", toMap("x=x1", "y=y1")));
    assertEquals("a.x1.y2", overridable.get("a", toMap("x=x1", "y=y2")));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) BackedOverridableQueryProfile(com.yahoo.search.query.profile.BackedOverridableQueryProfile) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties) Properties(com.yahoo.search.query.Properties) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties)

Aggregations

Properties (com.yahoo.search.query.Properties)13 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)9 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)9 BackedOverridableQueryProfile (com.yahoo.search.query.profile.BackedOverridableQueryProfile)8 QueryProfile (com.yahoo.search.query.profile.QueryProfile)8 QueryProperties (com.yahoo.search.query.properties.QueryProperties)2 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 Query (com.yahoo.search.Query)1 PropagateSourceProperties (com.yahoo.search.federation.StrictContractsConfig.PropagateSourceProperties)1 ModelObjectMap (com.yahoo.search.query.profile.ModelObjectMap)1 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)1 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)1 DefaultProperties (com.yahoo.search.query.properties.DefaultProperties)1 PropertyMap (com.yahoo.search.query.properties.PropertyMap)1 RequestContextProperties (com.yahoo.search.query.properties.RequestContextProperties)1 SubProperties (com.yahoo.search.query.properties.SubProperties)1 Test (org.junit.Test)1