1.系统使用 SSM 来搭建  使用maven和svn用来管理jar和版本控制

2.架构搭建--

1.maven的配置文件导入jar包依赖和文件资源管理

2.配置web.xml加载spring相关的配置文件

3.配置spring相关的配置 springmvc 数据连接 及 事务处理(solr用不到)

4.配置相关工具类
   AOP切面日志工具类---见以前的 博客
http://blog.csdn.net/sqh201030412/article/details/50916179

返回结果工具类
package cn.com.mx.gome.search.core.common;

import java.io.Serializable;

import com.alibaba.fastjson.annotation.JSONField;
/**
 * 统一结果返回类
 * @author songqinghu
 *
 * @param <T>
 */
public class ResultData<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 处理结果
     */
    @JSONField(ordinal = 1)
    private Boolean success = true;

    /**
     * 响应码:200为成功,其他:失败(六位数正整形) 默认SUCCESS
     */
    @JSONField(ordinal = 2)
    private int code = 200;

    /**
     * 响应信息,默认SUCCESS_MSG
     */
    @JSONField(ordinal = 4)
    private String message;
    
    @JSONField(ordinal = 3)
    private Long totalCount;

    /**
     * 返回数据, 如果没有返回数据时,可定义为String类型,赋予""空值
     */
    @JSONField(ordinal = 5)
    private T data;

    public ResultData() {

    }

    public ResultData(Boolean success, int code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }

}

properties文件加载
package cn.com.mx.gome.search.core.util.prop;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
import org.apache.log4j.Logger;

public class Property {

    private static final Logger logger = Logger.getLogger(Property.class);

    private final byte[] lock = new byte[0];

    private ConcurrentMap<String, PropertiesConfiguration> configMap = new ConcurrentHashMap<String, PropertiesConfiguration>();

    private String dir;
    private String filename;
    private boolean isChange = true;

    protected void setDir(String dir) {
        this.dir = dir;
    }

    protected void setFilename(String filename) {
        this.filename = filename;
    }

    protected void setChange(boolean isChange) {
        this.isChange = isChange;
    }

    private PropertiesConfiguration loadConfig(String configFile) {
        PropertiesConfiguration config = configMap.get(configFile);
        if (config == null) {
            synchronized (lock) {
                try {
                    config = new PropertiesConfiguration();
                    config.setListDelimiter((char) 0);
                    if (isChange) {
                        // 可以自动更新
                        config.load(new File(configFile));
                        config.setReloadingStrategy(new FileChangedReloadingStrategy());
                    } else {
                        config.load(new FileInputStream(configFile));
                    }
                    configMap.put(configFile, config);
                } catch (Exception e) {
                    logger.error("load config error: " + e);
                }
            }
        }
        return config;
    }

    private PropertiesConfiguration loadConfig(ClassLoader classLoader, String configFile) {
        PropertiesConfiguration config = configMap.get(configFile);
        if (config == null) {
            synchronized (lock) {
                try {
                    InputStream inputStream = classLoader.getResourceAsStream(configFile);
                    config = new PropertiesConfiguration();
                    config.setListDelimiter((char) 0);
                    config.load(inputStream);
                    configMap.put(configFile, config);
                } catch (Exception e) {
                    logger.error("load config error: " + e);
                }
            }
        }
        return config;
    }

    private String path(String configFile) {
        return dir + configFile;
    }

    /**
     * 默认classes下面的config.properties
     * 
     * @param key
     * @return
     */
    public String get(String key) {
        return get(filename, key);
    }

