Search in sources :

Example 16 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class CarrotClusteringEngine method init.

@Override
@SuppressWarnings("rawtypes")
public String init(NamedList config, final SolrCore core) {
    this.core = core;
    String result = super.init(config, core);
    final SolrParams initParams = SolrParams.toSolrParams(config);
    // Initialization attributes for Carrot2 controller.
    HashMap<String, Object> initAttributes = new HashMap<>();
    // Customize Carrot2's resource lookup to first look for resources
    // using Solr's resource loader. If that fails, try loading from the classpath.
    ResourceLookup resourceLookup = new ResourceLookup(// Solr-specific resource loading.
    new SolrResourceLocator(core, initParams), // Using the class loader directly because this time we want to omit the prefix
    new ClassLoaderLocator(core.getResourceLoader().getClassLoader()));
    DefaultLexicalDataFactoryDescriptor.attributeBuilder(initAttributes).resourceLookup(resourceLookup);
    // Make sure the requested Carrot2 clustering algorithm class is available
    String carrotAlgorithmClassName = initParams.get(CarrotParams.ALGORITHM);
    try {
        this.clusteringAlgorithmClass = core.getResourceLoader().findClass(carrotAlgorithmClassName, IClusteringAlgorithm.class);
    } catch (SolrException s) {
        if (!(s.getCause() instanceof ClassNotFoundException)) {
            throw s;
        }
    }
    // Load Carrot2-Workbench exported attribute XMLs based on the 'name' attribute
    // of this component. This by-name convention lookup is used to simplify configuring algorithms.
    String componentName = initParams.get(ClusteringEngine.ENGINE_NAME);
    log.info("Initializing Clustering Engine '" + MoreObjects.firstNonNull(componentName, "<no 'name' attribute>") + "'");
    if (!Strings.isNullOrEmpty(componentName)) {
        IResource[] attributeXmls = resourceLookup.getAll(componentName + "-attributes.xml");
        if (attributeXmls.length > 0) {
            if (attributeXmls.length > 1) {
                log.warn("More than one attribute file found, first one will be used: " + Arrays.toString(attributeXmls));
            }
            Thread ct = Thread.currentThread();
            ClassLoader prev = ct.getContextClassLoader();
            try {
                ct.setContextClassLoader(core.getResourceLoader().getClassLoader());
                AttributeValueSets avs = AttributeValueSets.deserialize(attributeXmls[0].open());
                AttributeValueSet defaultSet = avs.getDefaultAttributeValueSet();
                initAttributes.putAll(defaultSet.getAttributeValues());
            } catch (Exception e) {
                throw new SolrException(ErrorCode.SERVER_ERROR, "Could not read attributes XML for clustering component: " + componentName, e);
            } finally {
                ct.setContextClassLoader(prev);
            }
        }
    }
    // Extract solrconfig attributes, they take precedence.
    extractCarrotAttributes(initParams, initAttributes);
    // Customize the stemmer and tokenizer factories. The implementations we provide here
    // are included in the code base of Solr, so that it's possible to refactor
    // the Lucene APIs the factories rely on if needed.
    // Additionally, we set a custom lexical resource factory for Carrot2 that
    // will use both Carrot2 default stop words as well as stop words from
    // the StopFilter defined on the field.
    final AttributeBuilder attributeBuilder = BasicPreprocessingPipelineDescriptor.attributeBuilder(initAttributes);
    attributeBuilder.lexicalDataFactory(SolrStopwordsCarrot2LexicalDataFactory.class);
    if (!initAttributes.containsKey(BasicPreprocessingPipelineDescriptor.Keys.TOKENIZER_FACTORY)) {
        attributeBuilder.tokenizerFactory(LuceneCarrot2TokenizerFactory.class);
    }
    if (!initAttributes.containsKey(BasicPreprocessingPipelineDescriptor.Keys.STEMMER_FACTORY)) {
        attributeBuilder.stemmerFactory(LuceneCarrot2StemmerFactory.class);
    }
    // Pass the schema (via the core) to SolrStopwordsCarrot2LexicalDataFactory.
    initAttributes.put("solrCore", core);
    // Carrot2 uses current thread's context class loader to get
    // certain classes (e.g. custom tokenizer/stemmer) at initialization time.
    // To make sure classes from contrib JARs are available,
    // we swap the context class loader for the time of clustering.
    Thread ct = Thread.currentThread();
    ClassLoader prev = ct.getContextClassLoader();
    try {
        ct.setContextClassLoader(core.getResourceLoader().getClassLoader());
        this.controller.init(initAttributes);
    } finally {
        ct.setContextClassLoader(prev);
    }
    SchemaField uniqueField = core.getLatestSchema().getUniqueKeyField();
    if (uniqueField == null) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, CarrotClusteringEngine.class.getSimpleName() + " requires the schema to have a uniqueKeyField");
    }
    this.idFieldName = uniqueField.getName();
    return result;
}
Also used : AttributeBuilder(org.carrot2.text.preprocessing.pipeline.BasicPreprocessingPipelineDescriptor.AttributeBuilder) HashMap(java.util.HashMap) AttributeValueSets(org.carrot2.util.attribute.AttributeValueSets) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) ResourceLookup(org.carrot2.util.resource.ResourceLookup) AttributeValueSet(org.carrot2.util.attribute.AttributeValueSet) SchemaField(org.apache.solr.schema.SchemaField) ClassLoaderLocator(org.carrot2.util.resource.ClassLoaderLocator) IClusteringAlgorithm(org.carrot2.core.IClusteringAlgorithm) SolrParams(org.apache.solr.common.params.SolrParams) SolrException(org.apache.solr.common.SolrException) IResource(org.carrot2.util.resource.IResource)

