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

The following examples show how to use org.apache.solr.common.util.NamedList#toSolrParams() . 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: SolrParams.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Deprecated
public SolrParams toFilteredSolrParams(List<String> names) {
  // TODO do this better somehow via a view that filters?  See SolrCore.preDecorateResponse.
  //   ... and/or add some optional predicates to iterator()?
  NamedList<String> nl = new NamedList<>();
  for (Iterator<String> it = getParameterNamesIterator(); it.hasNext();) {
    final String name = it.next();
    if (names.contains(name)) {
      final String[] values = getParams(name);
      for (String value : values) {
        nl.add(name, value);
      }
    }
  }
  return nl.toSolrParams();
}
 
Example 2
Source File: TikaLanguageIdentifierUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * The UpdateRequestProcessor may be initialized in solrconfig.xml similarly
 * to a RequestHandler, with defaults, appends and invariants.
 * @param args a NamedList with the configuration parameters 
 */
@Override
@SuppressWarnings("rawtypes")
public void init( NamedList args )
{
  if (args != null) {
    Object o;
    o = args.get("defaults");
    if (o != null && o instanceof NamedList) {
      defaults = ((NamedList) o).toSolrParams();
    } else {
      defaults = args.toSolrParams();
    }
    o = args.get("appends");
    if (o != null && o instanceof NamedList) {
      appends = ((NamedList) o).toSolrParams();
    }
    o = args.get("invariants");
    if (o != null && o instanceof NamedList) {
      invariants = ((NamedList) o).toSolrParams();
    }
  }
}
 
Example 3
Source File: HdfsDirectoryFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void init(@SuppressWarnings("rawtypes") NamedList args) {
  super.init(args);
  params = args.toSolrParams();
  this.hdfsDataDir = getConfig(HDFS_HOME, null);
  if (this.hdfsDataDir != null && this.hdfsDataDir.length() == 0) {
    this.hdfsDataDir = null;
  } else {
    log.info("{}={}", HDFS_HOME, this.hdfsDataDir);
  }
  cacheMerges = getConfig(CACHE_MERGES, false);
  cacheReadOnce = getConfig(CACHE_READONCE, false);
  boolean kerberosEnabled = getConfig(KERBEROS_ENABLED, false);
  if (log.isInfoEnabled()) {
    log.info("Solr Kerberos Authentication {}", (kerberosEnabled ? "enabled" : "disabled"));
  }
  if (kerberosEnabled) {
    initKerberos();
  }
}
 
Example 4
Source File: IndexSchema.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
static SimilarityFactory readSimilarity(SolrResourceLoader loader, Node node) {
  if (node==null) {
    return null;
  } else {
    SimilarityFactory similarityFactory;
    final String classArg = ((Element) node).getAttribute(SimilarityFactory.CLASS_NAME);
    final Object obj = loader.newInstance(classArg, Object.class, "search.similarities.");
    if (obj instanceof SimilarityFactory) {
      // configure a factory, get a similarity back
      final NamedList<Object> namedList = DOMUtil.childNodesToNamedList(node);
      namedList.add(SimilarityFactory.CLASS_NAME, classArg);
      SolrParams params = namedList.toSolrParams();
      similarityFactory = (SimilarityFactory)obj;
      similarityFactory.init(params);
    } else {
      // just like always, assume it's a Similarity and get a ClassCastException - reasonable error handling
      similarityFactory = new SimilarityFactory() {
        @Override
        public Similarity getSimilarity() {
          return (Similarity) obj;
        }
      };
    }
    return similarityFactory;
  }
}
 
Example 5
Source File: SignatureUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void init(@SuppressWarnings({"rawtypes"})final NamedList args) {
  if (args != null) {
    SolrParams params = args.toSolrParams();
    boolean enabled = params.getBool("enabled", true);
    this.enabled = enabled;

    overwriteDupes = params.getBool("overwriteDupes", true);

    signatureField = params.get("signatureField", "signatureField");

    signatureClass = params.get("signatureClass",
        "org.apache.solr.update.processor.Lookup3Signature");
    this.params = params;

    Object fields = args.get("fields");
    sigFields = fields == null ? null: StrUtils.splitSmart((String)fields, ",", true); 
    if (sigFields != null) {
      Collections.sort(sigFields);
    }
  }
}
 
