Java Code Examples for org.elasticsearch.index.mapper.core.StringFieldMapper

The following examples show how to use org.elasticsearch.index.mapper.core.StringFieldMapper. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Elasticsearch   Source File: QueryParseContext.java    License: Apache License 2.0 6 votes vote down vote up
private MappedFieldType failIfFieldMappingNotFound(String name, MappedFieldType fieldMapping) {
    if (fieldMapping != null || allowUnmappedFields) {
        return fieldMapping;
    } else if (mapUnmappedFieldAsString){
        StringFieldMapper.Builder builder = MapperBuilders.stringField(name);
        // it would be better to pass the real index settings, but they are not easily accessible from here...
        Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexQueryParser.getIndexCreatedVersion()).build();
        return builder.build(new Mapper.BuilderContext(settings, new ContentPath(1))).fieldType();
    } else {
        Version indexCreatedVersion = indexQueryParser.getIndexCreatedVersion();
        if (fieldMapping == null && indexCreatedVersion.onOrAfter(Version.V_1_4_0_Beta1)) {
            throw new QueryParsingException(this, "Strict field resolution and no field mapping can be found for the field with name ["
                    + name + "]");
        } else {
            return fieldMapping;
        }
    }
}
 
Example 2
Source Project: Elasticsearch   Source File: BaseGeoPointFieldMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public FieldMapper updateFieldType(Map<String, MappedFieldType> fullNameToFieldType) {
    BaseGeoPointFieldMapper updated = (BaseGeoPointFieldMapper) super.updateFieldType(fullNameToFieldType);
    StringFieldMapper geoUpdated = geoHashMapper == null ? null : (StringFieldMapper) geoHashMapper.updateFieldType(fullNameToFieldType);
    DoubleFieldMapper latUpdated = latMapper == null ? null : (DoubleFieldMapper) latMapper.updateFieldType(fullNameToFieldType);
    DoubleFieldMapper lonUpdated = lonMapper == null ? null : (DoubleFieldMapper) lonMapper.updateFieldType(fullNameToFieldType);
    if (updated == this
            && geoUpdated == geoHashMapper
            && latUpdated == latMapper
            && lonUpdated == lonMapper) {
        return this;
    }
    if (updated == this) {
        updated = (BaseGeoPointFieldMapper) updated.clone();
    }
    updated.geoHashMapper = geoUpdated;
    updated.latMapper = latUpdated;
    updated.lonMapper = lonUpdated;
    return updated;
}
 
Example 3
Source Project: ElasticUtils   Source File: LocalWeatherDataMapper.java    License: MIT License 6 votes vote down vote up
@Override
protected void configureRootObjectBuilder(RootObjectMapper.Builder builder) {
    builder
            .add(new DateFieldMapper.Builder("dateTime"))
            .add(new FloatFieldMapper.Builder("temperature"))
            .add(new FloatFieldMapper.Builder("windSpeed"))
            .add(new FloatFieldMapper.Builder("stationPressure"))
            .add(new StringFieldMapper.Builder("skyCondition"))
            .add(new ObjectMapper.Builder("station")
                    .add(new StringFieldMapper.Builder("wban"))
                    .add(new StringFieldMapper.Builder("name"))
                    .add(new StringFieldMapper.Builder("state"))
                    .add(new StringFieldMapper.Builder("location"))
                    .add(new GeoPointFieldMapper.Builder("coordinates")
                            .enableLatLon(true)
                            .enableGeoHash(false))
                    .nested(ObjectMapper.Nested.newNested(true, false)));
}
 
