Search in sources :

Example 31 with SDDocumentType

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

the class VsmSummary method doMapField.

/**
 * Don't include field in map if sources are the same as the struct sub fields for the SDField.
 * But do map if not all do summarying.
 * Don't map if not struct either.
 * @param summaryField a {@link SummaryField}
 */
private boolean doMapField(Search search, SummaryField summaryField) {
    SDField sdField = search.getConcreteField(summaryField.getName());
    SDDocumentType document = search.getDocument();
    if (sdField == null || ((document != null) && (document.getField(summaryField.getName()) == sdField))) {
        return true;
    }
    if (summaryField.getVsmCommand().equals(SummaryField.VsmCommand.FLATTENJUNIPER)) {
        return true;
    }
    if (!sdField.usesStructOrMap()) {
        return !(sdField.getName().equals(summaryField.getName()));
    }
    if (summaryField.getSourceCount() == sdField.getStructFields().size()) {
        for (SummaryField.Source source : summaryField.getSources()) {
            if (!sdField.getStructFields().contains(new SDField(search.getDocument(), source.getName(), sdField.getDataType()))) {
                // equals() uses just name
                return true;
            }
            if (sdField.getStructField(source.getName()) != null && !sdField.getStructField(source.getName()).doesSummarying()) {
                return true;
            }
        }
        // Don't map.
        return false;
    }
    return true;
}
Also used : SummaryField(com.yahoo.vespa.documentmodel.SummaryField) SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType)

Example 32 with SDDocumentType

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

the class DocumentReferenceResolverTest method reference_from_one_document_to_another_is_resolved.

@Test
public void reference_from_one_document_to_another_is_resolved() {
    // Create bar document with no fields
    Search barSearch = new Search();
    SDDocumentType barDocument = new SDDocumentType("bar", barSearch);
    barSearch.addDocument(barDocument);
    // Create foo document with document reference to bar and add another field
    SDField fooRefToBarField = new SDField("bar_ref", ReferenceDataType.createWithInferredId(barDocument.getDocumentType()));
    addAttributeAspect(fooRefToBarField);
    SDField irrelevantField = new SDField("irrelevant_stuff", DataType.INT);
    Search fooSearch = new Search();
    SDDocumentType fooDocument = new SDDocumentType("foo", fooSearch);
    fooDocument.addField(fooRefToBarField);
    fooDocument.addField(irrelevantField);
    fooSearch.addDocument(fooDocument);
    DocumentReferenceResolver resolver = new DocumentReferenceResolver(asList(fooSearch, barSearch));
    resolver.resolveReferences(fooDocument);
    assertTrue(fooDocument.getDocumentReferences().isPresent());
    Map<String, DocumentReference> fooReferenceMap = fooDocument.getDocumentReferences().get().referenceMap();
    assertEquals(1, fooReferenceMap.size());
    assertSame(barSearch, fooReferenceMap.get("bar_ref").targetSearch());
    assertSame(fooRefToBarField, fooReferenceMap.get("bar_ref").referenceField());
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Test(org.junit.Test)

Example 33 with SDDocumentType

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

the class DocumentReferenceResolverTest method throws_exception_if_reference_is_not_an_attribute.

@Test
public void throws_exception_if_reference_is_not_an_attribute() {
    // Create bar document with no fields
    Search barSearch = new Search();
    SDDocumentType barDocument = new SDDocumentType("bar", barSearch);
    barSearch.addDocument(barDocument);
    // Create foo document with document reference to bar
    SDField fooRefToBarField = new SDField("bar_ref", ReferenceDataType.createWithInferredId(barDocument.getDocumentType()));
    Search fooSearch = new Search();
    SDDocumentType fooDocument = new SDDocumentType("foo", fooSearch);
    fooDocument.addField(fooRefToBarField);
    fooSearch.addDocument(fooDocument);
    DocumentReferenceResolver resolver = new DocumentReferenceResolver(asList(fooSearch, barSearch));
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("The field 'bar_ref' is an invalid document reference. The field must be an attribute.");
    resolver.resolveReferences(fooDocument);
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Test(org.junit.Test)

Example 34 with SDDocumentType

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

the class DocumentGraphValidatorTest method self_inheritance_forbidden.

@Test
public void self_inheritance_forbidden() {
    Search adSearch = createSearchWithName("ad");
    SDDocumentType document = adSearch.getDocument();
    document.inherit(document);
    DocumentGraphValidator validator = new DocumentGraphValidator();
    exceptionRule.expect(DocumentGraphValidator.DocumentGraphException.class);
    exceptionRule.expectMessage("Document dependency cycle detected: ad->ad.");
    validator.validateDocumentGraph(documentListOf(adSearch));
}
Also used : SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Test(org.junit.Test)

Example 35 with SDDocumentType

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

the class RankProfileTestCase method testRankProfileInheritance.

@Test
public void testRankProfileInheritance() {
    Search search = new Search("test", null);
    RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);
    SDDocumentType document = new SDDocumentType("test");
    SDField a = document.addField("a", DataType.STRING);
    a.setRankType(RankType.IDENTITY);
    document.addField("b", DataType.STRING);
    search.addDocument(document);
    RankProfile child = new RankProfile("child", search, rankProfileRegistry);
    child.setInherited("default");
    rankProfileRegistry.addRankProfile(child);
    Iterator<RankProfile.RankSetting> i = child.rankSettingIterator();
    RankProfile.RankSetting setting = i.next();
    assertEquals(RankType.IDENTITY, setting.getValue());
    assertEquals("a", setting.getFieldName());
    assertEquals(RankProfile.RankSetting.Type.RANKTYPE, setting.getType());
    setting = i.next();
    assertEquals(RankType.DEFAULT, setting.getValue());
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) Test(org.junit.Test)

Aggregations

SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)48 Test (org.junit.Test)28 SDField (com.yahoo.searchdefinition.document.SDField)23 Search (com.yahoo.searchdefinition.Search)21 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)7 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)6 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)6 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)5 TemporarySDField (com.yahoo.searchdefinition.document.TemporarySDField)4 ArrayList (java.util.ArrayList)4 DataTypeName (com.yahoo.document.DataTypeName)3 TemporarySDDocumentType (com.yahoo.searchdefinition.document.TemporarySDDocumentType)3 HashMap (java.util.HashMap)3 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)2 DocumentReferences (com.yahoo.searchdefinition.DocumentReferences)2 RankProfile (com.yahoo.searchdefinition.RankProfile)2 SearchBuilder (com.yahoo.searchdefinition.SearchBuilder)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 DataType (com.yahoo.document.DataType)1