Example 6
Source File: UpdateRequestHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected Map<String,ContentStreamLoader> createDefaultLoaders(@SuppressWarnings({"rawtypes"})NamedList args) {
  SolrParams p = null;
  if(args!=null) {
    p = args.toSolrParams();
  }
  Map<String,ContentStreamLoader> registry = new HashMap<>();
  registry.put("application/xml", new XMLLoader().init(p) );
  registry.put("application/json", new JsonLoader().init(p) );
  registry.put("application/csv", new CSVLoader().init(p) );
  registry.put("application/javabin", new JavabinLoader(instance).init(p) );
  registry.put("text/csv", registry.get("application/csv") );
  registry.put("text/xml", registry.get("application/xml") );
  registry.put("text/json", registry.get("application/json"));

  pathVsLoaders.put(JSON_PATH,registry.get("application/json"));
  pathVsLoaders.put(DOC_PATH,registry.get("application/json"));
  pathVsLoaders.put(CSV_PATH,registry.get("application/csv"));
  pathVsLoaders.put(BIN_PATH,registry.get("application/javabin"));
  return registry;
}
 
Example 7
Source File: LangDetectLanguageIdentifierUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * The UpdateRequestProcessor may be initialized in solrconfig.xml similarly
 * to a RequestHandler, with defaults, appends and invariants.
 * @param args a NamedList with the configuration parameters 
 */
@Override
@SuppressWarnings("rawtypes")
public void init( NamedList args )
{
  try {
    loadData();
  } catch (Exception e) {
    throw new RuntimeException("Couldn't load profile data, will return empty languages always!", e);
  }
  if (args != null) {
    Object o;
    o = args.get("defaults");
    if (o != null && o instanceof NamedList) {
      defaults = ((NamedList) o).toSolrParams();
    } else {
      defaults = args.toSolrParams();
    }
    o = args.get("appends");
    if (o != null && o instanceof NamedList) {
      appends = ((NamedList) o).toSolrParams();
    }
    o = args.get("invariants");
    if (o != null && o instanceof NamedList) {
      invariants = ((NamedList) o).toSolrParams();
    }
  }
}
 
Example 8
Source File: OpenNLPLangDetectUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void init( @SuppressWarnings({"rawtypes"})NamedList args )
{
  if (args != null) {
    Object o;
    o = args.get("defaults");
    if (o != null && o instanceof NamedList) {
      defaults = ((NamedList) o).toSolrParams();
    } else {
      defaults = args.toSolrParams();
    }
    o = args.get("appends");
    if (o != null && o instanceof NamedList) {
      appends = ((NamedList) o).toSolrParams();
    }
    o = args.get("invariants");
    if (o != null && o instanceof NamedList) {
      invariants = ((NamedList) o).toSolrParams();
    }

    // Look for model filename in invariants, then in args, then defaults
    if (invariants != null) {
      modelFile = invariants.get(MODEL_PARAM);
    }
    if (modelFile == null) {
      o = args.get(MODEL_PARAM);
      if (o != null && o instanceof String) {
        modelFile = (String)o;
      } else {
        modelFile = defaults.get(MODEL_PARAM);
        if (modelFile == null) {
          throw new RuntimeException("Couldn't load language model, will return empty languages always!");
        }
      }
    }
  }
}
 
