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