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;
}
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());
}
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());
}
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);
}
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());
}
Aggregations