Example 4
@Override
protected void configure(RootObjectMapper.Builder builder) {
    builder
            .add(new DateFieldMapper.Builder("dateTime"))
            .add(new FloatFieldMapper.Builder("temperature"))
            .add(new FloatFieldMapper.Builder("windSpeed"))
            .add(new FloatFieldMapper.Builder("stationPressure"))
            .add(new StringFieldMapper.Builder("skyCondition"))
            .add(new ObjectMapper.Builder("station")
                    .add(new StringFieldMapper.Builder("wban"))
                    .add(new StringFieldMapper.Builder("name"))
                    .add(new StringFieldMapper.Builder("state"))
                    .add(new StringFieldMapper.Builder("location"))
                    .add(new GeoPointFieldMapper.Builder("coordinates")
                            .enableLatLon(true)
                            .enableGeoHash(false))
                    .nested(ObjectMapper.Nested.newNested(true, false)));
}
 
Example 5
private static Map<String, Mapper.TypeParser> registerBuiltInMappers() {
    Map<String, Mapper.TypeParser> mapperParsers = new LinkedHashMap<>();
    mapperParsers.put(ByteFieldMapper.CONTENT_TYPE, new ByteFieldMapper.TypeParser());
    mapperParsers.put(ShortFieldMapper.CONTENT_TYPE, new ShortFieldMapper.TypeParser());
    mapperParsers.put(IntegerFieldMapper.CONTENT_TYPE, new IntegerFieldMapper.TypeParser());
    mapperParsers.put(LongFieldMapper.CONTENT_TYPE, new LongFieldMapper.TypeParser());
    mapperParsers.put(FloatFieldMapper.CONTENT_TYPE, new FloatFieldMapper.TypeParser());
    mapperParsers.put(DoubleFieldMapper.CONTENT_TYPE, new DoubleFieldMapper.TypeParser());
    mapperParsers.put(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser());
    mapperParsers.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser());
    mapperParsers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser());
    mapperParsers.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser());
    mapperParsers.put(StringFieldMapper.CONTENT_TYPE, new StringFieldMapper.TypeParser());
    mapperParsers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser());
    mapperParsers.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser());
    mapperParsers.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser());
    mapperParsers.put(TypeParsers.MULTI_FIELD_CONTENT_TYPE, TypeParsers.multiFieldConverterTypeParser);
    mapperParsers.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser());
    mapperParsers.put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser());
    return mapperParsers;
}
 
Example 6
Source Project: Elasticsearch   Source File: ShardTermVectorsService.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isValidField(MappedFieldType fieldType) {
    // must be a string
    if (!(fieldType instanceof StringFieldMapper.StringFieldType)) {
        return false;
    }
    // and must be indexed
    if (fieldType.indexOptions() == IndexOptions.NONE) {
        return false;
    }
    return true;
}
 
Example 7
Source Project: Elasticsearch   Source File: BaseGeoPointFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
public Y build(Mapper.BuilderContext context) {
    ContentPath.Type origPathType = context.path().pathType();
    context.path().pathType(pathType);

    GeoPointFieldType geoPointFieldType = (GeoPointFieldType)fieldType;

    DoubleFieldMapper latMapper = null;
    DoubleFieldMapper lonMapper = null;

    context.path().add(name);
    if (enableLatLon) {
        NumberFieldMapper.Builder<?, ?> latMapperBuilder = doubleField(Names.LAT).includeInAll(false);
        NumberFieldMapper.Builder<?, ?> lonMapperBuilder = doubleField(Names.LON).includeInAll(false);
        if (precisionStep != null) {
            latMapperBuilder.precisionStep(precisionStep);
            lonMapperBuilder.precisionStep(precisionStep);
        }
        latMapper = (DoubleFieldMapper) latMapperBuilder.includeInAll(false).store(fieldType.stored()).docValues(false).build(context);
        lonMapper = (DoubleFieldMapper) lonMapperBuilder.includeInAll(false).store(fieldType.stored()).docValues(false).build(context);
        geoPointFieldType.setLatLonEnabled(latMapper.fieldType(), lonMapper.fieldType());
    }
    StringFieldMapper geoHashMapper = null;
    if (enableGeoHash || enableGeoHashPrefix) {
        // TODO: possible also implicitly enable geohash if geohash precision is set
        geoHashMapper = stringField(Names.GEOHASH).index(true).tokenized(false).includeInAll(false).store(fieldType.stored())
                .omitNorms(true).indexOptions(IndexOptions.DOCS).build(context);
        geoPointFieldType.setGeoHashEnabled(geoHashMapper.fieldType(), geoHashPrecision, enableGeoHashPrefix);
    }
    context.path().remove();
    context.path().pathType(origPathType);

    return build(context, name, fieldType, defaultFieldType, context.indexSettings(), origPathType,
            latMapper, lonMapper, geoHashMapper, multiFieldsBuilder.build(this, context), ignoreMalformed(context), copyTo);
}
 
