示例#1
0
  @Inject
  public MapperService(
      Index index,
      @IndexSettings Settings indexSettings,
      Environment environment,
      AnalysisService analysisService) {
    super(index, indexSettings);
    this.analysisService = analysisService;
    this.documentParser = new DocumentMapperParser(index, indexSettings, analysisService);
    this.searchAnalyzer = new SmartIndexNameSearchAnalyzer(analysisService.defaultSearchAnalyzer());

    this.dynamic = componentSettings.getAsBoolean("dynamic", true);
    String defaultMappingLocation = componentSettings.get("default_mapping_location");
    URL defaultMappingUrl;
    if (defaultMappingLocation == null) {
      try {
        defaultMappingUrl = environment.resolveConfig("default-mapping.json");
      } catch (FailedToResolveConfigException e) {
        // not there, default to the built in one
        defaultMappingUrl =
            indexSettings
                .getClassLoader()
                .getResource("org/elasticsearch/index/mapper/default-mapping.json");
      }
    } else {
      try {
        defaultMappingUrl = environment.resolveConfig(defaultMappingLocation);
      } catch (FailedToResolveConfigException e) {
        // not there, default to the built in one
        try {
          defaultMappingUrl = new File(defaultMappingLocation).toURI().toURL();
        } catch (MalformedURLException e1) {
          throw new FailedToResolveConfigException(
              "Failed to resolve dynamic mapping location [" + defaultMappingLocation + "]");
        }
      }
    }

    try {
      defaultMappingSource =
          Streams.copyToString(
              new InputStreamReader(defaultMappingUrl.openStream(), Charsets.UTF_8));
    } catch (IOException e) {
      throw new MapperException(
          "Failed to load default mapping source from [" + defaultMappingLocation + "]", e);
    }

    logger.debug(
        "using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}] and source[{}]",
        dynamic,
        defaultMappingLocation,
        defaultMappingUrl,
        defaultMappingSource);
  }
  @Inject
  public HyphenationCompoundWordTokenFilterFactory(
      Index index,
      @IndexSettings Settings indexSettings,
      Environment env,
      @Assisted String name,
      @Assisted Settings settings) {
    super(index, indexSettings, env, name, settings);

    String hyphenationPatternsPath = settings.get("hyphenation_patterns_path", null);
    if (hyphenationPatternsPath == null) {
      throw new ElasticsearchIllegalArgumentException(
          "hyphenation_patterns_path is a required setting.");
    }

    URL hyphenationPatternsFile = env.resolveConfig(hyphenationPatternsPath);

    try {
      hyphenationTree =
          HyphenationCompoundWordTokenFilter.getHyphenationTree(
              new InputSource(hyphenationPatternsFile.toExternalForm()));
    } catch (Exception e) {
      throw new ElasticsearchIllegalArgumentException(
          "Exception while reading hyphenation_patterns_path: " + e.getMessage());
    }
  }
 private Decompounder createDecompounder(Environment env, Settings settings) {
   try {
     String forward = settings.get("forward", "/decompound/kompVVic.tree");
     String backward = settings.get("backward", "/decompound/kompVHic.tree");
     String reduce = settings.get("reduce", "/decompound/grfExt.tree");
     double threshold = settings.getAsDouble("threshold", 0.51);
     return new Decompounder(
         env.resolveConfig(forward).openStream(),
         env.resolveConfig(backward).openStream(),
         env.resolveConfig(reduce).openStream(),
         threshold);
   } catch (ClassNotFoundException e) {
     throw new ElasticsearchIllegalArgumentException(
         "decompounder resources in settings not found: " + settings, e);
   } catch (IOException e) {
     throw new ElasticsearchIllegalArgumentException(
         "decompounder resources in settings not found: " + settings, e);
   }
 }