    /**
     * classes下面指定的configFile
     * 
     * @param configFile 配置文件名
     * @param key
     * @return
     */
    public String get(String configFile, String key) {
        PropertiesConfiguration config = loadConfig(path(configFile));
        try {
            return config.getString(key);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 指定jar包中的configFile
     * 
     * @param classLoader 指定jar包的类加载器
     * @param configFile 配置文件名
     * @param key
     * @return
     */
    public String get(ClassLoader classLoader, String configFile, String key) {
        PropertiesConfiguration config = loadConfig(classLoader, configFile);
        try {
            return config.getString(key);
        } catch (Exception e) {
            return null;
        }
    }

    public String getString(String key, String defaultValue) {
        return getString(filename, key, defaultValue);
    }

    public String getString(String configFile, String key, String defaultValue) {
        PropertiesConfiguration config = loadConfig(path(configFile));
        return config.getString(key, defaultValue);
    }

    public String getString(ClassLoader classLoader, String configFile, String key, String defaultValue) {
        PropertiesConfiguration config = loadConfig(classLoader, configFile);
        return config.getString(key, defaultValue);
    }

    public int getInt(String key, int defaultValue) {
        return getInt(filename, key, defaultValue);
    }

    public int getInt(String configFile, String key, int defaultValue) {
        PropertiesConfiguration config = loadConfig(path(configFile));
        try {
            return config.getInt(key);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public int getInt(ClassLoader classLoader, String configFile, String key, int defaultValue) {
        PropertiesConfiguration config = loadConfig(classLoader, configFile);
        try {
            return config.getInt(key);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public float getFloat(String key, float defaultValue) {
        return getFloat(filename, key, defaultValue);
    }

    public float getFloat(String configFile, String key, float defaultValue) {
        PropertiesConfiguration config = loadConfig(path(configFile));
        try {
            return config.getFloat(key);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public float getFloat(ClassLoader classLoader, String configFile, String key, float defaultValue) {
        PropertiesConfiguration config = loadConfig(classLoader, configFile);
        try {
            return config.getFloat(key);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public long getLong(String key, long defaultValue) {
        return getLong(filename, key, defaultValue);
    }

    public long getLong(String configFile, String key, long defaultValue) {
        PropertiesConfiguration config = loadConfig(path(configFile));
        try {
            return config.getLong(key);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public long getLong(ClassLoader classLoader, String configFile, String key, long defaultValue) {
        PropertiesConfiguration config = loadConfig(classLoader, configFile);
        try {
            return config.getLong(key);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public boolean getBoolean(String key, boolean defaultValue) {
        return getBoolean(filename, key, defaultValue);
    }

    public boolean getBoolean(String configFile, String key, boolean defaultValue) {
        PropertiesConfiguration config = loadConfig(path(configFile));
        try {
            return config.getBoolean(key);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public boolean getBoolean(ClassLoader classLoader, String configFile, String key, boolean defaultValue) {
        PropertiesConfiguration config = loadConfig(classLoader, configFile);
        try {
            return config.getBoolean(key);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public List<?> getList(String key) {
        return getList(filename, key);
    }

    public List<?> getList(String configFile, String key) {
        PropertiesConfiguration config = loadConfig(path(configFile));
        try {
            return config.getList(key);
        } catch (Exception e) {
            return null;
        }
    }

    public List<?> getList(ClassLoader classLoader, String configFile, String key) {
        PropertiesConfiguration config = loadConfig(classLoader, configFile);
        try {
            return config.getList(key);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * {@inheritDoc} This implementation returns keys that either match the
     * prefix or start with the prefix followed by a dot ('.'). So the call
     * {@code getKeys("db");} will find the keys {@code db}, {@code db.user}, or
     * {@code db.password}, but not the key {@code dbdriver}.
     */
    public Iterator<String> getKeys(String prefix) {
        return getKeys(filename, prefix);
    }

    public Iterator<String> getKeys(String configFile, String prefix) {
        PropertiesConfiguration config = loadConfig(path(configFile));
        try {
            return config.getKeys(prefix);
        } catch (Exception e) {
            return null;
        }
    }

    public Iterator<String> getKeys(ClassLoader classLoader, String configFile, String prefix) {
        PropertiesConfiguration config = loadConfig(classLoader, configFile);
        try {
            return config.getKeys(prefix);
        } catch (Exception e) {
            return null;
        }
    }

}

package cn.com.mx.gome.search.core.util.prop;

import java.net.URL;
import java.util.Properties;
/**
 * properties文件处理工具类
 * @author songqinghu
 *
 */
public class PropUtils extends Property {
    //配置文件名称
    private final static String _default = "config/config.properties";
    
    private PropUtils(){
        this(true);
    }

    public PropUtils(boolean isChange) {
        
        URL url = PropUtils.class.getResource("/");
        
        if(url != null){
            setDir(url.getPath());
        }
        setFilename(_default);
        setChange(isChange);
    }
    
    /**
     * 获取默认的自动加载配置文件工具类实例
     */
    public static PropUtils getInstance() {
        return Creater.changePropUtil;
    }

    /**
     * 获取静态的配置文件工具类实例,不自动加载
     */
    public static PropUtils getUnChangeInstance() {
        return Creater.unchangePropUtil;
    }
    
    private static class Creater{
        public static final PropUtils changePropUtil = new PropUtils();
        public static final PropUtils unchangePropUtil = new PropUtils(false);
    }
    
}

常量配置类
package cn.com.mx.gome.suggest.constant;

public final class Const {

    public static final String SOLR_ZK_URL = "solr.zk.url";
    public static final String SOLR_COLLECTIONS = "solr.collections";
    public static final String INDEX_FULL_LIMIT_GROUP = "index.full.limit.group";
    public static final String INDEX_FULL_LIMIT_USER = "index.full.limit.user";
    public static final String INDEX_FULL_LIMIT_TOPIC = "index.full.limit.topic";
    public static final String INDEZ_FULL_THREAD_MAX = "index.full.thread.max";//线程数大小
    /**
     * `expert_audit_status` tinyint(1) DEFAULT '0' COMMENT '达人审核状态
     * 0表示未审核,1表示审核中,2表示审核成功,3表示审核失败',
     */
    public static final String USER_STATUS_V = "2";
}

solr客户端初始化获取类
package cn.com.mx.gome.suggest.solr.init;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.SolrClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import cn.com.mx.gome.search.core.util.prop.PropUtils;
import cn.com.mx.gome.suggest.constant.Const;
import cn.com.mx.gome.suggest.solr.SolrServiceWrapper;
import cn.com.mx.gome.suggest.solr.connect.SolrClientConnect;
/**
 * solr连接客户端初始化类
 * @author songqinghu
 *
 */
@Service
public class SolrServiceWrapperImpl implements SolrServiceWrapper {

    private final Logger logger = LoggerFactory.getLogger(SolrServiceWrapperImpl.class);
    
    private static  Map<String,SolrClient> solrClients= new  ConcurrentHashMap<String, SolrClient>();
    

    @PostConstruct//类初始化后执行此方法
    @Override
    public Map<String, SolrClient> initSolrClient() {
        
        //获取zk地址
        String zkUrl = PropUtils.getInstance().get(Const.SOLR_ZK_URL);
        System.out.println(zkUrl);
        //获取collection名称 ,为切割符
        String[] collectionNames = PropUtils.getInstance().get(Const.SOLR_COLLECTIONS).split(",");

        //循环创建solr连接客户端存入map中
        for (String name : collectionNames) {
            solrClients.put(name, SolrClientConnect.getCloudSolrClient(zkUrl, name));
        }
        logger.info(collectionNames + " init,load solr client from zk = " + zkUrl);
        return solrClients;
    }

    //获取指定的collection连接
    @Override
    public SolrClient getCollection(String name) {
        SolrClient client = null;
        if(solrClients !=null && solrClients.size()>0){
            if(StringUtils.isNotBlank(name))
                client = solrClients.get(name);
        }
        if(client == null) //没有获取到连接
             throw  new RuntimeException("the solrClient init fail");
        return client;
    }

}

package cn.com.mx.gome.suggest.solr.connect;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;

import cn.com.mx.gome.search.core.common.ESystemDefaultHttpClient;

/**
 * 获取solr的客户端--集群连接 或者单机连接
 * @author songqinghu
 *
 */
public class SolrClientConnect {

    //获取集群 方式的solr连接 
    public static SolrClient  getCloudSolrClient(String zkUrl,String name){
        
        ESystemDefaultHttpClient httpClient = new ESystemDefaultHttpClient(200, 2000);
        
        CloudSolrClient cloudSolrClient = new  CloudSolrClient(zkUrl, httpClient);
        
        cloudSolrClient.setDefaultCollection(name);
        
        cloudSolrClient.connect();
        
        return cloudSolrClient;
    }
    //获取单机版 solr连接
    public static SolrClient getSolrClient(String baseUrl,String name){
        ESystemDefaultHttpClient client = new ESystemDefaultHttpClient(200, 2000);
        HttpSolrClient solrClient = new HttpSolrClient(baseUrl+"/"+name, client);
        return solrClient;
    }
    
    
}

5.编写测试controller使用maven启动项目 访问观察项目是否成功,不成功根据报错解决问题



6.solr的collection的配置文件设置

公司的solr现在使用的是solrcloud的方式  只需要配置schema.xml和solrcofig.xml文件就可以了

分析思考---本索引库主要是用于搜索建议使用的 字段不需要考虑分词的问题,主要涉及的字段有
suggestId: 唯一标识
word:原始输入词
all_py:全程拼音   多值
short_py:首字母拼音  多值
type: 索引来源类别 (商品,店铺,人名,圈子名....)
count: 词语出现次数
all_text: 原始次 拼音 短拼 复制字段  多值  默认搜索域
createTime: 创建时间
-----------------------------------

schema.xml

<?xml version="1.0" encoding="UTF-8" ?>

<schema name="meixin_group" version="1.5">


    <fieldType name="string" class="solr.StrField" sortMissingLast="true" />
    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" />
    <fieldType name="int" class="solr.TrieIntField" sortMissingLast="true" precisionStep="0" positionIncrementGap="0" />
    <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0" />
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0" />
    <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0" />
    <fieldType name="tint" class="solr.TrieIntField" sortMissingLast="true" precisionStep="8" positionIncrementGap="0" />
    <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0" />
    <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0" />
    <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0" />
    <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0" />
    <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0" />
    <fieldType name="random" class="solr.RandomSortField" indexed="true" />

    <fieldType name="mmseg_text" class="solr.TextField">
        <analyzer type="index">
            <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" dicPath="/usr/local/mmseg_dic" />
        </analyzer>
        <analyzer type="query">
            <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" dicPath="/usr/local/mmseg_dic" />
        </analyzer>
    </fieldType>

    <fieldtype name="ng1_1" class="solr.TextField" positionIncrementGap="100">
        <analyzer>
            <tokenizer class="solr.NGramTokenizerFactory" minGramSize="1" maxGramSize="1"/>
            <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
  </fieldtype>

    <field name="suggestId" type="string" indexed="true" stored="true" required="true" />
    <field name="word" type="string" indexed="true" stored="true" />
    <field name="all_py" type="string" indexed="true" stored="true" />
    <field name="short_py" type="string" indexed="true" stored="true" />
    <field name="type" type="string" indexed="true" stored="true" />
    <field name="count" type="long" indexed="true" stored="true" />
    <field name="suggest" type="string" indexed="true" stored="false" />

    <field name="_version_" type="long" indexed="true" stored="true" />

    <copyField source="word" dest="suggest"/> 
    <copyField source="all_py" dest="suggest"/>  
    <copyField source="short_py" dest="suggest"/> 

    <uniqueKey>suggestId</uniqueKey>
    <defaultSearchField>suggest</defaultSearchField>
    <solrQueryParser defaultOperator="AND" />
</schema>

solrcofig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!--
 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.
-->

<!-- 
     For more details about configurations options that may appear in
     this file, see http://wiki.apache.org/solr/SolrConfigXml. 
-->
<config>
  <!-- In all configuration below, a prefix of "solr." for class names
       is an alias that causes solr to search appropriate packages,
       including org.apache.solr.(search|update|request|core|analysis)

       You may also specify a fully qualified Java classname if you
       have your own custom plugins.
    -->

  <!-- Controls what version of Lucene various components of Solr
       adhere to.  Generally, you want to use the latest version to
       get all bug fixes and improvements. It is highly recommended
       that you fully re-index after changing this setting as it can
       affect both how text is indexed and queried.
  -->
  <luceneMatchVersion>5.3.1</luceneMatchVersion>

  <!-- Data Directory

       Used to specify an alternate directory to hold all index data
       other than the default ./data under the Solr home.  If
       replication is in use, this should match the replication
       configuration.
    -->
  <dataDir>${solr.data.dir:}</dataDir>


  <!-- The DirectoryFactory to use for indexes.

       solr.StandardDirectoryFactory is filesystem
       based and tries to pick the best implementation for the current
       JVM and platform.  solr.NRTCachingDirectoryFactory, the default,
       wraps solr.StandardDirectoryFactory and caches small files in memory
       for better NRT performance.

       One can force a particular implementation via solr.MMapDirectoryFactory,
       solr.NIOFSDirectoryFactory, or solr.SimpleFSDirectoryFactory.

       solr.RAMDirectoryFactory is memory based, not
       persistent, and doesn't work with replication.
    -->
  <directoryFactory name="DirectoryFactory" 
                    class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}">
  </directoryFactory> 

  <!-- The CodecFactory for defining the format of the inverted index.
       The default implementation is SchemaCodecFactory, which is the official Lucene
       index format, but hooks into the schema to provide per-field customization of
       the postings lists and per-document values in the fieldType element
       (postingsFormat/docValuesFormat). Note that most of the alternative implementations
       are experimental, so if you choose to customize the index format, it's a good
       idea to convert back to the official format e.g. via IndexWriter.addIndexes(IndexReader)
       before upgrading to a newer version to avoid unnecessary reindexing.
  -->
  <codecFactory class="solr.SchemaCodecFactory"/>

  <schemaFactory class="ClassicIndexSchemaFactory"/>

  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Index Config - These settings control low-level behavior of indexing
       Most example settings here show the default value, but are commented
       out, to more easily see where customizations have been made.

       Note: This replaces <indexDefaults> and <mainIndex> from older versions
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <indexConfig>

    <!-- LockFactory 

         This option specifies which Lucene LockFactory implementation
         to use.

         single = SingleInstanceLockFactory - suggested for a
                  read-only index or when there is no possibility of
                  another process trying to modify the index.
         native = NativeFSLockFactory - uses OS native file locking.
                  Do not use when multiple solr webapps in the same
                  JVM are attempting to share a single index.
         simple = SimpleFSLockFactory  - uses a plain file for locking

         Defaults: 'native' is default for Solr3.6 and later, otherwise
                   'simple' is the default

         More details on the nuances of each LockFactory...
         http://wiki.apache.org/lucene-java/AvailableLockFactories
    -->
    <lockType>${solr.lock.type:native}</lockType>

    <!-- Lucene Infostream

         To aid in advanced debugging, Lucene provides an "InfoStream"
         of detailed information when indexing.

         Setting the value to true will instruct the underlying Lucene
         IndexWriter to write its info stream to solr's log. By default,
         this is enabled here, and controlled through log4j.properties.
      -->
     <infoStream>true</infoStream>
  </indexConfig>


  <!-- JMX

       This example enables JMX if and only if an existing MBeanServer
       is found, use this if you want to configure JMX through JVM
       parameters. Remove this to disable exposing Solr configuration
       and statistics to JMX.

       For more details see http://wiki.apache.org/solr/SolrJmx
    -->
  <jmx />
  <!-- If you want to connect to a particular server, specify the
       agentId 
    -->
  <!-- <jmx agentId="myAgent" /> -->
  <!-- If you want to start a new MBeanServer, specify the serviceUrl -->
  <!-- <jmx serviceUrl="service:jmx:rmi:///jndi/rmi://localhost:9999/solr"/>
    -->

  <!-- The default high-performance update handler -->
  <updateHandler class="solr.DirectUpdateHandler2">

    <!-- Enables a transaction log, used for real-time get, durability, and
         and solr cloud replica recovery.  The log can grow as big as
         uncommitted changes to the index, so use of a hard autoCommit
         is recommended (see below).
         "dir" - the target directory for transaction logs, defaults to the
                solr data directory.
         "numVersionBuckets" - sets the number of buckets used to keep
                track of max version values when checking for re-ordered
                updates; increase this value to reduce the cost of
                synchronizing access to version buckets during high-volume
                indexing, this requires 8 bytes (long) * numVersionBuckets
                of heap space per Solr core.
    -->
    <updateLog>
      <str name="dir">${solr.ulog.dir:}</str>
      <int name="numVersionBuckets">${solr.ulog.numVersionBuckets:65536}</int>
    </updateLog>

    <!-- AutoCommit

         Perform a hard commit automatically under certain conditions.
         Instead of enabling autoCommit, consider using "commitWithin"
         when adding documents. 

         http://wiki.apache.org/solr/UpdateXmlMessages

         maxDocs - Maximum number of documents to add since the last
                   commit before automatically triggering a new commit.

         maxTime - Maximum amount of time in ms that is allowed to pass
                   since a document was added before automatically
                   triggering a new commit. 
         openSearcher - if false, the commit causes recent index changes
           to be flushed to stable storage, but does not cause a new
           searcher to be opened to make those changes visible.

         If the updateLog is enabled, then it's highly recommended to
         have some sort of hard autoCommit to limit the log size.
      -->
     <autoCommit> 
       <maxTime>${solr.autoCommit.maxTime:30000}</maxTime> 
       <openSearcher>false</openSearcher> 
     </autoCommit>

    <!-- softAutoCommit is like autoCommit except it causes a
         'soft' commit which only ensures that changes are visible
         but does not ensure that data is synced to disk.  This is
         faster and more near-realtime friendly than a hard commit.
      -->
     <autoSoftCommit> 
       <maxTime>${solr.autoSoftCommit.maxTime:1000}</maxTime> 
     </autoSoftCommit>

  </updateHandler>

  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Query section - these settings control query time things like caches
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <query>
    <!-- Max Boolean Clauses

         Maximum number of clauses in each BooleanQuery,  an exception
         is thrown if exceeded.

         ** WARNING **

         This option actually modifies a global Lucene property that
         will affect all SolrCores.  If multiple solrconfig.xml files
         disagree on this property, the value at any given moment will
         be based on the last SolrCore to be initialized.

      -->
    <maxBooleanClauses>1024</maxBooleanClauses>


    <!-- Solr Internal Query Caches

         There are two implementations of cache available for Solr,
         LRUCache, based on a synchronized LinkedHashMap, and
         FastLRUCache, based on a ConcurrentHashMap.  

         FastLRUCache has faster gets and slower puts in single
         threaded operation and thus is generally faster than LRUCache
         when the hit ratio of the cache is high (> 75%), and may be
         faster under other scenarios on multi-cpu systems.
    -->

    <!-- Filter Cache

         Cache used by SolrIndexSearcher for filters (DocSets),
         unordered sets of *all* documents that match a query.  When a
         new searcher is opened, its caches may be prepopulated or
         "autowarmed" using data from caches in the old searcher.
         autowarmCount is the number of items to prepopulate.  For
         LRUCache, the autowarmed items will be the most recently
         accessed items.

         Parameters:
           class - the SolrCache implementation LRUCache or
               (LRUCache or FastLRUCache)
           size - the maximum number of entries in the cache
           initialSize - the initial capacity (number of entries) of
               the cache.  (see java.util.HashMap)
           autowarmCount - the number of entries to prepopulate from
               and old cache.  
      -->
    <filterCache class="solr.FastLRUCache"
                 size="2048"
                 initialSize="512"
                 autowarmCount="1024"/>

    <!-- Query Result Cache

        Caches results of searches - ordered lists of document ids
        (DocList) based on a query, a sort, and the range of documents requested.
        Additional supported parameter by LRUCache:
           maxRamMB - the maximum amount of RAM (in MB) that this cache is allowed
                      to occupy
     -->
    <queryResultCache class="solr.LRUCache"
                     size="512"
                     initialSize="512"
                     autowarmCount="0"/>

    <!-- Document Cache

         Caches Lucene Document objects (the stored fields for each
         document).  Since Lucene internal document ids are transient,
         this cache will not be autowarmed.  
      -->
    <documentCache class="solr.LRUCache"
                   size="512"
                   initialSize="512"
                   autowarmCount="0"/>

    <!-- custom cache currently used by block join --> 
    <cache name="perSegFilter"
      class="solr.search.LRUCache"
      size="10"
      initialSize="0"
      autowarmCount="10"
      regenerator="solr.NoOpRegenerator" />

    <!-- Lazy Field Loading

         If true, stored fields that are not requested will be loaded
         lazily.  This can result in a significant speed improvement
         if the usual case is to not load all stored fields,
         especially if the skipped fields are large compressed text
         fields.
    -->
    <enableLazyFieldLoading>true</enableLazyFieldLoading>

   <!-- Result Window Size

        An optimization for use with the queryResultCache.  When a search
        is requested, a superset of the requested number of document ids
        are collected.  For example, if a search for a particular query
        requests matching documents 10 through 19, and queryWindowSize is 50,
        then documents 0 through 49 will be collected and cached.  Any further
        requests in that range can be satisfied via the cache.  
     -->
   <queryResultWindowSize>60</queryResultWindowSize>

   <!-- Maximum number of documents to cache for any entry in the
        queryResultCache. 
     -->
   <queryResultMaxDocsCached>200</queryResultMaxDocsCached>

    <!-- Use Cold Searcher

         If a search request comes in and there is no current
         registered searcher, then immediately register the still
         warming searcher and use it.  If "false" then all requests
         will block until the first searcher is done warming.
      -->
    <useColdSearcher>false</useColdSearcher>

    <!-- Max Warming Searchers

         Maximum number of searchers that may be warming in the
         background concurrently.  An error is returned if this limit
         is exceeded.

         Recommend values of 1-2 for read-only slaves, higher for
         masters w/o cache warming.
      -->
    <maxWarmingSearchers>2</maxWarmingSearchers>

  </query>


  <!-- Request Dispatcher

       This section contains instructions for how the SolrDispatchFilter
       should behave when processing requests for this SolrCore.

       handleSelect is a legacy option that affects the behavior of requests
       such as /select?qt=XXX

       handleSelect="true" will cause the SolrDispatchFilter to process
       the request and dispatch the query to a handler specified by the 
       "qt" param, assuming "/select" isn't already registered.

       handleSelect="false" will cause the SolrDispatchFilter to
       ignore "/select" requests, resulting in a 404 unless a handler
       is explicitly registered with the name "/select"

       handleSelect="true" is not recommended for new users, but is the default
       for backwards compatibility
    -->
  <requestDispatcher handleSelect="false" >
    <!-- Request Parsing

         These settings indicate how Solr Requests may be parsed, and
         what restrictions may be placed on the ContentStreams from
         those requests

         enableRemoteStreaming - enables use of the stream.file
         and stream.url parameters for specifying remote streams.

         multipartUploadLimitInKB - specifies the max size (in KiB) of
         Multipart File Uploads that Solr will allow in a Request.

         formdataUploadLimitInKB - specifies the max size (in KiB) of
         form data (application/x-www-form-urlencoded) sent via
         POST. You can use POST to pass request parameters not
         fitting into the URL.

         addHttpRequestToContext - if set to true, it will instruct
         the requestParsers to include the original HttpServletRequest
         object in the context map of the SolrQueryRequest under the 
         key "httpRequest". It will not be used by any of the existing
         Solr components, but may be useful when developing custom 
         plugins.

         *** WARNING ***
         The settings below authorize Solr to fetch remote files, You
         should make sure your system has some authentication before
         using enableRemoteStreaming="true"

      --> 
    <requestParsers enableRemoteStreaming="true" 
                    multipartUploadLimitInKB="2048000"
                    formdataUploadLimitInKB="2048"
                    addHttpRequestToContext="false"/>

    <!-- HTTP Caching

         Set HTTP caching related parameters (for proxy caches and clients).

         The options below instruct Solr not to output any HTTP Caching
         related headers
      -->
    <httpCaching never304="true" />

  </requestDispatcher>

  <!-- Request Handlers 

       http://wiki.apache.org/solr/SolrRequestHandler

       Incoming queries will be dispatched to a specific handler by name
       based on the path specified in the request.

       Legacy behavior: If the request path uses "/select" but no Request
       Handler has that name, and if handleSelect="true" has been specified in
       the requestDispatcher, then the Request Handler is dispatched based on
       the qt parameter.  Handlers without a leading '/' are accessed this way
       like so: http://host/app/[core/]select?qt=name  If no qt is
       given, then the requestHandler that declares default="true" will be
       used or the one named "standard".

       If a Request Handler is declared with startup="lazy", then it will
       not be initialized until the first request that uses it.

    -->
  <!-- SearchHandler

       http://wiki.apache.org/solr/SearchHandler

       For processing Search Queries, the primary Request Handler
       provided with Solr is "SearchHandler" It delegates to a sequent
       of SearchComponents (see below) and supports distributed
       queries across multiple shards
    -->
  <requestHandler name="/select" class="solr.SearchHandler">
    <!-- default values for query parameters can be specified, these
         will be overridden by parameters in the request
      -->
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <int name="rows">10</int>
     </lst>

    </requestHandler>

  <!-- A request handler that returns indented JSON by default -->
  <requestHandler name="/query" class="solr.SearchHandler">
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <str name="wt">xml</str>
       <str name="indent">true</str>
       <!-- 
        <str name="df">text</str>
        -->
     </lst>
  </requestHandler>

  <!--
    The export request handler is used to export full sorted result sets.
    Do not change these defaults.
  -->
  <requestHandler name="/export" class="solr.SearchHandler">
    <lst name="invariants">
      <str name="rq">{!xport}</str>
      <str name="wt">xsort</str>
      <str name="distrib">false</str>
    </lst>

    <arr name="components">
      <str>query</str>
    </arr>
  </requestHandler>


  <initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell">
    <lst name="defaults">
      <str name="df">groupName</str>
    </lst>
  </initParams>

  <!-- Field Analysis Request Handler

       RequestHandler that provides much the same functionality as
       analysis.jsp. Provides the ability to specify multiple field
       types and field names in the same request and outputs
       index-time and query-time analysis for each of them.

       Request parameters are:
       analysis.fieldname - field name whose analyzers are to be used

       analysis.fieldtype - field type whose analyzers are to be used
       analysis.fieldvalue - text for index-time analysis
       q (or analysis.q) - text for query time analysis
       analysis.showmatch (true|false) - When set to true and when
           query analysis is performed, the produced tokens of the
           field value analysis will be marked as "matched" for every
           token that is produces by the query analysis
   -->
  <requestHandler name="/analysis/field" 
                  startup="lazy"
                  class="solr.FieldAnalysisRequestHandler" />


  <!-- Document Analysis Handler

       http://wiki.apache.org/solr/AnalysisRequestHandler

       An analysis handler that provides a breakdown of the analysis
       process of provided documents. This handler expects a (single)
       content stream with the following format:

       <docs>
         <doc>
           <field name="id">1</field>
           <field name="name">The Name</field>
           <field name="text">The Text Value</field>
         </doc>
         <doc>...</doc>
         <doc>...</doc>
         ...
       </docs>

    Note: Each document must contain a field which serves as the
    unique key. This key is used in the returned response to associate
    an analysis breakdown to the analyzed document.

    Like the FieldAnalysisRequestHandler, this handler also supports
    query analysis by sending either an "analysis.query" or "q"
    request parameter that holds the query text to be analyzed. It
    also supports the "analysis.showmatch" parameter which when set to
    true, all field tokens that match the query tokens will be marked
    as a "match". 
  -->
  <requestHandler name="/analysis/document" 
                  class="solr.DocumentAnalysisRequestHandler" 
                  startup="lazy" />

  <!-- Echo the request contents back to the client -->
  <requestHandler name="/debug/dump" class="solr.DumpRequestHandler" >
    <lst name="defaults">
     <str name="echoParams">explicit</str> 
     <str name="echoHandler">true</str>
    </lst>
  </requestHandler>



  <!-- Search Components

       Search components are registered to SolrCore and used by 
       instances of SearchHandler (which can access them by name)

       By default, the following components are available:

       <searchComponent name="query"     class="solr.QueryComponent" />
       <searchComponent name="facet"     class="solr.FacetComponent" />
       <searchComponent name="mlt"       class="solr.MoreLikeThisComponent" />
       <searchComponent name="highlight" class="solr.HighlightComponent" />
       <searchComponent name="stats"     class="solr.StatsComponent" />
       <searchComponent name="debug"     class="solr.DebugComponent" />

     -->

  <!-- Terms Component

       http://wiki.apache.org/solr/TermsComponent

       A component to return terms and document frequency of those
       terms
    -->
  <searchComponent name="terms" class="solr.TermsComponent"/>

  <!-- A request handler for demonstrating the terms component -->
  <requestHandler name="/terms" class="solr.SearchHandler" startup="lazy">
     <lst name="defaults">
      <bool name="terms">true</bool>
      <bool name="distrib">false</bool>
    </lst>     
    <arr name="components">
      <str>terms</str>
    </arr>
  </requestHandler>

  <!-- Legacy config for the admin interface -->
  <admin>
    <defaultQuery>*:*</defaultQuery>
  </admin>

</config>







Logo

开源、云原生的融合云平台

更多推荐