Example 8
Source Project: Elasticsearch   Source File: BaseGeoPointFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
protected BaseGeoPointFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Settings indexSettings,
                                  ContentPath.Type pathType, DoubleFieldMapper latMapper, DoubleFieldMapper lonMapper, StringFieldMapper geoHashMapper,
                                  MultiFields multiFields, Explicit<Boolean> ignoreMalformed, CopyTo copyTo) {
    super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
    this.pathType = pathType;
    this.latMapper = latMapper;
    this.lonMapper = lonMapper;
    this.geoHashMapper = geoHashMapper;
    this.ignoreMalformed = ignoreMalformed;
}
 
Example 9
Source Project: Elasticsearch   Source File: GeoPointFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GeoPointFieldMapper build(BuilderContext context, String simpleName, MappedFieldType fieldType,
                                 MappedFieldType defaultFieldType, Settings indexSettings, ContentPath.Type pathType, DoubleFieldMapper latMapper,
                                 DoubleFieldMapper lonMapper, StringFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed,
                                 CopyTo copyTo) {
    fieldType.setTokenized(false);
    if (context.indexCreatedVersion().before(Version.V_2_3_0)) {
        fieldType.setNumericPrecisionStep(GeoPointField.PRECISION_STEP);
        fieldType.setNumericType(FieldType.NumericType.LONG);
    }
    setupFieldType(context);
    return new GeoPointFieldMapper(simpleName, fieldType, defaultFieldType, indexSettings, pathType, latMapper, lonMapper,
            geoHashMapper, multiFields, ignoreMalformed, copyTo);
}
 
Example 10
Source Project: Elasticsearch   Source File: GeoPointFieldMapperLegacy.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GeoPointFieldMapperLegacy build(BuilderContext context, String simpleName, MappedFieldType fieldType,
                                       MappedFieldType defaultFieldType, Settings indexSettings, ContentPath.Type pathType, DoubleFieldMapper latMapper,
                                       DoubleFieldMapper lonMapper, StringFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed,
                                       CopyTo copyTo) {
    fieldType.setTokenized(false);
    setupFieldType(context);
    fieldType.setHasDocValues(false);
    defaultFieldType.setHasDocValues(false);
    return new GeoPointFieldMapperLegacy(simpleName, fieldType, defaultFieldType, indexSettings, pathType, latMapper, lonMapper,
            geoHashMapper, multiFields, ignoreMalformed, coerce(context), copyTo);
}
 
Example 11
Source Project: Elasticsearch   Source File: GeoPointFieldMapperLegacy.java    License: Apache License 2.0 5 votes vote down vote up
public GeoPointFieldMapperLegacy(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Settings indexSettings,
                                 ContentPath.Type pathType, DoubleFieldMapper latMapper, DoubleFieldMapper lonMapper,
                                 StringFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed,
                                 Explicit<Boolean> coerce, CopyTo copyTo) {
    super(simpleName, fieldType, defaultFieldType, indexSettings, pathType, latMapper, lonMapper, geoHashMapper, multiFields,
            ignoreMalformed, copyTo);
    this.coerce = coerce;
}
 