示例#4
0
  @Inject
  public MapperService(
      Index index,
      @IndexSettings Settings indexSettings,
      Environment environment,
      AnalysisService analysisService,
      PostingsFormatService postingsFormatService,
      DocValuesFormatService docValuesFormatService,
      SimilarityLookupService similarityLookupService) {
    super(index, indexSettings);
    this.analysisService = analysisService;
    this.documentParser =
        new DocumentMapperParser(
            index,
            indexSettings,
            analysisService,
            postingsFormatService,
            docValuesFormatService,
            similarityLookupService);
    this.searchAnalyzer = new SmartIndexNameSearchAnalyzer(analysisService.defaultSearchAnalyzer());
    this.searchQuoteAnalyzer =
        new SmartIndexNameSearchQuoteAnalyzer(analysisService.defaultSearchQuoteAnalyzer());

    this.dynamic = componentSettings.getAsBoolean("dynamic", true);
    String defaultMappingLocation = componentSettings.get("default_mapping_location");
    URL defaultMappingUrl;
    if (defaultMappingLocation == null) {
      try {
        defaultMappingUrl = environment.resolveConfig("default-mapping.json");
      } catch (FailedToResolveConfigException e) {
        // not there, default to the built in one
        defaultMappingUrl =
            indexSettings
                .getClassLoader()
                .getResource("org/elasticsearch/index/mapper/default-mapping.json");
        if (defaultMappingUrl == null) {
          defaultMappingUrl =
              MapperService.class
                  .getClassLoader()
                  .getResource("org/elasticsearch/index/mapper/default-mapping.json");
        }
      }
    } else {
      try {
        defaultMappingUrl = environment.resolveConfig(defaultMappingLocation);
      } catch (FailedToResolveConfigException e) {
        // not there, default to the built in one
        try {
          defaultMappingUrl = new File(defaultMappingLocation).toURI().toURL();
        } catch (MalformedURLException e1) {
          throw new FailedToResolveConfigException(
              "Failed to resolve dynamic mapping location [" + defaultMappingLocation + "]");
        }
      }
    }

    if (defaultMappingUrl == null) {
      logger.info(
          "failed to find default-mapping.json in the classpath, using the default template");
      defaultMappingSource = "{\n" + "    \"_default_\":{\n" + "    }\n" + "}";
    } else {
      try {
        defaultMappingSource =
            Streams.copyToString(
                new InputStreamReader(defaultMappingUrl.openStream(), Charsets.UTF_8));
      } catch (IOException e) {
        throw new MapperException(
            "Failed to load default mapping source from [" + defaultMappingLocation + "]", e);
      }
    }

    String percolatorMappingLocation = componentSettings.get("default_percolator_mapping_location");
    URL percolatorMappingUrl = null;
    if (percolatorMappingLocation != null) {
      try {
        percolatorMappingUrl = environment.resolveConfig(percolatorMappingLocation);
      } catch (FailedToResolveConfigException e) {
        // not there, default to the built in one
        try {
          percolatorMappingUrl = new File(percolatorMappingLocation).toURI().toURL();
        } catch (MalformedURLException e1) {
          throw new FailedToResolveConfigException(
              "Failed to resolve default percolator mapping location ["
                  + percolatorMappingLocation
                  + "]");
        }
      }
    }
    if (percolatorMappingUrl != null) {
      try {
        defaultPercolatorMappingSource =
            Streams.copyToString(
                new InputStreamReader(percolatorMappingUrl.openStream(), Charsets.UTF_8));
      } catch (IOException e) {
        throw new MapperException(
            "Failed to load default percolator mapping source from [" + percolatorMappingUrl + "]",
            e);
      }
    } else {
      defaultPercolatorMappingSource =
          "{\n"
              +
              // "    \"" + PercolatorService.TYPE_NAME + "\":{\n" +
              "    \""
              + "_default_"
              + "\":{\n"
              + "        \"_id\" : {\"index\": \"not_analyzed\"},"
              + "        \"properties\" : {\n"
              + "            \"query\" : {\n"
              + "                \"type\" : \"object\",\n"
              + "                \"enabled\" : false\n"
              + "            }\n"
              + "        }\n"
              + "    }\n"
              + "}";
    }

    if (logger.isDebugEnabled()) {
      logger.debug(
          "using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}], default percolator mapping: location[{}], loaded_from[{}]",
          dynamic,
          defaultMappingLocation,
          defaultMappingUrl,
          percolatorMappingLocation,
          percolatorMappingUrl);
    } else if (logger.isTraceEnabled()) {
      logger.trace(
          "using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}] and source[{}], default percolator mapping: location[{}], loaded_from[{}] and source[{}]",
          dynamic,
          defaultMappingLocation,
          defaultMappingUrl,
          defaultMappingSource,
          percolatorMappingLocation,
          percolatorMappingUrl,
          defaultPercolatorMappingSource);
    }
  }