Search in sources :

Example 61 with SDField

use of com.yahoo.searchdefinition.document.SDField in project vespa by vespa-engine.

the class InheritanceTestCase method testIndexSettingInheritance.

@Test
public void testIndexSettingInheritance() {
    SDDocumentType parent = new SDDocumentType("parent");
    Search parentSearch = new Search("parent", null);
    parentSearch.addDocument(parent);
    SDField prefixed = parent.addField("prefixed", DataType.STRING);
    prefixed.parseIndexingScript("{ index }");
    prefixed.addIndex(new Index("prefixed", true));
    SDDocumentType child = new SDDocumentType("child");
    child.inherit(parent);
    Search childSearch = new Search("child", null);
    childSearch.addDocument(child);
    prefixed = (SDField) child.getField("prefixed");
    assertNotNull(prefixed);
    assertEquals(new Index("prefixed", true), childSearch.getIndex("prefixed"));
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Search(com.yahoo.searchdefinition.Search) Index(com.yahoo.searchdefinition.Index) Test(org.junit.Test)

Example 62 with SDField

use of com.yahoo.searchdefinition.document.SDField in project vespa by vespa-engine.

the class LiteralBoostTestCase method testTwoLiteralBoostFields.

/**
 * Tests literal boosts in two fields going to the same index
 */
@Test
public void testTwoLiteralBoostFields() {
    Search search = new Search("msb", null);
    RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);
    SDDocumentType document = new SDDocumentType("msb");
    search.addDocument(document);
    SDField field1 = document.addField("title", DataType.STRING);
    field1.parseIndexingScript("{ summary | index }");
    field1.setLiteralBoost(20);
    SDField field2 = document.addField("body", DataType.STRING);
    field2.parseIndexingScript("{ summary | index }");
    field2.setLiteralBoost(20);
    search = SearchBuilder.buildFromRawSearch(search, rankProfileRegistry, new QueryProfileRegistry());
    new DerivedConfiguration(search, rankProfileRegistry, new QueryProfileRegistry());
    assertIndexing(Arrays.asList("clear_state | guard { input title | tokenize normalize stem:\"SHORTEST\" | summary title | index title; }", "clear_state | guard { input body | tokenize normalize stem:\"SHORTEST\" | summary body | index body; }", "clear_state | guard { input title | tokenize | index title_literal; }", "clear_state | guard { input body | tokenize | index body_literal; }"), search);
}
Also used : RankProfileRegistry(com.yahoo.searchdefinition.RankProfileRegistry) SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Search(com.yahoo.searchdefinition.Search) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) Test(org.junit.Test)

Example 63 with SDField

use of com.yahoo.searchdefinition.document.SDField in project vespa by vespa-engine.

the class LiteralBoostTestCase method testNonDefaultRankLiteralBoost.

/**
 * Tests adding a literal boost in a non-default rank profile only
 */
@Test
public void testNonDefaultRankLiteralBoost() {
    Search search = new Search("literalboost", null);
    RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);
    SDDocumentType document = new SDDocumentType("literalboost");
    search.addDocument(document);
    SDField field1 = document.addField("a", DataType.STRING);
    field1.parseIndexingScript("{ index }");
    RankProfile other = new RankProfile("other", search, rankProfileRegistry);
    rankProfileRegistry.addRankProfile(other);
    other.addRankSetting(new RankProfile.RankSetting("a", RankProfile.RankSetting.Type.LITERALBOOST, 333));
    search = SearchBuilder.buildFromRawSearch(search, rankProfileRegistry, new QueryProfileRegistry());
    DerivedConfiguration derived = new DerivedConfiguration(search, rankProfileRegistry, new QueryProfileRegistry());
    // Check il script addition
    assertIndexing(Arrays.asList("clear_state | guard { input a | tokenize normalize stem:\"SHORTEST\" | index a; }", "clear_state | guard { input a | tokenize | index a_literal; }"), search);
    // Check index info addition
    IndexInfo indexInfo = derived.getIndexInfo();
    assertTrue(indexInfo.hasCommand("a", "literal-boost"));
}
Also used : RankProfileRegistry(com.yahoo.searchdefinition.RankProfileRegistry) SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Search(com.yahoo.searchdefinition.Search) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) RankProfile(com.yahoo.searchdefinition.RankProfile) Test(org.junit.Test)

Example 64 with SDField

use of com.yahoo.searchdefinition.document.SDField in project vespa by vespa-engine.

the class TypeConversionTestCase method testExactStringToStringTypeConversion.

/**
 * Tests that exact-string stuff is not spilled over to the default index
 */
