Search in sources :

Example 46 with SDField

use of com.yahoo.searchdefinition.document.SDField 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 47 with SDField

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

the class AttributeSettingsTestCase method requireThatFastAccessCanBeSet.

@Test
public void requireThatFastAccessCanBeSet() throws IOException, ParseException {
    Search search = SearchBuilder.buildFromFile("src/test/examples/attributesettings.sd");
    SDField field = (SDField) search.getDocument().getField("fast_access");
    assertTrue(field.getAttributes().size() == 1);
    Attribute attr = field.getAttributes().get(field.getName());
    assertTrue(attr.isFastAccess());
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute) Test(org.junit.Test)

Example 48 with SDField

use of com.yahoo.searchdefinition.document.SDField 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 49 with SDField

use of com.yahoo.searchdefinition.document.SDField 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 50 with SDField

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

the class ArraysWeightedSetsTestCase method testArrayWeightedSetsImporting.

@Test
public void testArrayWeightedSetsImporting() throws java.io.IOException, com.yahoo.searchdefinition.parser.ParseException {
    Search search = SearchBuilder.buildFromFile("src/test/examples/arraysweightedsets.sd");
    SDField tags = (SDField) search.getDocument().getField("tags");
    assertTrue(tags.getDataType() instanceof ArrayDataType);
    assertEquals(DataType.STRING, ((CollectionDataType) tags.getDataType()).getNestedType());
    SDField ratings = (SDField) search.getDocument().getField("ratings");
    assertTrue(ratings.getDataType() instanceof ArrayDataType);
    assertEquals(DataType.INT, ((CollectionDataType) ratings.getDataType()).getNestedType());
    SDField flags = (SDField) search.getDocument().getField("flags");
    assertTrue(flags.getDataType() instanceof WeightedSetDataType);
    assertEquals(DataType.STRING, ((CollectionDataType) flags.getDataType()).getNestedType());
    SDField banners = (SDField) search.getDocument().getField("banners");
    assertTrue(banners.getDataType() instanceof WeightedSetDataType);
    assertEquals(DataType.INT, ((CollectionDataType) banners.getDataType()).getNestedType());
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ArrayDataType(com.yahoo.document.ArrayDataType) Test(org.junit.Test)

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