Java Code Examples for org.apache.solr.common.util.NamedList#getBooleanArg()

The following examples show how to use org.apache.solr.common.util.NamedList#getBooleanArg() . 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 File: SynonymFormatCommonRulesRewriterFactory.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Override
public RewriterFactory createFactory(final String id, final NamedList<?> args, final ResourceLoader resourceLoader)
        throws IOException {

   String boostUp = (String) args.get("boostUp");
   String boostDown = (String) args.get("boostDown");
   Boolean ignoreCase = args.getBooleanArg("ignoreCase");

   if ((boostUp == null) && (boostDown == null)) {
      // remove this check when we load other instruction types
      throw new IllegalArgumentException("At least on of boostUp or boostDown must be configured");
   }

   RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(ignoreCase != null && ignoreCase);

   if (boostUp != null) {
      addBoostInstructions(builder, BoostDirection.UP, 1f, resourceLoader, boostUp);
   }

   if (boostDown != null) {
      addBoostInstructions(builder, BoostDirection.DOWN, 1f, resourceLoader, boostDown);
   }

   return new RulesRewriterFactory(id, builder.build());
}
 
Example 2
Source File: ManagedStopFilterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Callback invoked by the {@link ManagedResource} instance to trigger this
 * class to create the CharArraySet used to create the StopFilter using the
 * wordset managed by {@link ManagedWordSetResource}. Keep in mind that
 * a schema.xml may reuse the same {@link ManagedStopFilterFactory} many
 * times for different field types; behind the scenes all instances of this
 * class/handle combination share the same managed data, hence the need for
 * a listener/callback scheme.
 */
@Override
public void onManagedResourceInitialized(NamedList<?> args, ManagedResource res) 
    throws SolrException {

  Set<String> managedWords = ((ManagedWordSetResource)res).getWordSet(); 
      
  // first thing is to rebuild the Lucene CharArraySet from our managedWords set
  // which is slightly inefficient to do for every instance of the managed filter
  // but ManagedResource's don't have access to the luceneMatchVersion
  boolean ignoreCase = args.getBooleanArg("ignoreCase");
  stopWords = new CharArraySet(managedWords.size(), ignoreCase);
  stopWords.addAll(managedWords);
}
 
Example 3
Source File: ConfigSetService.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Load the ConfigSet for a core
 * @param dcore the core's CoreDescriptor
 * @return a ConfigSet
 */
@SuppressWarnings({"rawtypes"})
public final ConfigSet loadConfigSet(CoreDescriptor dcore) {

  SolrResourceLoader coreLoader = createCoreResourceLoader(dcore);

  try {

    // ConfigSet properties are loaded from ConfigSetProperties.DEFAULT_FILENAME file.
    NamedList properties = loadConfigSetProperties(dcore, coreLoader);
    // ConfigSet flags are loaded from the metadata of the ZK node of the configset.
    NamedList flags = loadConfigSetFlags(dcore, coreLoader);

    boolean trusted =
        (coreLoader instanceof ZkSolrResourceLoader
            && flags != null
            && flags.get("trusted") != null
            && !flags.getBooleanArg("trusted")
            ) ? false: true;

    SolrConfig solrConfig = createSolrConfig(dcore, coreLoader, trusted);
    IndexSchema schema = createIndexSchema(dcore, solrConfig);
    return new ConfigSet(configSetName(dcore), solrConfig, schema, properties, trusted);
  } catch (Exception e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
        "Could not load conf for core " + dcore.getName() +
            ": " + e.getMessage(), e);
  }

}
 
Example 4
Source File: SolrSynonymsRewriterFactory.java    From querqy with Apache License 2.0 5 votes vote down vote up
@Override
public RewriterFactory createFactory(final String id, final NamedList<?> args, final ResourceLoader resourceLoader)
        throws IOException {

   Boolean expand = args.getBooleanArg("expand");
   if (expand == null) {
      expand = false;
   }

   Boolean ignoreCase = args.getBooleanArg("ignoreCase");
   if (ignoreCase == null) {
      ignoreCase = true;
   }

   String synonymResoureName = (String) args.get("synonyms");
   if (synonymResoureName == null) {
      throw new IllegalArgumentException("Property 'synonyms' not configured");
   }

   LuceneSynonymsRewriterFactory factory = new LuceneSynonymsRewriterFactory(id, expand, ignoreCase);
   for (String resource : synonymResoureName.split(",")) {
      resource = resource.trim();
      if (resource.length() > 0) {
         factory.addResource(resourceLoader.openResource(resource));
      }
   }

   factory.build();

   return factory;

}
 