@Test
public void testExactStringToStringTypeConversion() {
    Search search = new Search("test", null);
    RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);
    SDDocumentType document = new SDDocumentType("test");
    search.addDocument(document);
    SDField a = new SDField("a", DataType.STRING);
    a.parseIndexingScript("{ index }");
    document.addField(a);
    Processing.process(search, new BaseDeployLogger(), rankProfileRegistry, new QueryProfiles(), true);
    DerivedConfiguration derived = new DerivedConfiguration(search, rankProfileRegistry, new QueryProfileRegistry());
    IndexInfo indexInfo = derived.getIndexInfo();
    assertFalse(indexInfo.hasCommand("default", "compact-to-term"));
}
Also used : RankProfileRegistry(com.yahoo.searchdefinition.RankProfileRegistry) SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) BaseDeployLogger(com.yahoo.config.model.application.provider.BaseDeployLogger) Search(com.yahoo.searchdefinition.Search) QueryProfiles(com.yahoo.vespa.model.container.search.QueryProfiles) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) Test(org.junit.Test)

Example 65 with SDField

use of com.yahoo.searchdefinition.document.SDField in project vespa by vespa-engine.

the class ImplicitSummaries method isValid.

// Returns whether this is valid. Warns if invalid and ignorable. Throws if not ignorable.
private boolean isValid(SummaryField summaryField, Search search, boolean validate) {
    if (summaryField.getTransform() == SummaryTransform.DISTANCE || summaryField.getTransform() == SummaryTransform.POSITIONS) {
        int sourceCount = summaryField.getSourceCount();
        if (validate && sourceCount != 1) {
            throw newProcessException(search.getName(), summaryField.getName(), "Expected 1 source field, got " + sourceCount + ".");
        }
        String sourceName = summaryField.getSingleSource();
        if (validate && search.getAttribute(sourceName) == null) {
            throw newProcessException(search.getName(), summaryField.getName(), "Summary source attribute '" + sourceName + "' not found.");
        }
        return true;
    }
    String fieldName = summaryField.getSourceField();
    SDField sourceField = search.getConcreteField(fieldName);
    if (validate && sourceField == null) {
        throw newProcessException(search, summaryField, "Source field '" + fieldName + "' does not exist.");
    }
    if (!sourceField.doesSummarying() && !summaryField.getTransform().equals(SummaryTransform.ATTRIBUTE) && !summaryField.getTransform().equals(SummaryTransform.GEOPOS)) {
        // Summary transform attribute may indicate that the ilscript was rewritten to remove summary
        // by another search that uses this same field in inheritance.
        deployLogger.log(Level.WARNING, "Ignoring " + summaryField + ": " + sourceField + " is not creating a summary value in its indexing statement");
        return false;
    }
    if (summaryField.getTransform().isDynamic() && summaryField.getName().equals(sourceField.getName()) && sourceField.doesAttributing()) {
        Attribute attribute = sourceField.getAttributes().get(sourceField.getName());
        if (attribute != null) {
            String destinations = "document summary 'default'";
            if (summaryField.getDestinations().size() > 0) {
                destinations = "document summaries " + summaryField.getDestinations();
            }
            deployLogger.log(Level.WARNING, "Will fetch the disk summary value of " + sourceField + " in " + destinations + " since this summary field uses a dynamic summary value (snippet/bolding): Dynamic summaries and bolding " + "is not supported with summary values fetched from in-memory attributes yet. If you want to see partial updates " + "to this attribute, remove any bolding and dynamic snippeting from this field");
        // Note: The dynamic setting has already overridden the attribute map setting,
        // so we do not need to actually do attribute.setSummary(false) here
        // Also, we can not do this, since it makes it impossible to fetch this attribute
        // in another summary
        }
    }
    return true;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute)

Aggregations

SDField (com.yahoo.searchdefinition.document.SDField)85 Test (org.junit.Test)33 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)22 Search (com.yahoo.searchdefinition.Search)15 Attribute (com.yahoo.searchdefinition.document.Attribute)11 Index (com.yahoo.searchdefinition.Index)7 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)7 ArrayList (java.util.ArrayList)7 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)6 Field (com.yahoo.document.Field)6 SummaryField (com.yahoo.vespa.documentmodel.SummaryField)6 ScriptExpression (com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)6 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)5 ImmutableSDField (com.yahoo.searchdefinition.document.ImmutableSDField)5 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)5 ArrayDataType (com.yahoo.document.ArrayDataType)4 DataType (com.yahoo.document.DataType)4 DocumentReference (com.yahoo.searchdefinition.DocumentReference)4 RankProfile (com.yahoo.searchdefinition.RankProfile)4 TemporarySDField (com.yahoo.searchdefinition.document.TemporarySDField)4