Example 9
Source File: NRTCachingDirectoryFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"rawtypes"})
public void init(NamedList args) {
  super.init(args);
  SolrParams params = args.toSolrParams();
  maxMergeSizeMB = params.getDouble("maxMergeSizeMB", DEFAULT_MAX_MERGE_SIZE_MB);
  if (maxMergeSizeMB <= 0){
    throw new IllegalArgumentException("maxMergeSizeMB must be greater than 0");
  }
  maxCachedMB = params.getDouble("maxCachedMB", DEFAULT_MAX_CACHED_MB);
  if (maxCachedMB <= 0){
    throw new IllegalArgumentException("maxCachedMB must be greater than 0");
  }
}
 
Example 10
Source File: MMapDirectoryFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"rawtypes"})
public void init(NamedList args) {
  super.init(args);
  SolrParams params = args.toSolrParams();
  maxChunk = params.getInt("maxChunkSize", MMapDirectory.DEFAULT_MAX_CHUNK_SIZE);
  if (maxChunk <= 0){
    throw new IllegalArgumentException("maxChunk must be greater than 0");
  }
  unmapHack = params.getBool("unmap", true);
  preload = params.getBool("preload", false); //default turn-off
}
 
Example 11
Source File: LogUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void init( @SuppressWarnings({"rawtypes"})final NamedList args ) {
  if( args != null ) {
    SolrParams params = args.toSolrParams();
    maxNumToLog = params.getInt( "maxNumToLog", maxNumToLog );
    slowUpdateThresholdMillis = params.getInt("slowUpdateThresholdMillis", slowUpdateThresholdMillis);
  }
}
 
Example 12
Source File: RangerSolrAuthorizer.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Override
public void init(NamedList args) {
	SolrParams params = args.toSolrParams();
	this.authField = params.get(AUTH_FIELD_PROP, DEFAULT_AUTH_FIELD);
	this.allRolesToken = params.get(ALL_ROLES_TOKEN_PROP, "");
	this.enabled = params.getBool(ENABLED_PROP, false);
	this.matchMode = MatchType.valueOf(params.get(MODE_PROP, DEFAULT_MODE_PROP).toUpperCase());

	if (this.matchMode == MatchType.CONJUNCTIVE) {
		this.qParserName = params.get(QPARSER_PROP, "subset").trim();
		this.allowMissingValue = params.getBool(ALLOW_MISSING_VAL_PROP, false);
		this.tokenCountField = params.get(TOKEN_COUNT_PROP, DEFAULT_TOKEN_COUNT_FIELD_PROP);
	}

	this.attrsEnabled = params.getBool(ATTRS_ENABLED_PROP, false);

	logger.info("RangerSolrAuthorizer.init(): authField={" + authField + "}, allRolesToken={" + allRolesToken +
			"}, enabled={" + enabled + "}, matchType={" + matchMode + "}, qParserName={" + qParserName +
			"}, allowMissingValue={" + allowMissingValue + "}, tokenCountField={" + tokenCountField + "}, attrsEnabled={" + attrsEnabled + "}");

	if (attrsEnabled) {

		if (params.get(FIELD_ATTR_MAPPINGS) != null) {
			logger.info("Solr params = " + params.get(FIELD_ATTR_MAPPINGS));

			NamedList mappings = checkAndGet(args, FIELD_ATTR_MAPPINGS);

			Iterator<Map.Entry<String, NamedList>> iter = mappings.iterator();
			while (iter.hasNext()) {
				Map.Entry<String, NamedList> entry = iter.next();
				String solrFieldName = entry.getKey();
				String attributeNames = checkAndGet(entry.getValue(), ATTR_NAMES);
				String filterType = checkAndGet(entry.getValue(), FIELD_FILTER_TYPE);
				boolean acceptEmpty = false;
				if (entry.getValue().getBooleanArg(PERMIT_EMPTY_VALUES) != null) {
					acceptEmpty = entry.getValue().getBooleanArg(PERMIT_EMPTY_VALUES);
				}
				String allUsersValue = getWithDefault(entry.getValue(), ALL_USERS_VALUE, "");
				String regex = getWithDefault(entry.getValue(), ATTRIBUTE_FILTER_REGEX, "");
				String extraOpts = getWithDefault(entry.getValue(), EXTRA_OPTS, "");
				FieldToAttributeMapping mapping = new FieldToAttributeMapping(solrFieldName, attributeNames, filterType, acceptEmpty, allUsersValue, regex, extraOpts);
				fieldAttributeMappings.add(mapping);
			}
		}
		this.andQParserName = this.<String>checkAndGet(args, AND_OP_QPARSER).trim();
	}
}
 