Example 12
private final Query toFieldDataTermsQuery(MappedFieldType fieldType, IndexFieldData fieldData,
                                          byte[] encodedTerms, long cacheKey) {
  Query query = null;

  if (fieldType instanceof NumberFieldMapper.NumberFieldType) {
    query = FieldDataTermsQuery.newLongs(encodedTerms, (IndexNumericFieldData) fieldData, cacheKey);
  } else if (fieldType instanceof StringFieldMapper.StringFieldType) {
    query = FieldDataTermsQuery.newBytes(encodedTerms, fieldData, cacheKey);
  } else {
    throw new ElasticsearchParseException("[fielddata_terms] query does not support field data type " + fieldType.fieldDataType().getType());
  }

  return query;
}
 
Example 13
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public OntologyMapper build(BuilderContext context) {
	ContentPath.Type origPathType = context.path().pathType();
	context.path().pathType(pathType);

	Map<String, FieldMapper<String>> fieldMappers = Maps.newHashMap();

	context.path().add(name);

	if (propertyBuilders != null) {
		for (String property : propertyBuilders.keySet()) {
			StringFieldMapper sfm = propertyBuilders.get(property).build(context);
			fieldMappers.put(sfm.names().indexName(), sfm);
		}
	}

	// Initialise field mappers for the pre-defined fields
	for (FieldMappings mapping : ontologySettings.getFieldMappings()) {
		if (!fieldMappers.containsKey(context.path().fullPathAsText(mapping.getFieldName()))) {
			StringFieldMapper mapper = MapperBuilders.stringField(mapping.getFieldName())
					.store(true)
					.index(true)
					.tokenized(!mapping.isUriField())
					.build(context);
			fieldMappers.put(mapper.names().indexName(), mapper);
		}
	}

	context.path().remove(); // remove name
	context.path().pathType(origPathType);

	return new OntologyMapper(buildNames(context), fieldType, docValues, indexAnalyzer, searchAnalyzer,
			postingsProvider, docValuesProvider,
			similarity, fieldDataSettings, context.indexSettings(),
			new MultiFields.Builder().build(this, context),
			ontologySettings, fieldMappers, threadPool);
}
 
Example 14
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name          the field name
 * @param node          the JSON node holding the mapping definitions.
 * @param parserContext the parser context object.
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name, threadPool);

	for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 15
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Map.Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>) entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder) builder);
	}
	return propertyMap;
}
 
Example 16
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public OntologyMapper build(BuilderContext context) {
	ContentPath.Type origPathType = context.path().pathType();
	context.path().pathType(pathType);

	Map<String, StringFieldMapper> fieldMappers = new HashMap<>();

	context.path().add(name);

	if (propertyBuilders != null) {
		for (String property : propertyBuilders.keySet()) {
			StringFieldMapper sfm = propertyBuilders.get(property).build(context);
			fieldMappers.put(sfm.fieldType().names().indexName(), sfm);
		}
	}

	// Initialise field mappers for the pre-defined fields
	for (FieldMappings mapping : ontologySettings.getFieldMappings()) {
		if (!fieldMappers.containsKey(context.path().fullPathAsText(mapping.getFieldName()))) {
			StringFieldMapper mapper = MapperBuilders.stringField(mapping.getFieldName())
					.store(true)
					.index(true)
					.tokenized(!mapping.isUriField())
					.includeInAll(true)
					.build(context);
			fieldMappers.put(mapper.fieldType().names().indexName(), mapper);
		}
	}

	context.path().remove(); // remove name
	context.path().pathType(origPathType);

	setupFieldType(context);

	return new OntologyMapper(name, fieldType, defaultFieldType, context.indexSettings(),
			multiFieldsBuilder.build(this, context),
			ontologySettings, fieldMappers);
}
 
Example 17
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name          the field name
 * @param node          the JSON node holding the mapping definitions.
 * @param parserContext the parser context object.
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name);
	parseField(builder, name, node, parserContext);

	for (Iterator<Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder = builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 18
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>) entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder) builder);
	}
	return propertyMap;
}
 