Example 5
Source File: ReplaceRewriterFactory.java    From querqy with Apache License 2.0 5 votes vote down vote up
@Override
public RewriterFactory createFactory(String id, NamedList<?> args, ResourceLoader resourceLoader) throws IOException {

    final String rulesResourceName = (String) args.get("rules");
    if (rulesResourceName == null) {
        throw new IllegalArgumentException("Property 'rules' not configured");
    }

    final InputStreamReader reader = new InputStreamReader(resourceLoader.openResource(rulesResourceName), StandardCharsets.UTF_8);

    final Boolean ignoreCase = args.getBooleanArg("ignoreCase");

    final String inputDelimiter = (String) args.get("inputDelimiter");

    // querqy parser for queries that are part of the instructions in the rules
    String rulesQuerqyParser = (String) args.get("querqyParser");
    QuerqyParserFactory querqyParser = null;
    if (rulesQuerqyParser != null) {
        rulesQuerqyParser = rulesQuerqyParser.trim();
        if (rulesQuerqyParser.length() > 0) {
            querqyParser = resourceLoader.newInstance(rulesQuerqyParser, QuerqyParserFactory.class);
        }
    }

    if (querqyParser == null) {
        querqyParser = new WhiteSpaceQuerqyParserFactory();
    }

    return new querqy.rewrite.contrib.ReplaceRewriterFactory(id, reader,
            ignoreCase != null ? ignoreCase : DEFAULT_IGNORE_CASE,
            inputDelimiter != null ? inputDelimiter : DEFAULT_INPUT_DELIMITER,
            querqyParser.createParser());
}
 
Example 6
Source File: NumFoundSearchComponent.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public void init(NamedList args) {
	super.init(args);

	joinField = (String)args.get(INIT_JOIN_FIELD);
	Boolean b = args.getBooleanArg(INIT_IGNORE_CONVERSION_ERRORS);
	if (b != null) {
		ignoreConversionErrors = b.booleanValue();
	}
}
 
Example 7
Source File: ClusteringComponent.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void inform(SolrCore core) {
  if (initParams != null) {
    log.info("Initializing Clustering Engines");

    // Our target list of engines, split into search-results and document clustering.
    SolrResourceLoader loader = core.getResourceLoader();

    for (Map.Entry<String,Object> entry : initParams) {
      if ("engine".equals(entry.getKey())) {
        NamedList<Object> engineInitParams = (NamedList<Object>) entry.getValue();
        Boolean optional = engineInitParams.getBooleanArg("optional");
        optional = (optional == null ? Boolean.FALSE : optional);

        String engineClassName = StringUtils.defaultIfBlank( 
            (String) engineInitParams.get("classname"),
            CarrotClusteringEngine.class.getName()); 

        // Instantiate the clustering engine and split to appropriate map. 
        final ClusteringEngine engine = loader.newInstance(engineClassName, ClusteringEngine.class);
        final String name = StringUtils.defaultIfBlank(engine.init(engineInitParams, core), "");

        if (!engine.isAvailable()) {
          if (optional) {
            log.info("Optional clustering engine not available: {}", name);
          } else {
            throw new SolrException(ErrorCode.SERVER_ERROR, 
                "A required clustering engine failed to initialize, check the logs: " + name);
          }
        }
        
        final ClusteringEngine previousEntry;
        if (engine instanceof SearchClusteringEngine) {
          previousEntry = searchClusteringEngines.put(name, (SearchClusteringEngine) engine);
        } else if (engine instanceof DocumentClusteringEngine) {
          previousEntry = documentClusteringEngines.put(name, (DocumentClusteringEngine) engine);
        } else {
          log.warn("Unknown type of a clustering engine for class: {}", engineClassName);
          continue;
        }
        if (previousEntry != null) {
          log.warn("Duplicate clustering engine component named '{}'.", name);
        }
      }
    }

    // Set up the default engine key for both types of engines.
    setupDefaultEngine("search results clustering", searchClusteringEngines);
    setupDefaultEngine("document clustering", documentClusteringEngines);

    log.info("Finished Initializing Clustering Engines");
  }
}
 