Example 17 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class AnalyticsComponent method process.

@Override
public void process(ResponseBuilder rb) throws IOException {
    if (rb.req.getParams().getBool(AnalyticsParams.ANALYTICS, false)) {
        SolrParams params = rb.req.getParams();
        AnalyticsStats s = new AnalyticsStats(rb.req, rb.getResults().docSet, params, analyticsCollector);
        rb.rsp.add("stats", s.execute());
    }
}
Also used : AnalyticsStats(org.apache.solr.analytics.request.AnalyticsStats) SolrParams(org.apache.solr.common.params.SolrParams)

Example 18 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class MMapDirectoryFactory method init.

@Override
public void init(NamedList args) {
    super.init(args);
    SolrParams params = SolrParams.toSolrParams(args);
    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);
    //default turn-off
    preload = params.getBool("preload", false);
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams)

Example 19 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class NRTCachingDirectoryFactory method init.

@Override
public void init(NamedList args) {
    super.init(args);
    SolrParams params = SolrParams.toSolrParams(args);
    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");
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams)

Example 20 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class UpdateRequestHandler method createDefaultLoaders.

protected Map<String, ContentStreamLoader> createDefaultLoaders(NamedList args) {
    SolrParams p = null;
    if (args != null) {
        p = SolrParams.toSolrParams(args);
    }
    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().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;
}
Also used : ContentStreamLoader(org.apache.solr.handler.loader.ContentStreamLoader) HashMap(java.util.HashMap) CSVLoader(org.apache.solr.handler.loader.CSVLoader) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) MapSolrParams(org.apache.solr.common.params.MapSolrParams) JsonLoader(org.apache.solr.handler.loader.JsonLoader) JavabinLoader(org.apache.solr.handler.loader.JavabinLoader) XMLLoader(org.apache.solr.handler.loader.XMLLoader)

Aggregations

SolrParams (org.apache.solr.common.params.SolrParams)310 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)179 SolrException (org.apache.solr.common.SolrException)78 Test (org.junit.Test)45 Tuple (org.apache.solr.client.solrj.io.Tuple)43 SolrDocument (org.apache.solr.common.SolrDocument)42 ArrayList (java.util.ArrayList)41 NamedList (org.apache.solr.common.util.NamedList)40 MapSolrParams (org.apache.solr.common.params.MapSolrParams)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)37 IOException (java.io.IOException)35 SolrDocumentList (org.apache.solr.common.SolrDocumentList)34 HashMap (java.util.HashMap)33 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)30 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)27 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)26 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)24 Map (java.util.Map)22 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)22 SolrCore (org.apache.solr.core.SolrCore)20