Beispiel #1
0
  /**
   * Creates a configuration instance from a resource loader, a configuration name and a stream. If
   * the stream is null, the resource loader will open the configuration stream. If the stream is
   * not null, no attempt to load the resource will occur (the name is not used).
   *
   * @param loader the resource loader
   * @param name the configuration name
   * @param is the configuration stream
   */
  public SolrConfig(SolrResourceLoader loader, String name, InputSource is)
      throws ParserConfigurationException, IOException, SAXException {
    super(loader, name, is, "/config/");
    getOverlay(); // just in case it is not initialized
    getRequestParams();
    initLibs();
    luceneMatchVersion = getLuceneVersion("luceneMatchVersion");
    String indexConfigPrefix;

    // Old indexDefaults and mainIndex sections are deprecated and fails fast for
    // luceneMatchVersion=>LUCENE_4_0_0.
    // For older solrconfig.xml's we allow the old sections, but never mixed with the new
    // <indexConfig>
    boolean hasDeprecatedIndexConfig =
        (getNode("indexDefaults", false) != null) || (getNode("mainIndex", false) != null);
    if (hasDeprecatedIndexConfig) {
      throw new SolrException(
          ErrorCode.FORBIDDEN,
          "<indexDefaults> and <mainIndex> configuration sections are discontinued. Use <indexConfig> instead.");
    } else {
      defaultIndexConfig = mainIndexConfig = null;
      indexConfigPrefix = "indexConfig";
    }
    assertWarnOrFail(
        "The <nrtMode> config has been discontinued and NRT mode is always used by Solr."
            + " This config will be removed in future versions.",
        getNode(indexConfigPrefix + "/nrtMode", false) == null,
        true);
    assertWarnOrFail(
        "Solr no longer supports forceful unlocking via the 'unlockOnStartup' option.  "
            + "This is no longer neccessary for the default lockType except in situations where "
            + "it would be dangerous and should not be done.  For other lockTypes and/or "
            + "directoryFactory options it may also be dangerous and users must resolve "
            + "problematic locks manually.",
        null == getNode(indexConfigPrefix + "/unlockOnStartup", false),
        true // 'fail' in trunk
        );

    // Parse indexConfig section, using mainIndex as backup in case old config is used
    indexConfig = new SolrIndexConfig(this, "indexConfig", mainIndexConfig);

    booleanQueryMaxClauseCount =
        getInt("query/maxBooleanClauses", BooleanQuery.getMaxClauseCount());
    log.info("Using Lucene MatchVersion: " + luceneMatchVersion);

    // Warn about deprecated / discontinued parameters
    // boolToFilterOptimizer has had no effect since 3.1
    if (get("query/boolTofilterOptimizer", null) != null)
      log.warn(
          "solrconfig.xml: <boolTofilterOptimizer> is currently not implemented and has no effect.");
    if (get("query/HashDocSet", null) != null)
      log.warn("solrconfig.xml: <HashDocSet> is deprecated and no longer recommended used.");

    // TODO: Old code - in case somebody wants to re-enable. Also see SolrIndexSearcher#search()
    //    filtOptEnabled = getBool("query/boolTofilterOptimizer/@enabled", false);
    //    filtOptCacheSize = getInt("query/boolTofilterOptimizer/@cacheSize",32);
    //    filtOptThreshold = getFloat("query/boolTofilterOptimizer/@threshold",.05f);

    useFilterForSortedQuery = getBool("query/useFilterForSortedQuery", false);
    queryResultWindowSize = Math.max(1, getInt("query/queryResultWindowSize", 1));
    queryResultMaxDocsCached = getInt("query/queryResultMaxDocsCached", Integer.MAX_VALUE);
    enableLazyFieldLoading = getBool("query/enableLazyFieldLoading", false);

    filterCacheConfig = CacheConfig.getConfig(this, "query/filterCache");
    queryResultCacheConfig = CacheConfig.getConfig(this, "query/queryResultCache");
    documentCacheConfig = CacheConfig.getConfig(this, "query/documentCache");
    CacheConfig conf = CacheConfig.getConfig(this, "query/fieldValueCache");
    if (conf == null) {
      Map<String, String> args = new HashMap<>();
      args.put(NAME, "fieldValueCache");
      args.put("size", "10000");
      args.put("initialSize", "10");
      args.put("showItems", "-1");
      conf = new CacheConfig(FastLRUCache.class, args, null);
    }
    fieldValueCacheConfig = conf;
    useColdSearcher = getBool("query/useColdSearcher", false);
    dataDir = get("dataDir", null);
    if (dataDir != null && dataDir.length() == 0) dataDir = null;

    userCacheConfigs = CacheConfig.getMultipleConfigs(this, "query/cache");

    org.apache.solr.search.SolrIndexSearcher.initRegenerators(this);

    hashSetInverseLoadFactor = 1.0f / getFloat("//HashDocSet/@loadFactor", 0.75f);
    hashDocSetMaxSize = getInt("//HashDocSet/@maxSize", 3000);

    httpCachingConfig = new HttpCachingConfig(this);

    Node jmx = getNode("jmx", false);
    if (jmx != null) {
      jmxConfig =
          new JmxConfiguration(
              true,
              get("jmx/@agentId", null),
              get("jmx/@serviceUrl", null),
              get("jmx/@rootName", null));

    } else {
      jmxConfig = new JmxConfiguration(false, null, null, null);
    }
    maxWarmingSearchers = getInt("query/maxWarmingSearchers", Integer.MAX_VALUE);
    slowQueryThresholdMillis = getInt("query/slowQueryThresholdMillis", -1);
    for (SolrPluginInfo plugin : plugins) loadPluginInfo(plugin);
    updateHandlerInfo = loadUpdatehandlerInfo();

    multipartUploadLimitKB =
        getInt("requestDispatcher/requestParsers/@multipartUploadLimitInKB", 2048);

    formUploadLimitKB = getInt("requestDispatcher/requestParsers/@formdataUploadLimitInKB", 2048);

    enableRemoteStreams = getBool("requestDispatcher/requestParsers/@enableRemoteStreaming", false);

    // Let this filter take care of /select?xxx format
    handleSelect = getBool("requestDispatcher/@handleSelect", true);

    addHttpRequestToContext =
        getBool("requestDispatcher/requestParsers/@addHttpRequestToContext", false);

    List<PluginInfo> argsInfos = getPluginInfos(InitParams.class.getName());
    if (argsInfos != null) {
      Map<String, InitParams> argsMap = new HashMap<>();
      for (PluginInfo p : argsInfos) {
        InitParams args = new InitParams(p);
        argsMap.put(args.name == null ? String.valueOf(args.hashCode()) : args.name, args);
      }
      this.initParams = Collections.unmodifiableMap(argsMap);
    }

    solrRequestParsers = new SolrRequestParsers(this);
    Config.log.info("Loaded SolrConfig: " + name);
  }