Example 8
Source File: JaegerTracerConfigurator.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void init(@SuppressWarnings({"rawtypes"})NamedList args) {
  Object host = args.get(AGENT_HOST);
  if (!(host instanceof String)) {
    throw new IllegalArgumentException("Expected a required string for param '" + AGENT_HOST + "'");
  }

  Object portArg = args.get(AGENT_PORT);
  if (!(portArg instanceof Integer)) {
    throw new IllegalArgumentException("Expected a required int for param '" + AGENT_PORT + "'");
  }
  int port = (Integer) portArg;

  Boolean logSpans = args.getBooleanArg(LOG_SPANS);
  if (logSpans == null)
    logSpans = true;

  Object flushIntervalArg = args.get(FLUSH_INTERVAL);
  if (flushIntervalArg != null && !(flushIntervalArg instanceof Integer)) {
    throw new IllegalArgumentException("Expected a required int for param '" + FLUSH_INTERVAL +"'");
  }
  int flushInterval = flushIntervalArg == null ? 1000 : (Integer) flushIntervalArg;

  Object maxQueueArgs = args.get(MAX_QUEUE_SIZE);
  if (maxQueueArgs != null && !(maxQueueArgs instanceof Integer)) {
    throw new IllegalArgumentException("Expected a required int for param '" + MAX_QUEUE_SIZE +"'");
  }
  int maxQueue = maxQueueArgs == null ? 10000 : (Integer) maxQueueArgs;

  Configuration.SamplerConfiguration samplerConfig = new Configuration.SamplerConfiguration()
      .withType(ConstSampler.TYPE)
      .withParam(1);

  Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv();
  Configuration.SenderConfiguration senderConfig = reporterConfig.getSenderConfiguration()
      .withAgentHost(host.toString())
      .withAgentPort(port);

  reporterConfig.withLogSpans(logSpans)
      .withFlushInterval(flushInterval)
      .withMaxQueueSize(maxQueue)
      .withSender(senderConfig);
  tracer = new Configuration("solr")
      .withSampler(samplerConfig)
      .withReporter(reporterConfig)
      .getTracer();
}
 
Example 9
Source File: IndexFetcher.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public IndexFetcher(@SuppressWarnings({"rawtypes"})final NamedList initArgs, final ReplicationHandler handler, final SolrCore sc) {
  solrCore = sc;
  Object fetchFromLeader = initArgs.get(FETCH_FROM_LEADER);
  if (fetchFromLeader != null && fetchFromLeader instanceof Boolean) {
    this.fetchFromLeader = (boolean) fetchFromLeader;
  }
  Object skipCommitOnMasterVersionZero = initArgs.get(SKIP_COMMIT_ON_MASTER_VERSION_ZERO);
  if (skipCommitOnMasterVersionZero != null && skipCommitOnMasterVersionZero instanceof Boolean) {
    this.skipCommitOnMasterVersionZero = (boolean) skipCommitOnMasterVersionZero;
  }
  String masterUrl = (String) initArgs.get(MASTER_URL);
  if (masterUrl == null && !this.fetchFromLeader)
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
            "'masterUrl' is required for a slave");
  if (masterUrl != null && masterUrl.endsWith(ReplicationHandler.PATH)) {
    masterUrl = masterUrl.substring(0, masterUrl.length()-12);
    log.warn("'masterUrl' must be specified without the {} suffix", ReplicationHandler.PATH);
  }
  this.masterUrl = masterUrl;

  this.replicationHandler = handler;
  String compress = (String) initArgs.get(COMPRESSION);
  useInternalCompression = INTERNAL.equals(compress);
  useExternalCompression = EXTERNAL.equals(compress);
  connTimeout = getParameter(initArgs, HttpClientUtil.PROP_CONNECTION_TIMEOUT, 30000, null);
  
  // allow a master override for tests - you specify this in /replication slave section of solrconfig and some 
  // test don't want to define this
  soTimeout = Integer.getInteger("solr.indexfetcher.sotimeout", -1);
  if (soTimeout == -1) {
    soTimeout = getParameter(initArgs, HttpClientUtil.PROP_SO_TIMEOUT, 120000, null);
  }

  if (initArgs.getBooleanArg(TLOG_FILES) != null) {
    downloadTlogFiles = initArgs.getBooleanArg(TLOG_FILES);
  }

  String httpBasicAuthUser = (String) initArgs.get(HttpClientUtil.PROP_BASIC_AUTH_USER);
  String httpBasicAuthPassword = (String) initArgs.get(HttpClientUtil.PROP_BASIC_AUTH_PASS);
  myHttpClient = createHttpClient(solrCore, httpBasicAuthUser, httpBasicAuthPassword, useExternalCompression);
}
 