Example 13
Source File: SolrParams.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Create SolrParams from NamedList.
 * @deprecated Use {@link NamedList#toSolrParams()}.
 */
@Deprecated //move to NamedList to allow easier flow
public static SolrParams toSolrParams(@SuppressWarnings({"rawtypes"})NamedList params) {
  return params.toSolrParams();
}
 
Example 14
Source File: DirectSolrSpellChecker.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public String init(@SuppressWarnings({"rawtypes"})NamedList config, SolrCore core) {

  SolrParams params = config.toSolrParams();

  log.info("init: {}", config);
  String name = super.init(config, core);
  
  Comparator<SuggestWord> comp = SuggestWordQueue.DEFAULT_COMPARATOR;
  String compClass = (String) config.get(COMPARATOR_CLASS);
  if (compClass != null) {
    if (compClass.equalsIgnoreCase(SCORE_COMP))
      comp = SuggestWordQueue.DEFAULT_COMPARATOR;
    else if (compClass.equalsIgnoreCase(FREQ_COMP))
      comp = new SuggestWordFrequencyComparator();
    else //must be a FQCN
      comp = (Comparator<SuggestWord>) core.getResourceLoader().newInstance(compClass, Comparator.class);
  }
  
  StringDistance sd = DirectSpellChecker.INTERNAL_LEVENSHTEIN;
  String distClass = (String) config.get(STRING_DISTANCE);
  if (distClass != null && !distClass.equalsIgnoreCase(INTERNAL_DISTANCE))
    sd = core.getResourceLoader().newInstance(distClass, StringDistance.class);

  float minAccuracy = DEFAULT_ACCURACY;
  Float accuracy = params.getFloat(ACCURACY);
  if (accuracy != null)
    minAccuracy = accuracy;
  
  int maxEdits = DEFAULT_MAXEDITS;
  Integer edits = params.getInt(MAXEDITS);
  if (edits != null)
    maxEdits = edits;
  
  int minPrefix = DEFAULT_MINPREFIX;
  Integer prefix = params.getInt(MINPREFIX);
  if (prefix != null)
    minPrefix = prefix;
  
  int maxInspections = DEFAULT_MAXINSPECTIONS;
  Integer inspections = params.getInt(MAXINSPECTIONS);
  if (inspections != null)
    maxInspections = inspections;
  
  float minThreshold = DEFAULT_THRESHOLD_TOKEN_FREQUENCY;
  Float threshold = params.getFloat(THRESHOLD_TOKEN_FREQUENCY);
  if (threshold != null)
    minThreshold = threshold;
  
  int minQueryLength = DEFAULT_MINQUERYLENGTH;
  Integer queryLength = params.getInt(MINQUERYLENGTH);
  if (queryLength != null)
    minQueryLength = queryLength;

  int maxQueryLength = DEFAULT_MAXQUERYLENGTH;
  Integer overriddenMaxQueryLength = params.getInt(MAXQUERYLENGTH);
  if (overriddenMaxQueryLength != null)
    maxQueryLength = overriddenMaxQueryLength;
  
  float maxQueryFrequency = DEFAULT_MAXQUERYFREQUENCY;
  Float queryFreq = params.getFloat(MAXQUERYFREQUENCY);
  if (queryFreq != null)
    maxQueryFrequency = queryFreq;
  
  checker.setComparator(comp);
  checker.setDistance(sd);
  checker.setMaxEdits(maxEdits);
  checker.setMinPrefix(minPrefix);
  checker.setAccuracy(minAccuracy);
  checker.setThresholdFrequency(minThreshold);
  checker.setMaxInspections(maxInspections);
  checker.setMinQueryLength(minQueryLength);
  checker.setMaxQueryLength(maxQueryLength);
  checker.setMaxQueryFrequency(maxQueryFrequency);
  checker.setLowerCaseTerms(false);
  
  return name;
}
 
Example 15
Source File: QueryElevationComponent.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void init(@SuppressWarnings({"rawtypes"})NamedList args) {
  this.initArgs = args.toSolrParams();
}
 
Example 16
Source File: RegexpBoostProcessorFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void init(@SuppressWarnings("rawtypes") final NamedList args) {
    if (args != null) {
      this.params = args.toSolrParams();
    }
}
 
Example 17
Source File: URLClassifyProcessorFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void init(@SuppressWarnings("rawtypes") final NamedList args) {
  if (args != null) {
    this.params = args.toSolrParams();
  }
}
 
Example 18
Source File: ClassificationUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void init(@SuppressWarnings({"rawtypes"})final NamedList args) {
  if (args != null) {
    params = args.toSolrParams();
    classificationParams = new ClassificationUpdateProcessorParams();

    String fieldNames = params.get(INPUT_FIELDS_PARAM);// must be a comma separated list of fields
    checkNotNull(INPUT_FIELDS_PARAM, fieldNames);
    classificationParams.setInputFieldNames(fieldNames.split("\\,"));

    String trainingClassField = (params.get(TRAINING_CLASS_FIELD_PARAM));
    checkNotNull(TRAINING_CLASS_FIELD_PARAM, trainingClassField);
    classificationParams.setTrainingClassField(trainingClassField);

    String predictedClassField = (params.get(PREDICTED_CLASS_FIELD_PARAM));
    if (predictedClassField == null || predictedClassField.isEmpty()) {
      predictedClassField = trainingClassField;
    }
    classificationParams.setPredictedClassField(predictedClassField);

    classificationParams.setMaxPredictedClasses(getIntParam(params, MAX_CLASSES_TO_ASSIGN_PARAM, DEFAULT_MAX_CLASSES_TO_ASSIGN));

    String algorithmString = params.get(ALGORITHM_PARAM);
    Algorithm classificationAlgorithm;
    try {
      if (algorithmString == null || Algorithm.valueOf(algorithmString.toUpperCase(Locale.ROOT)) == null) {
        classificationAlgorithm = DEFAULT_ALGORITHM;
      } else {
        classificationAlgorithm = Algorithm.valueOf(algorithmString.toUpperCase(Locale.ROOT));
      }
    } catch (IllegalArgumentException e) {
      throw new SolrException
          (SolrException.ErrorCode.SERVER_ERROR,
              "Classification UpdateProcessor Algorithm: '" + algorithmString + "' not supported");
    }
    classificationParams.setAlgorithm(classificationAlgorithm);

    classificationParams.setMinTf(getIntParam(params, KNN_MIN_TF_PARAM, DEFAULT_MIN_TF));
    classificationParams.setMinDf(getIntParam(params, KNN_MIN_DF_PARAM, DEFAULT_MIN_DF));
    classificationParams.setK(getIntParam(params, KNN_K_PARAM, DEFAULT_K));
  }
}
 
Example 19
Source File: XSLTResponseWriter.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void init(@SuppressWarnings({"rawtypes"})NamedList n) {
  final SolrParams p = n.toSolrParams();
    xsltCacheLifetimeSeconds = p.getInt(XSLT_CACHE_PARAM,XSLT_CACHE_DEFAULT);
    log.info("xsltCacheLifetimeSeconds={}", xsltCacheLifetimeSeconds);
}
 
Example 20
Source File: LocalSolrQueryRequest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public LocalSolrQueryRequest(SolrCore core, @SuppressWarnings({"rawtypes"})NamedList args) {
  super(core, args.toSolrParams());
}