Example 19
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
public OntologyMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
		Settings indexSettings, MultiFields multiFields, OntologySettings oSettings,
		Map<String, StringFieldMapper> fieldMappers) {
	super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, null);
	this.ontologySettings = oSettings;
	// Dynamic mappers are added to mappers map as they are used/created
	this.mappers = CopyOnWriteHashMap.copyOf(fieldMappers);
}
 
Example 20
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
private void addFieldData(ParseContext context, StringFieldMapper mapper, Collection<String> data) throws IOException {
	if (data != null && !data.isEmpty()) {
		for (String value : data) {
			ParseContext evc = context.createExternalValueContext(value);
			mapper.parse(evc);
		}
	}
}
 
Example 21
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
private void addRelatedNodesWithLabels(ParseContext context, Collection<String> iris, StringFieldMapper iriMapper,
		Collection<String> labels, StringFieldMapper labelMapper) throws IOException {
	if (!iris.isEmpty()) {
		addFieldData(context, iriMapper, iris);
		addFieldData(context, labelMapper, labels);
	}
}
 
Example 22
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void doMerge(Mapper mergeWith, boolean includeInAll) throws MergeMappingException {
	super.doMerge(mergeWith, includeInAll);

	OntologyMapper oMergeWith = (OntologyMapper) mergeWith;
	OntologySettings mergeSettings = oMergeWith.ontologySettings;
	if (mergeSettings.getOntologyUri() != null && !mergeSettings.getOntologyUri().equals(ontologySettings.getOntologyUri())) {
		throw new IllegalArgumentException("mapper [" + fieldType().names().fullName() + "] has different ontology URI");
	} else if (mergeSettings.getOlsBaseUrl() != null && !mergeSettings.getOlsBaseUrl().equals(ontologySettings.getOlsBaseUrl())) {
		throw new IllegalArgumentException("mapper [" + fieldType().names().fullName() + "] has different OLS base URL");
	}

	// Merge the mappers
	List<FieldMapper> newFieldMappers = null;
	Map<String, StringFieldMapper> newMapperMap = null;

	for (Entry<String, StringFieldMapper> entry : oMergeWith.mappers.entrySet()) {
		StringFieldMapper mergeIntoMapper = mappers.get(entry.getKey());
		if (mergeIntoMapper == null) {
			if (newFieldMappers == null) {
				newFieldMappers = new ArrayList<>(oMergeWith.mappers.size());
				newMapperMap = new HashMap<>();
			}
			newFieldMappers.add(entry.getValue());
			newMapperMap.put(entry.getKey(), entry.getValue());
		} else {
			mergeIntoMapper.merge(entry.getValue(), includeInAll);
		}
	}

	if (newFieldMappers != null) {
		mappers = mappers.copyAndPutAll(newMapperMap);
	}
}
 
Example 23
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public OntologyMapper build(BuilderContext context) {
	ContentPath.Type origPathType = context.path().pathType();
	context.path().pathType(pathType);

	Map<String, FieldMapper<String>> fieldMappers = Maps.newHashMap();

	context.path().add(name);

	if (propertyBuilders != null) {
		for (String property : propertyBuilders.keySet()) {
			StringFieldMapper sfm = propertyBuilders.get(property).build(context);
			fieldMappers.put(sfm.names().indexName(), sfm);
		}
	}

	// Initialise field mappers for the pre-defined fields
	for (FieldMappings mapping : ontologySettings.getFieldMappings()) {
		if (!fieldMappers.containsKey(context.path().fullPathAsText(mapping.getFieldName()))) {
			StringFieldMapper mapper = MapperBuilders.stringField(mapping.getFieldName())
					.store(true)
					.index(true)
					.tokenized(!mapping.isUriField())
					.build(context);
			fieldMappers.put(mapper.names().indexName(), mapper);
		}
	}

	context.path().remove(); // remove name
	context.path().pathType(origPathType);

	return new OntologyMapper(buildNames(context), fieldType, docValues, indexAnalyzer, searchAnalyzer,
			postingsProvider, docValuesProvider,
			similarity, fieldDataSettings, context.indexSettings(),
			new MultiFields.Builder().build(this, context),
			ontologySettings, fieldMappers, threadPool);
}
 
