@Override
    public Y build(BuilderContext context) {
      ContentPath.Type origPathType = context.path().pathType();
      context.path().pathType(pathType);
      context.path().add(name);

      Map<String, Mapper> mappers = new HashMap<>();
      for (Mapper.Builder builder : mappersBuilders) {
        Mapper mapper = builder.build(context);
        mappers.put(mapper.name(), mapper);
      }
      context.path().pathType(origPathType);
      context.path().remove();

      ObjectMapper objectMapper =
          createMapper(
              name,
              context.path().fullPathAsText(name),
              enabled,
              nested,
              dynamic,
              pathType,
              mappers,
              context.indexSettings());
      objectMapper.includeInAllIfNotSet(includeInAll);

      return (Y) objectMapper;
    }
Exemple #2
0
    @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);
    }
    @Override
    public AttachmentMapper build(BuilderContext context) {
      ContentPath.Type origPathType = context.path().pathType();
      context.path().pathType(pathType);

      FieldMapper contentMapper;
      if (context.indexCreatedVersion().before(Version.V_2_0_0_beta1)) {
        // old behavior, we need the content to be indexed under the attachment field name
        if (contentBuilder instanceof FieldMapper.Builder == false) {
          throw new IllegalStateException("content field for attachment must be a field mapper");
        }
        ((FieldMapper.Builder) contentBuilder).indexName(name);
        contentBuilder.name = name + "." + FieldNames.CONTENT;
        contentMapper = (FieldMapper) contentBuilder.build(context);
        context.path().add(name);
      } else {
        context.path().add(name);
        contentMapper = (FieldMapper) contentBuilder.build(context);
      }

      FieldMapper dateMapper = (FieldMapper) dateBuilder.build(context);
      FieldMapper authorMapper = (FieldMapper) authorBuilder.build(context);
      FieldMapper titleMapper = (FieldMapper) titleBuilder.build(context);
      FieldMapper nameMapper = (FieldMapper) nameBuilder.build(context);
      FieldMapper keywordsMapper = (FieldMapper) keywordsBuilder.build(context);
      FieldMapper contentTypeMapper = (FieldMapper) contentTypeBuilder.build(context);
      FieldMapper contentLength = (FieldMapper) contentLengthBuilder.build(context);
      FieldMapper language = (FieldMapper) languageBuilder.build(context);
      context.path().remove();

      context.path().pathType(origPathType);

      if (defaultIndexedChars == null && context.indexSettings() != null) {
        defaultIndexedChars =
            context.indexSettings().getAsInt("index.mapping.attachment.indexed_chars", 100000);
      }
      if (defaultIndexedChars == null) {
        defaultIndexedChars = 100000;
      }

      if (ignoreErrors == null && context.indexSettings() != null) {
        ignoreErrors =
            context
                .indexSettings()
                .getAsBoolean("index.mapping.attachment.ignore_errors", Boolean.TRUE);
      }
      if (ignoreErrors == null) {
        ignoreErrors = Boolean.TRUE;
      }

      if (langDetect == null && context.indexSettings() != null) {
        langDetect =
            context
                .indexSettings()
                .getAsBoolean("index.mapping.attachment.detect_language", Boolean.FALSE);
      }
      if (langDetect == null) {
        langDetect = Boolean.FALSE;
      }
      MappedFieldType defaultFieldType = Defaults.FIELD_TYPE.clone();
      if (this.fieldType.indexOptions() != IndexOptions.NONE && !this.fieldType.tokenized()) {
        defaultFieldType.setOmitNorms(true);
        defaultFieldType.setIndexOptions(IndexOptions.DOCS);
        if (!this.omitNormsSet && this.fieldType.boost() == 1.0F) {
          this.fieldType.setOmitNorms(true);
        }

        if (!this.indexOptionsSet) {
          this.fieldType.setIndexOptions(IndexOptions.DOCS);
        }
      }

      defaultFieldType.freeze();
      this.setupFieldType(context);
      return new AttachmentMapper(
          name,
          fieldType,
          defaultFieldType,
          pathType,
          defaultIndexedChars,
          ignoreErrors,
          langDetect,
          contentMapper,
          dateMapper,
          titleMapper,
          nameMapper,
          authorMapper,
          keywordsMapper,
          contentTypeMapper,
          contentLength,
          language,
          context.indexSettings(),
          multiFieldsBuilder.build(this, context),
          copyTo);
    }