Search in sources :

Example 11 with Attribute

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

the class AttributeListTestCase method testDeriving.

@Test
public void testDeriving() throws IOException, ParseException {
    // Test attribute importing
    Search search = SearchBuilder.buildFromFile("src/test/examples/simple.sd");
    // Test attribute deriving
    AttributeFields attributeFields = new AttributeFields(search);
    Iterator attributes = attributeFields.attributeIterator();
    Attribute attribute;
    attribute = (Attribute) attributes.next();
    assertEquals("popularity", attribute.getName());
    assertEquals(Attribute.Type.INTEGER, attribute.getType());
    assertEquals(Attribute.CollectionType.SINGLE, attribute.getCollectionType());
    attribute = (Attribute) attributes.next();
    assertEquals("measurement", attribute.getName());
    assertEquals(Attribute.Type.INTEGER, attribute.getType());
    assertEquals(Attribute.CollectionType.SINGLE, attribute.getCollectionType());
    attribute = (Attribute) attributes.next();
    assertEquals("smallattribute", attribute.getName());
    assertEquals(Attribute.Type.BYTE, attribute.getType());
    assertEquals(Attribute.CollectionType.ARRAY, attribute.getCollectionType());
    attribute = (Attribute) attributes.next();
    assertEquals("access", attribute.getName());
    assertEquals(Attribute.Type.BYTE, attribute.getType());
    assertEquals(Attribute.CollectionType.SINGLE, attribute.getCollectionType());
    attribute = (Attribute) attributes.next();
    assertEquals("category_arr", attribute.getName());
    assertEquals(Attribute.Type.STRING, attribute.getType());
    assertEquals(Attribute.CollectionType.ARRAY, attribute.getCollectionType());
    attribute = (Attribute) attributes.next();
    assertEquals("measurement_arr", attribute.getName());
    assertEquals(Attribute.Type.INTEGER, attribute.getType());
    assertEquals(Attribute.CollectionType.ARRAY, attribute.getCollectionType());
    attribute = (Attribute) attributes.next();
    assertEquals("popsiness", attribute.getName());
    assertEquals(Attribute.Type.INTEGER, attribute.getType());
    assertEquals(Attribute.CollectionType.SINGLE, attribute.getCollectionType());
    assertTrue(!attributes.hasNext());
}
Also used : Attribute(com.yahoo.searchdefinition.document.Attribute) Search(com.yahoo.searchdefinition.Search) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 12 with Attribute

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

the class AttributeFields method deriveAttribute.

private void deriveAttribute(ImmutableSDField field, Attribute fieldAttribute) {
    Attribute attribute = getAttribute(fieldAttribute.getName());
    if (attribute == null) {
        attributes.put(fieldAttribute.getName(), fieldAttribute);
        attribute = getAttribute(fieldAttribute.getName());
    }
    Ranking ranking = field.getRanking();
    if (ranking != null && ranking.isFilter()) {
        attribute.setEnableBitVectors(true);
        attribute.setEnableOnlyBitVector(true);
    }
}
Also used : Ranking(com.yahoo.searchdefinition.document.Ranking) Attribute(com.yahoo.searchdefinition.document.Attribute)

Example 13 with Attribute

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

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

the class PositionTestCase method assertPositionAttribute.

private static void assertPositionAttribute(Search search, String fieldName, Attribute.CollectionType type) {
    Attribute attribute = search.getAttribute(PositionDataType.getZCurveFieldName(fieldName));
    assertNotNull(attribute);
    assertTrue(attribute.isPosition());
    assertTrue(attribute.getCollectionType().equals(type));
    assertTrue(attribute.getType().equals(Attribute.Type.LONG));
}
Also used : Attribute(com.yahoo.searchdefinition.document.Attribute)

Example 15 with Attribute

use of com.yahoo.searchdefinition.document.Attribute 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

Attribute (com.yahoo.searchdefinition.document.Attribute)22 SDField (com.yahoo.searchdefinition.document.SDField)11 Test (org.junit.Test)4 DocumentSummary (com.yahoo.vespa.documentmodel.DocumentSummary)3 SummaryField (com.yahoo.vespa.documentmodel.SummaryField)3 DataType (com.yahoo.document.DataType)2 Field (com.yahoo.document.Field)2 Index (com.yahoo.searchdefinition.Index)2 Search (com.yahoo.searchdefinition.Search)2 ScriptExpression (com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ArrayDataType (com.yahoo.document.ArrayDataType)1 PositionDataType (com.yahoo.document.PositionDataType)1 TensorDataType (com.yahoo.document.TensorDataType)1 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)1 SearchBuilder (com.yahoo.searchdefinition.SearchBuilder)1 BooleanIndexDefinition (com.yahoo.searchdefinition.document.BooleanIndexDefinition)1 ImmutableSDField (com.yahoo.searchdefinition.document.ImmutableSDField)1 Ranking (com.yahoo.searchdefinition.document.Ranking)1