Search in sources :

Example 1 with Properties

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

the class FederationSearcher method getSourceProperties.

/**
 * Returns the set of properties set for the source or provider given in the query (if any).
 *
 * If the query has not set sourceName or providerName, null will be returned
 */
public static Properties getSourceProperties(Query query) {
    String sourceName = query.properties().getString(SOURCENAME);
    String providerName = query.properties().getString(PROVIDERNAME);
    if (sourceName == null || providerName == null)
        return null;
    Properties sourceProperties = new SubProperties("source." + sourceName, query.properties());
    Properties providerProperties = new SubProperties("provider." + providerName, query.properties());
    sourceProperties.chain(providerProperties);
    return sourceProperties;
}
Also used : SubProperties(com.yahoo.search.query.properties.SubProperties) QueryProperties(com.yahoo.search.query.properties.QueryProperties) PropagateSourceProperties(com.yahoo.search.federation.StrictContractsConfig.PropagateSourceProperties) Properties(com.yahoo.search.query.Properties) SubProperties(com.yahoo.search.query.properties.SubProperties)

Example 2 with Properties

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

the class GetSearcher method doGetDocuments.

private void doGetDocuments(Query query, Result result, List<String> documentIds) {
    GetResponse response = new GetResponse(documentIds);
    Properties properties = query.properties();
    boolean headersOnly = properties.getBoolean(HEADERS_ONLY, false);
    boolean populateHitFields = properties.getBoolean(POPULATE_HIT_FIELDS, false);
    String fieldSet = properties.getString(FIELDSET);
    String fieldName = properties.getString(FIELD);
    String contentType = properties.getString(CONTENT_TYPE);
    long timeoutMillis = properties.getString(TIEMOUT) != null ? query.getTimeout() : defaultTimeoutMillis;
    if (fieldSet == null) {
        fieldSet = headersOnly ? "[header]" : "[all]";
    }
    validateParameters(fieldName, contentType, documentIds);
    MessagePropertyProcessor.PropertySetter propertySetter;
    propertySetter = context.getPropertyProcessor().buildPropertySetter(query.getHttpRequest());
    SingleSender sender = new SingleSender(response, context.getSharedSender(propertySetter.getRoute().toString()));
    sender.addMessageProcessor(propertySetter);
    sendDocumentGetMessages(documentIds, fieldSet, sender);
    // Twiddle thumbs until we've received a reply for all documents
    sender.done();
    boolean completed = sender.waitForPending(timeoutMillis);
    if (!completed) {
        result.hits().addError(ErrorMessage.createTimeout("Timed out after waiting " + timeoutMillis + " ms for responses"));
    }
    response.processReplies();
    if (fieldName != null) {
        handleFieldFiltering(response, result, fieldName, contentType, headersOnly);
    } else {
        response.addHitsToResult(result, populateHitFields);
    }
}
Also used : Properties(com.yahoo.search.query.Properties)

Example 3 with Properties

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

the class QueryProfileVariantsTestCase method testListVariantPropertiesCompounds1.

