org.apache.solr.rest.schema.analysis.ManagedWordSetResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-core Show documentation
Show all versions of solr-core Show documentation
Apache Solr (module: core)
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.rest.schema.analysis;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.rest.BaseSolrResource;
import org.apache.solr.rest.ManagedResource;
import org.apache.solr.rest.ManagedResourceStorage.StorageIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* ManagedResource implementation for managing a set of words using the REST API; useful for
* managing stop words and/or protected words for analysis components like the KeywordMarkerFilter.
*/
public class ManagedWordSetResource extends ManagedResource
implements ManagedResource.ChildResourceSupport {
public static final String WORD_SET_JSON_FIELD = "wordSet";
public static final String IGNORE_CASE_INIT_ARG = "ignoreCase";
private SortedSet managedWords = null;
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public ManagedWordSetResource(String resourceId, SolrResourceLoader loader, StorageIO storageIO)
throws SolrException {
super(resourceId, loader, storageIO);
}
/** Returns the set of words in this managed word set. */
public Set getWordSet() {
return Collections.unmodifiableSet(managedWords);
}
/**
* 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() {
return getIgnoreCase(managedInitArgs);
}
/**
* 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;
}
/**
* Invoked when loading data from storage to initialize the list of words managed by this
* instance. A load of the data can happen many times throughout the life cycle of this object.
*/
@SuppressWarnings("unchecked")
@Override
protected void onManagedDataLoadedFromStorage(NamedList initArgs, Object data)
throws SolrException {
// the default behavior is to not ignore case,
boolean ignoreCase = getIgnoreCase(initArgs);
if (null == initArgs.get(IGNORE_CASE_INIT_ARG)) {
// Explicitly include the default value of ignoreCase
((NamedList