Search in sources :

Example 1 with EntityField

use of org.apache.solr.handler.dataimport.config.EntityField in project lucene-solr by apache.

the class DocBuilder method addFields.

@SuppressWarnings("unchecked")
private void addFields(Entity entity, DocWrapper doc, Map<String, Object> arow, VariableResolver vr) {
    for (Map.Entry<String, Object> entry : arow.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value == null)
            continue;
        if (key.startsWith("$"))
            continue;
        Set<EntityField> field = entity.getColNameVsField().get(key);
        IndexSchema schema = null == reqParams.getRequest() ? null : reqParams.getRequest().getSchema();
        if (field == null && schema != null) {
            // This can be a dynamic field or a field which does not have an entry in data-config ( an implicit field)
            SchemaField sf = schema.getFieldOrNull(key);
            if (sf == null) {
                sf = config.getSchemaField(key);
            }
            if (sf != null) {
                addFieldToDoc(entry.getValue(), sf.getName(), sf.multiValued(), doc);
            }
        //else do nothing. if we add it it may fail
        } else {
            if (field != null) {
                for (EntityField f : field) {
                    String name = f.getName();
                    boolean multiValued = f.isMultiValued();
                    boolean toWrite = f.isToWrite();
                    if (f.isDynamicName()) {
                        name = vr.replaceTokens(name);
                        SchemaField schemaField = config.getSchemaField(name);
                        if (schemaField == null) {
                            toWrite = false;
                        } else {
                            multiValued = schemaField.multiValued();
                            toWrite = true;
                        }
                    }
                    if (toWrite) {
                        addFieldToDoc(entry.getValue(), name, multiValued, doc);
                    }
                }
            }
        }
    }
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) IndexSchema(org.apache.solr.schema.IndexSchema) EntityField(org.apache.solr.handler.dataimport.config.EntityField)

Aggregations

EntityField (org.apache.solr.handler.dataimport.config.EntityField)1 IndexSchema (org.apache.solr.schema.IndexSchema)1 SchemaField (org.apache.solr.schema.SchemaField)1