public void testListVariantPropertiesCompounds1() {
    QueryProfile parent1 = new QueryProfile("parent1");
    // Defined everywhere
    parent1.set("a.p1", "parent1-a", (QueryProfileRegistry) null);
    // Defined everywhere, but no variants
    parent1.set("b.p1", "parent1-b", (QueryProfileRegistry) null);
    // Defined in both parents only
    parent1.set("c.p1", "parent1-c", (QueryProfileRegistry) null);
    QueryProfile parent2 = new QueryProfile("parent2");
    parent2.set("a.p1", "parent2-a", (QueryProfileRegistry) null);
    parent2.set("b.p1", "parent2-b", (QueryProfileRegistry) null);
    parent2.set("c.p1", "parent2-c", (QueryProfileRegistry) null);
    // Defined in second parent only
    parent2.set("d.p1", "parent2-d", (QueryProfileRegistry) null);
    QueryProfile main = new QueryProfile("main");
    main.setDimensions(new String[] { "x", "y" });
    main.addInherited(parent1);
    main.addInherited(parent2);
    main.set("a.p1", "main-a", (QueryProfileRegistry) null);
    main.set("a.p1", "main-a-x1", new String[] { "x1" }, null);
    // Defined in two variants only
    main.set("e.p1", "main-e-x1", new String[] { "x1" }, null);
    // Defined in one variants only
    main.set("f.p1", "main-f-x1", new String[] { "x1" }, null);
    main.set("a.p1", "main-a-x1.y1", new String[] { "x1", "y1" }, null);
    main.set("a.p1", "main-a-x1.y2", new String[] { "x1", "y2" }, null);
    main.set("e.p1", "main-e-x1.y2", new String[] { "x1", "y2" }, null);
    // Defined in one variant only
    main.set("g.p1", "main-g-x1.y2", new String[] { "x1", "y2" }, null);
    main.set("b.p1", "main-b", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant1 = new QueryProfile("inheritedVariant1");
    inheritedVariant1.set("a.p1", "inheritedVariant1-a", (QueryProfileRegistry) null);
    // Only defined in two inherited variants
    inheritedVariant1.set("h.p1", "inheritedVariant1-h", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant2 = new QueryProfile("inheritedVariant2");
    inheritedVariant2.set("a.p1", "inheritedVariant2-a", (QueryProfileRegistry) null);
    // Only defined in two inherited variants
    inheritedVariant2.set("h.p1", "inheritedVariant2-h", (QueryProfileRegistry) null);
    // Only defined in one inherited variant
    inheritedVariant2.set("i.p1", "inheritedVariant2-i", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant3 = new QueryProfile("inheritedVariant3");
    // Only defined in one inherited variant, but inherited twice
    inheritedVariant3.set("j.p1", "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("a.p1"));
    assertEquals("main-b", listed.get("b.p1"));
    assertEquals("parent1-c", listed.get("c.p1"));
    assertEquals("parent2-d", listed.get("d.p1"));
    // Context x=x1
    listed = properties.listProperties(toMap(main, new String[] { "x1" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1", listed.get("a.p1"));
    assertEquals("main-b", listed.get("b.p1"));
    assertEquals("parent1-c", listed.get("c.p1"));
    assertEquals("parent2-d", listed.get("d.p1"));
    assertEquals("main-e-x1", listed.get("e.p1"));
    assertEquals("main-f-x1", listed.get("f.p1"));
    assertEquals("inheritedVariant1-h", listed.get("h.p1"));
    assertEquals("inheritedVariant3-j", listed.get("j.p1"));
    // 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.p1"));
    assertEquals("main-b", listed.get("b.p1"));
    assertEquals("parent1-c", listed.get("c.p1"));
    assertEquals("parent2-d", listed.get("d.p1"));
    assertEquals("main-e-x1", listed.get("e.p1"));
    assertEquals("main-f-x1", listed.get("f.p1"));
    assertEquals("inheritedVariant1-h", listed.get("h.p1"));
    assertEquals("inheritedVariant3-j", listed.get("j.p1"));
    // 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.p1"));
    assertEquals("main-b", listed.get("b.p1"));
    assertEquals("parent1-c", listed.get("c.p1"));
    assertEquals("parent2-d", listed.get("d.p1"));
    assertEquals("main-e-x1.y2", listed.get("e.p1"));
    assertEquals("main-f-x1", listed.get("f.p1"));
    assertEquals("main-g-x1.y2", listed.get("g.p1"));
    assertEquals("inheritedVariant2-h", listed.get("h.p1"));
    assertEquals("inheritedVariant2-i", listed.get("i.p1"));
    assertEquals("inheritedVariant3-j", listed.get("j.p1"));
    // 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.p1"));
    assertEquals("main-b", listed.get("b.p1"));
    assertEquals("parent1-c", listed.get("c.p1"));
    assertEquals("parent2-d", listed.get("d.p1"));
    assertEquals("main-e-x1", listed.get("e.p1"));
    assertEquals("main-f-x1", listed.get("f.p1"));
    assertEquals("inheritedVariant1-h", listed.get("h.p1"));
    assertEquals("inheritedVariant3-j", listed.get("j.p1"));
    // Context x=x2,y=y1
    listed = properties.listProperties(toMap(main, new String[] { "x2", "y1" }));
    assertEquals(expectedBaseSize, listed.size());
    assertEquals("main-a", listed.get("a.p1"));
    assertEquals("main-b", listed.get("b.p1"));
    assertEquals("parent1-c", listed.get("c.p1"));
    assertEquals("parent2-d", listed.get("d.p1"));
}
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 4 with Properties

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

the class QueryProfileVariantsTestCase method testVariantInheritanceOverridesBaseInheritanceComplex.

public void testVariantInheritanceOverridesBaseInheritanceComplex() {
    QueryProfile defaultQP = new QueryProfile("default");
    defaultQP.set("model.defaultIndex", "title", (QueryProfileRegistry) null);
    QueryProfile root = new QueryProfile("root");
    root.addInherited(defaultQP);
    root.set("model.defaultIndex", "default", (QueryProfileRegistry) null);
    QueryProfile querybest = new QueryProfile("querybest");
    querybest.set("defaultIndex", "title", (QueryProfileRegistry) null);
    querybest.set("queryString", "best", (QueryProfileRegistry) null);
    QueryProfile multi = new QueryProfile("multi");
    multi.setDimensions(new String[] { "x" });
    multi.addInherited(defaultQP);
    multi.set("model", querybest, (QueryProfileRegistry) null);
    multi.addInherited(root, new String[] { "x1" });
    multi.set("model.queryString", "love", new String[] { "x1" }, null);
    // Rumtimize
    defaultQP.freeze();
    root.freeze();
    querybest.freeze();
    multi.freeze();
    Properties runtime = new QueryProfileProperties(multi.compile(null));
    assertEquals("default", runtime.get("model.defaultIndex", toMap("x=x1")));
    assertEquals("love", runtime.get("model.queryString", toMap("x=x1")));
}
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 5 with Properties

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

the class QueryProfileVariantsTestCase method testQueryProfileReferences.

public void testQueryProfileReferences() {
    QueryProfile main = new QueryProfile("main");
    main.setDimensions(new String[] { "x1" });
    QueryProfile referencedMain = new QueryProfile("referencedMain");
    // In both
    referencedMain.set("r1", "mainReferenced-r1", (QueryProfileRegistry) null);
    // Only in this
    referencedMain.set("r2", "mainReferenced-r2", (QueryProfileRegistry) null);
    QueryProfile referencedVariant = new QueryProfile("referencedVariant");
    // In both
    referencedVariant.set("r1", "variantReferenced-r1", (QueryProfileRegistry) null);
    // Only in this
    referencedVariant.set("r3", "variantReferenced-r3", (QueryProfileRegistry) null);
    main.set("a", referencedMain, (QueryProfileRegistry) null);
    main.set("a", referencedVariant, new String[] { "x1" }, null);
    Properties properties = new QueryProfileProperties(main.compile(null));
    // No context
    Map<String, Object> listed = properties.listProperties();
    assertEquals(2, listed.size());
    assertEquals("mainReferenced-r1", listed.get("a.r1"));
    assertEquals("mainReferenced-r2", listed.get("a.r2"));
    // Context x=x1
    listed = properties.listProperties(toMap(main, new String[] { "x1" }));
    assertEquals(3, listed.size());
    assertEquals("variantReferenced-r1", listed.get("a.r1"));
    assertEquals("mainReferenced-r2", listed.get("a.r2"));
    assertEquals("variantReferenced-r3", listed.get("a.r3"));
}
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