Beispiel #2
0
  /**
   * Creates a configuration instance from a resource loader, a configuration name and a stream. If
   * the stream is null, the resource loader will open the configuration stream. If the stream is
   * not null, no attempt to load the resource will occur (the name is not used).
   *
   * @param loader the resource loader
   * @param name the configuration name
   * @param is the configuration stream
   */
  public SolrConfig(SolrResourceLoader loader, String name, InputSource is)
      throws ParserConfigurationException, IOException, SAXException {
    super(loader, name, is, "/config/");
    initLibs();
    luceneMatchVersion = getLuceneVersion("luceneMatchVersion");
    String indexConfigPrefix;

    // Old indexDefaults and mainIndex sections are deprecated and fails fast for
    // luceneMatchVersion=>LUCENE_40.
    // For older solrconfig.xml's we allow the old sections, but never mixed with the new
    // <indexConfig>
    boolean hasDeprecatedIndexConfig =
        get("indexDefaults/text()", null) != null || get("mainIndex/text()", null) != null;
    boolean hasNewIndexConfig = get("indexConfig/text()", null) != null;
    if (hasDeprecatedIndexConfig) {
      if (luceneMatchVersion.onOrAfter(Version.LUCENE_40)) {
        throw new SolrException(
            ErrorCode.FORBIDDEN,
            "<indexDefaults> and <mainIndex> configuration sections are discontinued. Use <indexConfig> instead.");
      } else {
        // Still allow the old sections for older LuceneMatchVersion's
        if (hasNewIndexConfig) {
          throw new SolrException(
              ErrorCode.FORBIDDEN,
              "Cannot specify both <indexDefaults>, <mainIndex> and <indexConfig> at the same time. Please use <indexConfig> only.");
        }
        log.warn(
            "<indexDefaults> and <mainIndex> configuration sections are deprecated and will fail for luceneMatchVersion=LUCENE_40 and later. Please use <indexConfig> instead.");
        defaultIndexConfig = new SolrIndexConfig(this, "indexDefaults", null);
        mainIndexConfig = new SolrIndexConfig(this, "mainIndex", defaultIndexConfig);
        indexConfigPrefix = "mainIndex";
      }
    } else {
      defaultIndexConfig = mainIndexConfig = null;
      indexConfigPrefix = "indexConfig";
    }
    reopenReaders = getBool(indexConfigPrefix + "/reopenReaders", true);
    // Parse indexConfig section, using mainIndex as backup in case old config is used
    indexConfig = new SolrIndexConfig(this, "indexConfig", mainIndexConfig);

    booleanQueryMaxClauseCount =
        getInt("query/maxBooleanClauses", BooleanQuery.getMaxClauseCount());
    log.info("Using Lucene MatchVersion: " + luceneMatchVersion);

    // Warn about deprecated / discontinued parameters
    // boolToFilterOptimizer has had no effect since 3.1
    if (get("query/boolTofilterOptimizer", null) != null)
      log.warn(
          "solrconfig.xml: <boolTofilterOptimizer> is currently not implemented and has no effect.");
    if (get("query/HashDocSet", null) != null)
      log.warn("solrconfig.xml: <HashDocSet> is deprecated and no longer recommended used.");

    // TODO: Old code - in case somebody wants to re-enable. Also see SolrIndexSearcher#search()
    //    filtOptEnabled = getBool("query/boolTofilterOptimizer/@enabled", false);
    //    filtOptCacheSize = getInt("query/boolTofilterOptimizer/@cacheSize",32);
    //    filtOptThreshold = getFloat("query/boolTofilterOptimizer/@threshold",.05f);

    useFilterForSortedQuery = getBool("query/useFilterForSortedQuery", false);
    queryResultWindowSize = Math.max(1, getInt("query/queryResultWindowSize", 1));
    queryResultMaxDocsCached = getInt("query/queryResultMaxDocsCached", Integer.MAX_VALUE);
    enableLazyFieldLoading = getBool("query/enableLazyFieldLoading", false);

    filterCacheConfig = CacheConfig.getConfig(this, "query/filterCache");
    queryResultCacheConfig = CacheConfig.getConfig(this, "query/queryResultCache");
    documentCacheConfig = CacheConfig.getConfig(this, "query/documentCache");
    CacheConfig conf = CacheConfig.getConfig(this, "query/fieldValueCache");
    if (conf == null) {
      Map<String, String> args = new HashMap<String, String>();
      args.put("name", "fieldValueCache");
      args.put("size", "10000");
      args.put("initialSize", "10");
      args.put("showItems", "-1");
      conf = new CacheConfig(FastLRUCache.class, args, null);
    }
    fieldValueCacheConfig = conf;
    unlockOnStartup = getBool(indexConfigPrefix + "/unlockOnStartup", false);
    useColdSearcher = getBool("query/useColdSearcher", false);
    dataDir = get("dataDir", null);
    if (dataDir != null && dataDir.length() == 0) dataDir = null;

    userCacheConfigs = CacheConfig.getMultipleConfigs(this, "query/cache");

    org.apache.solr.search.SolrIndexSearcher.initRegenerators(this);

    hashSetInverseLoadFactor = 1.0f / getFloat("//HashDocSet/@loadFactor", 0.75f);
    hashDocSetMaxSize = getInt("//HashDocSet/@maxSize", 3000);

    httpCachingConfig = new HttpCachingConfig(this);

    Node jmx = getNode("jmx", false);
    if (jmx != null) {
      jmxConfig =
          new JmxConfiguration(
              true,
              get("jmx/@agentId", null),
              get("jmx/@serviceUrl", null),
              get("jmx/@rootName", null));

    } else {
      jmxConfig = new JmxConfiguration(false, null, null, null);
    }
    maxWarmingSearchers = getInt("query/maxWarmingSearchers", Integer.MAX_VALUE);

    loadPluginInfo(SolrRequestHandler.class, "requestHandler", true, true);
    loadPluginInfo(QParserPlugin.class, "queryParser", true, true);
    loadPluginInfo(QueryResponseWriter.class, "queryResponseWriter", true, true);
    loadPluginInfo(ValueSourceParser.class, "valueSourceParser", true, true);
    loadPluginInfo(TransformerFactory.class, "transformer", true, true);
    loadPluginInfo(SearchComponent.class, "searchComponent", true, true);
    loadPluginInfo(QueryConverter.class, "queryConverter", true, true);

    // this is hackish, since it picks up all SolrEventListeners,
    // regardless of when/how/why they are used (or even if they are
    // declared outside of the appropriate context) but there's no nice
    // way around that in the PluginInfo framework
    loadPluginInfo(SolrEventListener.class, "//listener", false, true);

    loadPluginInfo(DirectoryFactory.class, "directoryFactory", false, true);
    loadPluginInfo(IndexDeletionPolicy.class, indexConfigPrefix + "/deletionPolicy", false, true);
    loadPluginInfo(CodecFactory.class, "codecFactory", false, false);
    loadPluginInfo(IndexReaderFactory.class, "indexReaderFactory", false, true);
    loadPluginInfo(UpdateRequestProcessorChain.class, "updateRequestProcessorChain", false, false);
    loadPluginInfo(UpdateLog.class, "updateHandler/updateLog", false, false);
    loadPluginInfo(IndexSchemaFactory.class, "schemaFactory", false, true);

    updateHandlerInfo = loadUpdatehandlerInfo();

    Config.log.info("Loaded SolrConfig: " + name);
  }