Example 10
Source File: ManagedSynonymGraphFilterFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public boolean getIgnoreCase(NamedList<?> initArgs) {
  Boolean ignoreCase = initArgs.getBooleanArg(IGNORE_CASE_INIT_ARG);
  // ignoreCase = false by default
  return null == ignoreCase ? false : ignoreCase;
}
 
Example 11
Source File: ManagedWordSetResource.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the boolean value of the {@link #IGNORE_CASE_INIT_ARG} init arg,
 * or the default value (false) if it has not been specified
 */
public boolean getIgnoreCase(NamedList<?> initArgs) {
  Boolean ignoreCase = initArgs.getBooleanArg(IGNORE_CASE_INIT_ARG);
  // ignoreCase = false by default
  return null == ignoreCase ? false : ignoreCase;
}
 
Example 12
Source File: ManagedSynonymFilterFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public boolean getIgnoreCase(NamedList<?> initArgs) {
  Boolean ignoreCase = initArgs.getBooleanArg(IGNORE_CASE_INIT_ARG);
  // ignoreCase = false by default
  return null == ignoreCase ? false : ignoreCase;
}
 
Example 13
Source File: SimpleCommonRulesRewriterFactory.java    From querqy with Apache License 2.0 4 votes vote down vote up
@Override
public RewriterFactory createFactory(final String id, final NamedList<?> args,
                                     final ResourceLoader resourceLoader) throws IOException {

    final String rulesResourceName = (String) args.get("rules");
    if (rulesResourceName == null) {
        throw new IllegalArgumentException("Property 'rules' not configured");
    }

    final Map<String, SelectionStrategyFactory> selectionStrategyFactories = new HashMap<>();

    final NamedList<?> selectionStrategyConfiguration = (NamedList<?>) args.get("rules.selectionStrategy");

    if (selectionStrategyConfiguration != null) {

        @SuppressWarnings("unchecked")
        final List<NamedList<?>> strategyConfigs = (List<NamedList<?>>) selectionStrategyConfiguration
                .getAll("strategy");

        if (strategyConfigs != null) {
            for (NamedList<?> config : strategyConfigs) {
                @SuppressWarnings("unchecked")
                final FactoryAdapter<SelectionStrategyFactory> factory = resourceLoader
                        .newInstance((String) config.get("class"), FactoryAdapter.class);
                final String strategyId = (String) config.get("id");
                if (selectionStrategyFactories.put(strategyId,
                        factory.createFactory(strategyId, config, resourceLoader)) != null) {
                    throw new IOException("Duplicate id in rules.selectionStrategy: " + id);
                }
            }
        }
    }


    final Boolean ignoreCase = args.getBooleanArg("ignoreCase");

    // querqy parser for queries that are part of the instructions in the
    // rules
    String rulesQuerqyParser = (String) args.get("querqyParser");
    QuerqyParserFactory querqyParser = null;
    if (rulesQuerqyParser != null) {
        rulesQuerqyParser = rulesQuerqyParser.trim();
        if (rulesQuerqyParser.length() > 0) {
            querqyParser = resourceLoader.newInstance(rulesQuerqyParser, QuerqyParserFactory.class);
        }
    }

    if (querqyParser == null) {
        querqyParser = new WhiteSpaceQuerqyParserFactory();
    }

    return new querqy.rewrite.commonrules.SimpleCommonRulesRewriterFactory(id,
            new InputStreamReader(resourceLoader.openResource(rulesResourceName), "UTF-8"), querqyParser,
            ignoreCase == null || ignoreCase, selectionStrategyFactories, DEFAULT_SELECTION_STRATEGY_FACTORY);
}
 
Example 14
Source File: ShingleRewriterFactory.java    From querqy with Apache License 2.0 4 votes vote down vote up
@Override
public RewriterFactory createFactory(final String id, NamedList<?> args, ResourceLoader resourceLoader) {
    Boolean acceptGeneratedTerms = args.getBooleanArg("acceptGeneratedTerms");
    boolean t = (acceptGeneratedTerms == null) ? false : acceptGeneratedTerms;
    return new querqy.rewrite.contrib.ShingleRewriterFactory(id, t);
}