Example 24
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name          the field name
 * @param node          the JSON node holding the mapping definitions.
 * @param parserContext the parser context object.
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name, threadPool);

	for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 25
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Map.Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>) entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder) builder);
	}
	return propertyMap;
}
 
Example 26
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public OntologyMapper build(BuilderContext context) {
	ContentPath.Type origPathType = context.path().pathType();
	context.path().pathType(pathType);

	Map<String, FieldMapper<String>> fieldMappers = Maps.newHashMap();

	context.path().add(name);

	if (propertyBuilders != null) {
		for (String property : propertyBuilders.keySet()) {
			StringFieldMapper sfm = propertyBuilders.get(property).build(context);
			fieldMappers.put(sfm.names().indexName(), sfm);
		}
	}

	// Initialise field mappers for the pre-defined fields
	for (FieldMappings mapping : ontologySettings.getFieldMappings()) {
		if (!fieldMappers.containsKey(context.path().fullPathAsText(mapping.getFieldName()))) {
			StringFieldMapper mapper = MapperBuilders.stringField(mapping.getFieldName())
					.store(true)
					.index(true)
					.tokenized(!mapping.isUriField())
					.build(context);
			fieldMappers.put(mapper.names().indexName(), mapper);
		}
	}

	context.path().remove(); // remove name
	context.path().pathType(origPathType);

	return new OntologyMapper(buildNames(context), fieldType, docValues, indexAnalyzer, searchAnalyzer,
			postingsProvider, docValuesProvider,
			similarity, fieldDataSettings, context.indexSettings(),
			new MultiFields.Builder().build(this, context),
			ontologySettings, fieldMappers, threadPool);
}
 
Example 27
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name the field name
 * @param node the JSON node holding the mapping definitions.
 * @param parserContext the parser context
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name, threadPool);

	for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 28
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Map.Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext();) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>)entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder)builder);
	}
	return propertyMap;
}
 
Example 29
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public OntologyMapper build(BuilderContext context) {
	ContentPath.Type origPathType = context.path().pathType();
	context.path().pathType(pathType);

	Map<String, StringFieldMapper> fieldMappers = new HashMap<>();

	context.path().add(name);

	if (propertyBuilders != null) {
		for (String property : propertyBuilders.keySet()) {
			StringFieldMapper sfm = propertyBuilders.get(property).build(context);
			fieldMappers.put(sfm.fieldType().names().indexName(), sfm);
		}
	}

	// Initialise field mappers for the pre-defined fields
	for (FieldMappings mapping : ontologySettings.getFieldMappings()) {
		if (!fieldMappers.containsKey(context.path().fullPathAsText(mapping.getFieldName()))) {
			StringFieldMapper mapper = MapperBuilders.stringField(mapping.getFieldName())
					.store(true)
					.index(true)
					.tokenized(!mapping.isUriField())
					.includeInAll(true)
					.build(context);
			fieldMappers.put(mapper.fieldType().names().indexName(), mapper);
		}
	}

	context.path().remove(); // remove name
	context.path().pathType(origPathType);

	setupFieldType(context);

	return new OntologyMapper(name, fieldType, defaultFieldType, context.indexSettings(),
			multiFieldsBuilder.build(this, context),
			ontologySettings, fieldMappers);
}
 
Example 30
Source Project: BioSolr   Source File: OntologyMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name          the field name
 * @param node          the JSON node holding the mapping definitions.
 * @param parserContext the parser context object.
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name);
	parseField(builder, name, node, parserContext);

	for (Iterator<Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder = builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}