solr-chapter1--solr環境部署,數據源配置,簡單使用

資源鏈接:

W3CSchool--https://www.w3cschool.cn/solr_doc/solr_doc-1r4g2flx.html

ApacheSolr--http://www.apache.org/dyn/closer.lua/lucene/solr/7.2.1

SolrWiki--https://wiki.apache.org/solr/Support

一、linux服務器配置java、tomcat環境,ApacheSolr鏈接中下載solr解壓部署。

 Solr 查詢是簡單的 HTTP 請求 URL,就像部署一個web項目似的。

一、	安裝tomcat
1、	下載解壓apache-tomcat-8.5.20.tar,更改文件名爲tomcat-solr,
2、	配置修改(一臺服務器上只有一個)
修改server.xml
<Server port="18983" shutdown="SHUTDOWN">

<Connector port="8983" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8938" protocol="AJP/1.3" redirectPort="8443" />

在Host節點中加入
<Context path="solr" docBase="/usr/web/solr" debug="0" reloadable="true"/>
注:path="solr"必須,不得爲空或其它值,因爲solr開發者定死路徑solr,訪問路徑中也必須有solr

Vi  /etc/profile
加入  
 CATALINA_BASE0=/usr/java/tomcat-solr
CATALINA_HOME0=/usr/java/tomcat-solr
CATALINA_TMPDIR0=/usr/java/tomcat-solr/temp
export CATALINA_BASE0 CATALINA_HOME0 CATALINA_TMPDIR0


tomcat-solr>catalina.sh中修改
CATALINA_BASE替換爲CATALINA_BASE0
  CATALINA_HOME替換爲CATALINA_HOME0
CATALINA_TMPDIR替換爲CATALINA_ TMPDIR0


二、	安裝solr(solr相當於一個java web項目)
1、	本地電腦下載解壓solr-7.1.0
2、	本地solr 壓縮包中 solr\server\solr-webapp\文件夾下有個webapp文件夾,將之複製到服務器目錄/usr/web 下,文件夾名改成solr。

將 solr 壓縮包中 solr\server\lib\ext 中的 jar 和solr壓縮包中solr/server/lib/metrics* 開頭的jar全部複製到/usr/web/solr/WEB-INF/lib 目錄中

3、	在/usr/web/solr/WEB-INF/下建立classes目錄,並將solr/server/resources/log4j.properties文件複製其中;
4、	在/usr/web目錄下建立solrhome文件夾,複製solr/server/solr/* 所有文件到solrhome目錄
5、	編輯 web.xml
配置solr下core路徑,找如下配置內容(初始狀態下該內容是被註釋掉的):
    <env-entry>
       <env-entry-name>solr/home</env-entry-name>
       <env-entry-value>/usr/web/solrhome</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

配置訪問權限:找到如下內容,並註釋掉:
  <!-- Get rid of error message 
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Disable TRACE</web-resource-name>
      <url-pattern>/</url-pattern>
      <http-method>TRACE</http-method>
    </web-resource-collection>
    <auth-constraint/>
  </security-constraint>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Enable everything but TRACE</web-resource-name>
      <url-pattern>/</url-pattern>
      <http-method-omission>TRACE</http-method-omission>
    </web-resource-collection>
  </security-constraint>
  -->
6、重啓tomcat,運行http://www.aurorascm.cn:8983/solr/index.html


三、	solr和mysql整合
1、	下載mysql驅動jar包mysql-connector-java-5.1.44-bin.jar (或者北極光項目依賴文件中直接配置) ,上傳到/usr/web/solr/WEB-INF/lib 目錄中
2、	把solr-7.1.0\dist目錄下的jar包複製一份到/usr/web/solr/WEB-INF/lib,重複的替換,
重要的是solr-dataimporthandler-7.1.0和solr-dataimporthandler-extras-7.1.0
3、	在solrhome中新建文件夾goods-core,然後將C:\Users\loiikfb\Desktop\北極光\linux服務器\solr\solr-7.1.0\example\example-DIH\solr\solr下的所有文件copy到goods-core。(數據源可配置多個,只要查詢時solrUrl = http://47.254.131.164:8983/solr/goods-core中換成對應文件名稱即可)
4、/usr/web/solrhome/goods-core/conf目錄下solrconfig中添加
<!-- new add 888  -->
  <lib dir="/usr/web/solr/WEB-INF/lib/" regex=".*\.jar" />
4、	配置/usr/web/solrhome/goods-core/conf中solr-data-config文件,數據庫字段必須爲大寫,否則數據導入或查詢結果只有id和version。
 

5、配置字段(數據庫字段),添加後會自動添加到/usr/web/solrhome/goods-core/conf目錄下managed-schema文件中
 

四,中文分詞器、拼音配置
下載ikanalyzer-solr5和ikanalyzer-solr5
加壓後:ik-analyzer-solr5-5.x / solr-analyzer-ik-5.1.0 / pinyin4j-2.5.0 / pinyinAnalyzer4.3.1複製到/usr/web/solr/WEB-INF/lib目錄下。Ext  / IKAnalyzer.cfg / stopword 複製到/usr/web/solr/WEB-INF/classes目錄下

配置/usr/web/solrhome/goods-core/conf目錄下managed-schema 文件,新加
 
注:UseSmart應設爲false這樣分詞粒度更小

五,Solr月spring的整合及應用
六、定時增量更新和重建索引。(參考鏈接http://blog.csdn.net/u010942465/article/details/51347923)(可惜沒成功,只能在代碼中數據變更時隨時增刪,solr web中手動全部更新或者增量更新)
1、修改/usr/web/solr/WEB-INF中web.xml,在servlet節點前面增加: 2、將apache-solr-dataimportscheduler-.jar (dihs)放入/usr/web/solr/WEB-INF/lib
3、將apache-solr-dataimportscheduler-.jar 中 dataimport.properties 取出並根據實際情況修改,然後放到 solrhome/conf (不是solr.home/core/conf) 目錄下面 
dataimport.properties配置項說明:
# dataimport.properties example
#
# From this example, copy everything bellow "dataimport scheduler properties" to your
#   dataimport.properties file and then change params to fit your needs
#
# IMPORTANT:
# Regardless of whether you have single or multiple-core Solr,
#   use dataimport.properties located in your solr.home/conf (NOT solr.home/core/conf)
# For more info and context see here:
# http://wiki.apache.org/solr/DataImportHandler#dataimport.properties_example


#Tue Jul 21 12:10:50 CEST 2010
#metadataObject.last_index_time=2010-09-20 11\:12\:47
#last_index_time=2010-09-20 11\:12\:47


#################################################
#                                               #
#       dataimport scheduler properties         #
#                                               #
#################################################

#  to sync or not to sync
#  1 - active; anything else - inactive
syncEnabled=1

#  which cores to schedule
#  in a multi-core environment you can decide which cores you want syncronized
#  leave empty or comment it out if using single-core deployment
syncCores=goods_core

#  solr server name or IP address
#  [defaults to localhost if empty]
server=120.27.217.255

#  solr server port
#  [defaults to 80 if empty]
port=8983

#  application name/context
#  [defaults to current ServletContextListener's context (app) name]
webapp=solr

#  URL params [mandatory]
#  remainder of URL
params=/select?qt=/dataimport&command=delta-import&clean=false&commit=true

#  schedule interval
#  number of minutes between two runs
#  [defaults to 30 if empty]
interval=10

#  重做索引的時間間隔,單位分鐘,默認7200,即5天;   
#  爲空,爲0,或者註釋掉:表示永不重做索引  
reBuildIndexInterval=1440  
   
#  重做索引的參數  
reBuildIndexParams=/select?qt=/dataimport&command=full-import&clean=true&commit=true  
   
#  重做索引時間間隔的計時開始時間,第一次真正執行的時間=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;  
#  兩種格式:2012-04-11 03:10:00 或者  03:10:00,後一種會自動補全日期部分爲服務啓動時的日期  
reBuildIndexBeginTime=03:00:00
二、幾個配置文件的代碼

1、solr-data-config.xml 

<field column="GOODS_ID" name="goodsID" />column爲數據庫字段大寫(注意大寫不然很坑人的),name爲java代碼中字段名。


<!--
  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.
  -->


<dataConfig>
  <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://0.0.0.0:3306/dbname" user="root" password="mysql" />
  <document>
    <entity name="goods_solr"
		query="select * from goods_solr "
		deltaImportQuery="select * from goods_solr where id='${dih.delta.id}'"
		deltaQuery="select id from goods_solr where update_time > '${dataimporter.last_index_time}' ">
		<field column="GOODS_ID" name="goodsID" />
		<field column="GOODS_CODE" name="goodsCode" />
		<field column="GOODS_NAME" name="goodsName" />
		<field column="GOODS_DESCRIBE" name="goodsDescribe" />
		<field column="BRAND_ID" name="brandID" />
		<field column="BRAND_CNAME" name="brandCname" />
		<field column="BRAND_ENAME" name="brandEname" />
		<field column="TRADE_TYPE" name="tradeType" />
		<field column="TRADE_TYPE_NAME" name="tradeTypeName" />
		<field column="POSTAGE_STYLE" name="postageStyle" />
		<field column="POSTAGE_STYLE_NAME" name="postageStyleName" />
		<field column="DEPOSIT" name="deposit" />
		<field column="DEPOSIT_NAME" name="depositName" />
		<field column="PRODUCT_AREA" name="productArea" />
		<field column="CATEGORY1_NAME" name="category1Name" />
		<field column="CATEGORY2_ID" name="category2ID" />
		<field column="CATEGORY2_NAME" name="category2Name" />
		<field column="CATEGORY3_NAME" name="category3Name" />
		<field column="KEYWORD1" name="keyword1" />
		<field column="KEYWORD2" name="keyword2" />
		<field column="KEYWORD3" name="keyword3" />
		<field column="KEYWORD4" name="keyword4" />
		<field column="KEYWORD5" name="keyword5" />
		<field column="PROPERTY" name="property" />
		<field column="MAIN_MAP" name="mainMap" />
		<field column="FAKE_STOCK" name="fakeStock" />
		<field column="GOODS_PRICE2" name="goodsPrice2" />
		<field column="MARKET_PRICE" name="marketPrice" />
		<field column="GOODS_SALES" name="goodsSales" />
		<field column="CURRENCY_UNIT" name="currencyUnit" />
		<field column="UP_TIME" name="uptime" />
		<field column="UPDATE_TIME" name="updateTime" />	
    </entity>         
  </document>
</dataConfig>
2、managed-schema.xml

組要是fieldType和field的配置。其中有些是solr中的示例代碼可以刪。刪要刪全套,不然易出錯。

<?xml version="1.0" encoding="UTF-8"?>
<!-- Solr managed schema - automatically generated - DO NOT EDIT -->
<schema name="example-DIH-solr" version="1.5">
  <uniqueKey>id</uniqueKey>
  <fieldType name="alphaOnlySort" class="solr.TextField" omitNorms="true" sortMissingLast="true">
    <analyzer>
      <tokenizer class="solr.KeywordTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.TrimFilterFactory"/>
      <filter class="solr.PatternReplaceFilterFactory" pattern="([^a-z])" replace="all" replacement=""/>
    </analyzer>
  </fieldType>
  <fieldType name="ancestor_path" class="solr.TextField">
    <analyzer type="index">
      <tokenizer class="solr.KeywordTokenizerFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/"/>
    </analyzer>
  </fieldType>
  <fieldType name="binary" class="solr.BinaryField"/>
  <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
  <fieldType name="currency" class="solr.CurrencyFieldType" currencyConfig="currency.xml" amountLongSuffix="_l_ns" codeStrSuffix="_s_ns" defaultCurrency="USD"/>
  <fieldType name="descendent_path" class="solr.TextField">
    <analyzer type="index">
      <tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.KeywordTokenizerFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="ignored" class="solr.StrField" indexed="false" stored="false" multiValued="true"/>
  <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
  <fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType" geo="true" maxDistErr="0.001" distErrPct="0.025" distanceUnits="kilometers"/>
  <fieldType name="lowercase" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.KeywordTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="payloads" class="solr.TextField" indexed="true" stored="false">
    <analyzer>
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.DelimitedPayloadTokenFilterFactory" encoder="float"/>
    </analyzer>
  </fieldType>
  <fieldType name="pdate" class="solr.DatePointField" docValues="true"/>
  <fieldType name="pdates" class="solr.DatePointField" docValues="true" multiValued="true"/>
  <fieldType name="pdouble" class="solr.DoublePointField" docValues="true"/>
  <fieldType name="pdoubles" class="solr.DoublePointField" docValues="true" multiValued="true"/>
  <fieldType name="pfloat" class="solr.FloatPointField" docValues="true"/>
  <fieldType name="pfloats" class="solr.FloatPointField" docValues="true" multiValued="true"/>
  <fieldType name="phonetic" class="solr.TextField" indexed="true" stored="false">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.DoubleMetaphoneFilterFactory" inject="false"/>
    </analyzer>
  </fieldType>
  <fieldType name="pint" class="solr.IntPointField" docValues="true"/>
  <fieldType name="pints" class="solr.IntPointField" docValues="true" multiValued="true"/>
  <fieldType name="plong" class="solr.LongPointField" docValues="true"/>
  <fieldType name="plongs" class="solr.LongPointField" docValues="true" multiValued="true"/>
  <fieldType name="point" class="solr.PointType" subFieldSuffix="_d" dimension="2"/>
  <fieldType name="random" class="solr.RandomSortField" indexed="true"/>
  <fieldType name="solr_participle" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
  <fieldType name="text_ar" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_ar.txt" ignoreCase="true"/>
      <filter class="solr.ArabicNormalizationFilterFactory"/>
      <filter class="solr.ArabicStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_bg" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_bg.txt" ignoreCase="true"/>
      <filter class="solr.BulgarianStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_ca" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.ElisionFilterFactory" articles="lang/contractions_ca.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_ca.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Catalan"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_cjk" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.CJKWidthFilterFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.CJKBigramFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_ckb" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.SoraniNormalizationFilterFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_ckb.txt" ignoreCase="true"/>
      <filter class="solr.SoraniStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_cz" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_cz.txt" ignoreCase="true"/>
      <filter class="solr.CzechStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_da" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_da.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Danish"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_de" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_de.txt" ignoreCase="true"/>
      <filter class="solr.GermanNormalizationFilterFactory"/>
      <filter class="solr.GermanLightStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_el" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.GreekLowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_el.txt" ignoreCase="false"/>
      <filter class="solr.GreekStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.EnglishPossessiveFilterFactory"/>
      <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
      <filter class="solr.PorterStemFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.SynonymGraphFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.EnglishPossessiveFilterFactory"/>
      <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
      <filter class="solr.PorterStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_en_splitting" class="solr.TextField" autoGeneratePhraseQueries="true" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/>
      <filter class="solr.WordDelimiterGraphFilterFactory" catenateNumbers="1" generateNumberParts="1" splitOnCaseChange="1" generateWordParts="1" catenateAll="0" catenateWords="1"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
      <filter class="solr.PorterStemFilterFactory"/>
      <filter class="solr.FlattenGraphFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.SynonymGraphFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/>
      <filter class="solr.WordDelimiterGraphFilterFactory" catenateNumbers="0" generateNumberParts="1" splitOnCaseChange="1" generateWordParts="1" catenateAll="0" catenateWords="0"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
      <filter class="solr.PorterStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_en_splitting_tight" class="solr.TextField" autoGeneratePhraseQueries="true" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.SynonymGraphFilterFactory" expand="false" ignoreCase="true" synonyms="synonyms.txt"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/>
      <filter class="solr.WordDelimiterGraphFilterFactory" catenateNumbers="1" generateNumberParts="0" generateWordParts="0" catenateAll="0" catenateWords="1"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
      <filter class="solr.EnglishMinimalStemFilterFactory"/>
      <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      <filter class="solr.FlattenGraphFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.SynonymGraphFilterFactory" expand="false" ignoreCase="true" synonyms="synonyms.txt"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/>
      <filter class="solr.WordDelimiterGraphFilterFactory" catenateNumbers="1" generateNumberParts="0" generateWordParts="0" catenateAll="0" catenateWords="1"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
      <filter class="solr.EnglishMinimalStemFilterFactory"/>
      <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_es" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_es.txt" ignoreCase="true"/>
      <filter class="solr.SpanishLightStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_eu" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_eu.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Basque"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_fa" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <charFilter class="solr.PersianCharFilterFactory"/>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.ArabicNormalizationFilterFactory"/>
      <filter class="solr.PersianNormalizationFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_fa.txt" ignoreCase="true"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_fi" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_fi.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Finnish"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_fr" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.ElisionFilterFactory" articles="lang/contractions_fr.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_fr.txt" ignoreCase="true"/>
      <filter class="solr.FrenchLightStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_ga" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.ElisionFilterFactory" articles="lang/contractions_ga.txt" ignoreCase="true"/>
      <filter class="solr.StopFilterFactory" words="lang/hyphenations_ga.txt" ignoreCase="true"/>
      <filter class="solr.IrishLowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_ga.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Irish"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
      <filter class="solr.SynonymGraphFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_general_rev" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.ReversedWildcardFilterFactory" maxPosQuestion="2" maxFractionAsterisk="0.33" maxPosAsterisk="3" withOriginal="true"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.SynonymGraphFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
      <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_gl" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_gl.txt" ignoreCase="true"/>
      <filter class="solr.GalicianStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_hi" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.IndicNormalizationFilterFactory"/>
      <filter class="solr.HindiNormalizationFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_hi.txt" ignoreCase="true"/>
      <filter class="solr.HindiStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_hu" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_hu.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Hungarian"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_hy" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_hy.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Armenian"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_id" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_id.txt" ignoreCase="true"/>
      <filter class="solr.IndonesianStemFilterFactory" stemDerivational="true"/>
    </analyzer>
  </fieldType>
  <!-- new add 888 for:participle-->
  <fieldType name="text_ik" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="false">
    <analyzer type="index">
      <tokenizer class="org.apache.lucene.analysis.ik.IKTokenizerFactory" useSmart="false"/>
	  <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="org.apache.lucene.analysis.ik.IKTokenizerFactory" useSmart="true"/>
	  <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>
  <!-- new add 888 for:participle-->
  <fieldType name="suggest" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.KeywordTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.KeywordTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_it" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.ElisionFilterFactory" articles="lang/contractions_it.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_it.txt" ignoreCase="true"/>
      <filter class="solr.ItalianLightStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_ja" class="solr.TextField" autoGeneratePhraseQueries="false" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.JapaneseTokenizerFactory" mode="search"/>
      <filter class="solr.JapaneseBaseFormFilterFactory"/>
      <filter class="solr.JapanesePartOfSpeechStopFilterFactory" tags="lang/stoptags_ja.txt"/>
      <filter class="solr.CJKWidthFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_ja.txt" ignoreCase="true"/>
      <filter class="solr.JapaneseKatakanaStemFilterFactory" minimumLength="4"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_lv" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_lv.txt" ignoreCase="true"/>
      <filter class="solr.LatvianStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_nl" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_nl.txt" ignoreCase="true"/>
      <filter class="solr.StemmerOverrideFilterFactory" dictionary="lang/stemdict_nl.txt" ignoreCase="false"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Dutch"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_no" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_no.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Norwegian"/>
    </analyzer>
  </fieldType>
  
  <!-- 888 new add for: participle-->
  <fieldType name="text_pinyin" class="solr.TextField" positionIncrementGap="0">
    <analyzer type="index">
      <tokenizer class="org.apache.lucene.analysis.ik.IKTokenizerFactory"/>
      <filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" minTermLenght="2"/>
      <filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" maxGram="20" minGram="1"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="org.apache.lucene.analysis.ik.IKTokenizerFactory"/>
      <filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" minTermLenght="2"/>
      <filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" maxGram="20" minGram="1"/>
    </analyzer>
  </fieldType>
  <!-- 888 new add for: spell auto-complete Word -->
  <fieldType name="word_auto" class="solr.TextField">
	<analyzer type="index">
		<tokenizer class="solr.StandardTokenizerFactory"/>
		<filter class="solr.LowerCaseFilterFactory"/>
	</analyzer>
	<analyzer type="query">
		<tokenizer class="solr.StandardTokenizerFactory"/>
		<filter class="solr.LowerCaseFilterFactory"/>
	</analyzer>
  </fieldType> 
  <!-- 888 new add for: spell auto-complete phrase-->
  <fieldType name="phrase_auto" class="solr.TextField">
	<analyzer>  
		<tokenizer class="solr.KeywordTokenizerFactory"/>  
		<filter class="solr.LowerCaseFilterFactory"/>  
	</analyzer> 
  </fieldType> 
  <fieldType name="text_pt" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_pt.txt" ignoreCase="true"/>
      <filter class="solr.PortugueseLightStemFilterFactory"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_ro" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_ro.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Romanian"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_ru" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_ru.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Russian"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_sv" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_sv.txt" ignoreCase="true"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Swedish"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_th" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.ThaiTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_th.txt" ignoreCase="true"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_tr" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.ApostropheFilterFactory"/>
      <filter class="solr.TurkishLowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_tr.txt" ignoreCase="false"/>
      <filter class="solr.SnowballPorterFilterFactory" language="Turkish"/>
    </analyzer>
  </fieldType>
  <fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    </analyzer>
  </fieldType>
  <field name="_root_" type="string" indexed="true" stored="false"/>
  <field name="_version_" type="plong" indexed="true" stored="true"/>
  <field name="author" type="text_general" indexed="true" stored="true"/>
  <field name="cat" type="string" multiValued="true" indexed="true" stored="true"/>
  <field name="category" type="text_general" indexed="true" stored="true"/>
  <field name="comments" type="text_general" indexed="true" stored="true"/>
  <field name="content" type="text_general" multiValued="true" indexed="false" stored="true"/>
  <field name="content_type" type="string" multiValued="true" indexed="true" stored="true"/>
  <field name="description" type="text_general" indexed="true" stored="true"/>
  <field name="features" type="text_general" multiValued="true" indexed="true" stored="true"/>
  
  <field name="id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="goods_id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="goods_code" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="goods_name" type="text_ik" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="goods_describe" type="text_ik" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="brand_id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="brand_cname" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="brand_ename" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="trade_type" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="trade_type_name" type="text_ik" multiValued="false" indexed="true" required="false" stored="true"/>
  <field name="postage_style" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="postage_style_name" type="string" multiValued="false" indexed="true" required="false" stored="true"/>
  <field name="deposit" type="string" multiValued="false" indexed="false" required="true" stored="true"/>
  <field name="deposit_name" type="string" multiValued="false" indexed="true" required="false" stored="true"/>
  <field name="product_area" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="category1_name" type="text_ik" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="category2_id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="category2_name" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="category3_name" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="keyword1" type="text_ik" multiValued="false" indexed="true" required="false" stored="true"/>
  <field name="keyword2" type="text_ik" multiValued="false" indexed="true" required="false" stored="true"/>
  <field name="keyword3" type="text_ik" multiValued="false" indexed="true" required="false" stored="true"/>
  <field name="keyword4" type="text_ik" multiValued="false" indexed="true" required="false" stored="true"/>  
  <field name="keyword5" type="text_ik" multiValued="false" indexed="true" required="false" stored="true"/>
  <field name="property" type="text_ik" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="main_map" type="string" multiValued="false" indexed="false" required="true" stored="true"/>
  <field name="fake_stock" type="string" multiValued="false" indexed="false" required="true" stored="true"/>
  <field name="goods_price2" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="market_price" type="string" multiValued="false" indexed="false" required="true" stored="true"/>
  <field name="goods_sales" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="currency_unit" type="string" multiValued="false" indexed="false" required="true" stored="true"/>
  <field name="up_time" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="update_time" type="string" multiValued="false" indexed="false" required="true" stored="true" />
  
  <field name="auto_spell" type="text_ik" multiValued="true" indexed="true" required="false" stored="true" termVectors="true"/>
  <copyField source="goods_name" dest="auto_spell"/>
  <copyField source="brand_cname" dest="propertys"/>
  <copyField source="brand_ename" dest="propertys"/>
  <copyField source="trade_type_name" dest="propertys"/>
  <copyField source="postage_style_name" dest="propertys"/>
  <copyField source="deposit_name" dest="propertys"/>
  <copyField source="product_area" dest="propertys"/>
  <copyField source="category1_name" dest="propertys"/>
  <copyField source="category2_name" dest="propertys"/>
  <copyField source="category3_name" dest="propertys"/>
  <copyField source="keyword1" dest="propertys"/>
  <copyField source="keyword2" dest="propertys"/>
  <copyField source="keyword3" dest="propertys"/>
  <copyField source="keyword4" dest="propertys"/>
  <copyField source="keyword5" dest="propertys"/>

  
  <field name="propertys" type="text_ik" multiValued="true" indexed="true" required="false" stored="false" termVectors="true"/>
  <copyField source="goods_name" dest="propertys"/>
  <copyField source="goods_describe" dest="propertys"/>
  <copyField source="brand_cname" dest="propertys"/>
  <copyField source="brand_ename" dest="propertys"/>
  <copyField source="trade_type_name" dest="propertys"/>
  <copyField source="postage_style_name" dest="propertys"/>
  <copyField source="deposit_name" dest="propertys"/>
  <copyField source="product_area" dest="propertys"/>
  <copyField source="category1_name" dest="propertys"/>
  <copyField source="category2_name" dest="propertys"/>
  <copyField source="category3_name" dest="propertys"/>
  <copyField source="keyword1" dest="propertys"/>
  <copyField source="keyword2" dest="propertys"/>
  <copyField source="keyword3" dest="propertys"/>
  <copyField source="keyword4" dest="propertys"/>
  <copyField source="keyword5" dest="propertys"/>
  <copyField source="property" dest="propertys"/>
  
  <field name="inStock" type="boolean" indexed="true" stored="true"/>
  <field name="includes" type="text_general" termPositions="true" termVectors="true" indexed="true" termOffsets="true" stored="true"/>
  <field name="keywords" type="text_general" indexed="true" stored="true"/>
  <field name="last_modified" type="pdate" indexed="true" stored="true"/>
  <field name="links" type="string" multiValued="true" indexed="true" stored="true"/>
  <field name="manu" type="text_general" omitNorms="true" indexed="true" stored="true"/>
  <field name="manu_exact" type="string" indexed="true" stored="false"/>
  <field name="name" type="text_general" indexed="true" stored="true"/>
  <field name="payloads" type="payloads" indexed="true" stored="true"/>
  <field name="popularity" type="pint" indexed="true" stored="true"/>
  <field name="price" type="pfloat" indexed="true" stored="true"/>
  <field name="resourcename" type="text_general" indexed="true" stored="true"/>
  <field name="sku" type="text_en_splitting_tight" omitNorms="true" indexed="true" stored="true"/>
  <field name="store" type="location" indexed="true" stored="true"/>
  <field name="subject" type="text_general" indexed="true" stored="true"/>
  <field name="text" type="text_general" multiValued="true" indexed="true" stored="false"/>
  <field name="text_rev" type="text_general_rev" multiValued="true" indexed="true" stored="false"/>
  <field name="title" type="text_general" multiValued="true" indexed="true" stored="true"/>
  <field name="url" type="text_general" indexed="true" stored="true"/>
  <field name="weight" type="pfloat" indexed="true" stored="true"/>
  <dynamicField name="*_coordinate" type="pdouble" indexed="true" stored="false"/>
  <dynamicField name="ignored_*" type="ignored" multiValued="true"/>
  <dynamicField name="random_*" type="random"/>
  <dynamicField name="*_s_ns" type="string" indexed="true" stored="false"/>
  <dynamicField name="*_l_ns" type="plong" indexed="true" stored="false"/>
  <dynamicField name="attr_*" type="text_general" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_txt" type="text_general" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_dts" type="pdate" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_is" type="pint" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_ss" type="string" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_ls" type="plong" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_en" type="text_en" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_bs" type="boolean" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_fs" type="pfloat" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_ds" type="pdouble" multiValued="true" indexed="true" stored="true"/>
  <dynamicField name="*_dt" type="pdate" indexed="true" stored="true"/>
  <dynamicField name="*_i" type="pint" indexed="true" stored="true"/>
  <dynamicField name="*_s" type="string" indexed="true" stored="true"/>
  <dynamicField name="*_l" type="plong" indexed="true" stored="true"/>
  <dynamicField name="*_t" type="text_general" indexed="true" stored="true"/>
  <dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>
  <dynamicField name="*_f" type="pfloat" indexed="true" stored="true"/>
  <dynamicField name="*_d" type="pdouble" indexed="true" stored="true"/>
  <dynamicField name="*_p" type="location" indexed="true" stored="true"/>
  <dynamicField name="*_c" type="currency" indexed="true" stored="true"/>
  <copyField source="author" dest="text"/>
  <copyField source="cat" dest="text"/>
  <copyField source="content" dest="text"/>
  <copyField source="content_type" dest="text"/>
  <copyField source="description" dest="text"/>
  <copyField source="features" dest="text"/>
  <copyField source="includes" dest="text"/>
  <copyField source="keywords" dest="text"/>
  <copyField source="manu" dest="manu_exact"/>
  <copyField source="manu" dest="text"/>
  <copyField source="name" dest="text"/>
  <copyField source="resourcename" dest="text"/>
  <copyField source="title" dest="text"/>
  <copyField source="url" dest="text"/>
  <copyField source="price" dest="price_c"/>
  <copyField source="author" dest="author_s"/>
</schema>
3、solrconfig.xml中使用solr拼寫檢查,建議時會更改裏面一些配置。

4、java調用代碼

package com.aurorascm.solr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrQuery.ORDER;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.FacetField;
import org.apache.solr.client.solrj.response.FacetField.Count;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.SpellCheckResponse;
import org.apache.solr.client.solrj.response.SpellCheckResponse.Suggestion;
import org.apache.solr.common.SolrDocumentList;
import org.junit.Test;
import org.springframework.stereotype.Repository;

import com.aurorascm.entity.GoodsSolr;
import com.aurorascm.util.PageData;
import com.aurorascm.util.Tools;

/** solr 搜索引擎
 * @author BYG 2017-12-12
 * @version 1.0
 */
@Repository("solrUtil")
public class SolrUtil {

	private final String solrUrl = "http://47.254.131.164:8983/solr/goods-core";
	//創建solrClient同時指定超時時間,不指定走默認配置
	private HttpSolrClient getsolrClient(){
		HttpSolrClient solrClient = new HttpSolrClient.Builder(solrUrl)
                .withConnectionTimeout(10000)
                .withSocketTimeout(60000)
                .build();
		return solrClient;
	}
	
	/**solr搜索隨機四個商品
	 * @param pd
	 * @throws Exception
	 * @return Map
	 */
	public Map<String, Object> queryRandom4(PageData pd) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		String tradeType = pd.getString("tradeType");
		HttpSolrClient solrClient = this.getsolrClient();
		SolrQuery query = new SolrQuery();				//封裝查詢參數
		//查詢參數
		query.setQuery("*:*");
        //貿易方式-過濾查詢
		String fq = "";
		if (Tools.notEmpty(tradeType)) {
			fq += "trade_type:" + tradeType;
			query.addFilterQuery(fq);
		}
		//分頁
		int start = new Random().nextInt(10);           //爲了隨機獲取
		query.setStart(start);                          //起始頁
		query.setRows(4);								//設置每頁顯示多少條
		//添加需要回顯得字段(若不設置,默認全部回顯)
        query.addField("id");					
        query.addField("goods_id");
        query.addField("goods_name");
        query.addField("trade_type");
        query.addField("postage_style");
        query.addField("deposit");
        query.addField("category2_id");
        query.addField("category2_name");
        query.addField("fake_stock");
        query.addField("goods_price2");
        query.addField("currency_unit");
        query.addField("market_price");
        query.addField("main_map");
        //執行查詢、結果處理。
        QueryResponse response = solrClient.query(query);	//執行查詢返回QueryResponse
        List<GoodsSolr> goodsSolr = new ArrayList<GoodsSolr>();
        if (!response.getBeans(GoodsSolr.class).isEmpty()) {
        	goodsSolr = (List<GoodsSolr>) response.getBeans(GoodsSolr.class);
        }
        map.put("goodsSolr", goodsSolr);
		return map;
	}
	
	/**solr商品詳情頁根據商品二級累目搜索隨機6個商品
	 * @param pd
	 * @throws Exception
	 * @return Map
	 */
	public List<GoodsSolr> queryRandom6(String category2Name, String goodsID) throws Exception{
		HttpSolrClient solrClient = this.getsolrClient();
		SolrQuery query = new SolrQuery();				//封裝查詢參數
		//查詢參數
		query.setQuery("category2_name:" + category2Name);
        //商品ID過濾
		String fq = "-goods_id:" + goodsID;
		query.addFilterQuery(fq);
		//分頁
		int start = new Random().nextInt(5);           //爲了隨機獲取
		query.setStart(start);                          //起始頁
		query.setRows(6);								//設置每頁顯示多少條
		//添加需要回顯得字段(若不設置,默認全部回顯)
        query.addField("id");					
        query.addField("goods_id");
        query.addField("goods_name");
        query.addField("trade_type");
        query.addField("postage_style");
        query.addField("deposit");
        query.addField("goods_price2");
        query.addField("currency_unit");
        query.addField("main_map");
        //執行查詢、結果處理。
        QueryResponse response = solrClient.query(query);	//執行查詢返回QueryResponse
        List<GoodsSolr> goodsSolr = new ArrayList<GoodsSolr>();
        if (!response.getBeans(GoodsSolr.class).isEmpty()) {
        	goodsSolr = (List<GoodsSolr>) response.getBeans(GoodsSolr.class);
        }
		return goodsSolr;
	}
	
	/**solr根據關鍵詞搜索
	 * @param pd
	 * @throws Exception
	 * @return Map
	 */
	public Map<String, Object> queryByKeyword(PageData pd) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		String keyword = pd.getString("keyword");
		String tradeType = pd.getString("tradeType");
		String orderBY = pd.getString("orderBY");
		String orderAD = pd.getString("orderAD");
		Integer pageNum =  Integer.valueOf(pd.getString("pageNum"));
		Integer pageSize = Integer.valueOf(pd.getString("pageSize"));
		HttpSolrClient solrClient = this.getsolrClient();
		SolrQuery query = new SolrQuery();				//封裝查詢參數
		String q = "*:*";
		//查詢參數(propertys爲商品名稱、關鍵字等的組合)
		if (Tools.notEmpty(keyword)) {
			q = "goods_id:" + keyword + " OR " + "goods_code:" + keyword + " OR " + "brand_id:" + keyword + " OR " + "trade_type:" + keyword
			+ " OR " + "postage_style:" + keyword + " OR " + "deposit:" + keyword + " OR " + "category2_id:" + keyword + " OR " + "propertys:" + keyword;
			
		}
		query.setQuery(q);
        //貿易方式-過濾查詢
		String fq = "";
		if (Tools.notEmpty(tradeType)) {
			fq += "trade_type:" + tradeType;
			query.addFilterQuery(fq);
		}
		//銷量、新貨、價格排序
		if (!orderBY.equals("4")) {
			String sortField = "";
			if (orderBY.equals("1")) {
				sortField = "goods_sales";
			}else if(orderBY.equals("2")){
				sortField = "goods_sales";
			}else if(orderBY.equals("3")){
				sortField = "goods_sales";
			}
			if (orderAD.equals("ASC")) {
				query.addSort(sortField, ORDER.asc);
			} else {
				query.addSort(sortField, ORDER.desc);
			}
		}
		//分頁
		query.setStart(pageNum);               //起始頁
		query.setRows(pageSize);								//設置每頁顯示多少條
//		//權重計算
//		query.set("defType", "edismax");//權重計算類型
//		query.set("qf","goods_id^1 goods_name^0.1 brand_id^0.5");//設置權重計算分值
		//相似查詢
//		query.setMoreLikeThis(true);
//		query.setMoreLikeThisCount(4);
//		String[] fields = {"propertys"}; 
//		query.setMoreLikeThisFields(fields);
//		query.setMoreLikeThisMinTermFreq(1);//最小分詞頻率,源文檔中小於該頻率的分詞將被忽略掉。
//		query.setMoreLikeThisMinDocFreq(1);//最小文檔頻率,該詞所在文檔的個數小於這個值時將不用於相似判斷。
		//添加需要回顯得字段(若不設置,默認全部回顯)
        query.addField("id");					
        query.addField("goods_id");
        query.addField("goods_name");
        query.addField("brand_id");
        query.addField("brand_cname");
        query.addField("brand_ename");
        query.addField("trade_type");
        query.addField("postage_style");
        query.addField("deposit");
        query.addField("category2_id");
        query.addField("category2_name");
        query.addField("fake_stock");
        query.addField("goods_price2");
        query.addField("currency_unit");
        query.addField("market_price");
        query.addField("main_map");
        //執行查詢、結果處理。
        QueryResponse response = solrClient.query(query);	//執行查詢返回QueryResponse
        long totalRecord = response.getResults().getNumFound();       //總記錄數
        List<GoodsSolr> goodsSolr = new ArrayList<GoodsSolr>();
        goodsSolr = (List<GoodsSolr>) response.getBeans(GoodsSolr.class);
        if (!response.getBeans(GoodsSolr.class).isEmpty()) {
        	goodsSolr = (List<GoodsSolr>) response.getBeans(GoodsSolr.class);
		}
//        NamedList<SolrDocumentList> likeGoodsSolr1 = response.getMoreLikeThis();
//	for (int i = 0; i < likeGoodsSolr1.size(); i++) {
//		System.out.println(goodsSolr.get(i) + "相似的文檔有" + likeGoodsSolr1.getName(i));
//	}
//        map.put("likeGoodsSolr", likeGoodsSolr1);
        map.put("goodsSolr", goodsSolr);
        map.put("totalRecord", totalRecord);
		return map;
	}
	
	/**solr搜索
	 * @param pd
	 * @throws Exception
	 * @return Map
	 */
	public Map<String, Object> queryByBrand(PageData pd) throws Exception{
		String tradeType = pd.getString("tradeType");
		String orderBY = pd.getString("orderBY");
		String orderAD = pd.getString("orderAD");
		Integer pageNum =  Integer.valueOf(pd.getString("pageNum"));
		String brandID = pd.getString("brandID");
		Integer pageSize = Integer.valueOf(pd.getString("pageSize"));
		Map<String, Object> map = new HashMap<String, Object>();
		HttpSolrClient solrClient = this.getsolrClient();
		SolrQuery query = new SolrQuery();				//封裝查詢參數
		String q ="brand_id:" + brandID;
		query.setQuery(q);
		//貿易方式-過濾查詢
		String fq = "";
		if (Tools.notEmpty(tradeType)) {
			fq += "trade_type:" + tradeType;
			query.addFilterQuery(fq);
		}
		//銷量、新貨、價格排序
		if (!orderBY.equals("4")) {
			String sortField = "";
			if (orderBY.equals("1")) {
				sortField = "goods_sales";
			}else if(orderBY.equals("2")){
				sortField = "goods_sales";
			}else if(orderBY.equals("3")){
				sortField = "goods_sales";
			}
			if (orderAD.equals("ASC")) {
				query.addSort(sortField, ORDER.asc);
			} else {
				query.addSort(sortField, ORDER.desc);
			}
		}
		//分頁
		query.setStart(pageNum);                          	//起始頁
		query.setRows(pageSize);								//設置每頁顯示多少條
		//添加需要回顯得字段(若不設置,默認全部回顯)
        query.addField("id");					
        query.addField("goods_id");
        query.addField("goods_name");
        query.addField("trade_type");
        query.addField("postage_style");
        query.addField("deposit");
        query.addField("category2_id");
        query.addField("category2_name");
        query.addField("fake_stock");
        query.addField("goods_price2");
        query.addField("currency_unit");
        query.addField("market_price");
        query.addField("main_map");
        //執行查詢、結果處理。
        QueryResponse response = solrClient.query(query);	//執行查詢返回QueryResponse
        long totalRecord = response.getResults().getNumFound();       //總記錄數
        List<GoodsSolr> goodsSolr = new ArrayList<GoodsSolr>();
        if (!response.getBeans(GoodsSolr.class).isEmpty()) {
        	goodsSolr = (List<GoodsSolr>) response.getBeans(GoodsSolr.class);
		}
        map.put("goodsSolr", goodsSolr);
        map.put("totalRecord", totalRecord);
		return map;
	}
	
	/**solr搜索詞自動補全(前綴搜索模式)
	 * @param prefix
	 * @throws Exception
	 * @return List<String>
	 */
	public List<String> autoComplete(String prefix) throws Exception{
		HttpSolrClient solrClient = this.getsolrClient();
		SolrQuery query = new SolrQuery();				//封裝查詢參數
		query.setQuery("auto_spell:" + prefix);
		query.addField("goods_name");
		query.setStart(0);                          	//起始頁
		query.setRows(10);
		QueryResponse response = solrClient.query(query);
		List<String> autoComplete = new ArrayList<>();
		List<GoodsSolr> goodsSolr = new ArrayList<GoodsSolr>();
        if (!response.getBeans(GoodsSolr.class).isEmpty()) {
        	goodsSolr = (List<GoodsSolr>) response.getBeans(GoodsSolr.class);
        	for (GoodsSolr g : goodsSolr) {
        		autoComplete.add(g.getGoods_name());
			}
		}
        HashSet h = new HashSet(autoComplete);   
        autoComplete.clear();   
        autoComplete.addAll(h);
		return autoComplete;
	}
//	/**solr搜索詞自動補全(Facet模式)
//	 * @param prefix
//	 * @throws Exception
//	 * @return List<String>
//	 */
//	@Test
//	public void autoComplete() throws Exception{
//		String prefix = "喜寶";
//		HttpSolrClient solrClient = this.getsolrClient();
//		SolrQuery query = new SolrQuery();				//封裝查詢參數
//		query.setQuery("auto_spell:*" + prefix + "*");
//		query.setRows(0);//這樣可以只返回facet的結果,而沒有查詢結果。當然這不是必須的。
//		query.setFacet(true);
//		String[] fields={"auto_spell"};
//		query.addFacetField(fields);
////		query.setFacetPrefix(prefix);
//		query.setFacetLimit(10);// 限制facet返回的數量
//		query.setFacetMinCount(1);// 設置返回的數據中每個分組的數據最小值,比如設置爲1,則統計數量最小爲1,不然不顯示
//		
//		 QueryResponse response = solrClient.query(query);
//		 List<PageData> autoComplete = new ArrayList<PageData>();
//		 List<FacetField> facetFields = response.getFacetFields();
//		 if (facetFields.size() >= 1) {
//			 for (FacetField ff : facetFields) {
//				 List<Count> counts = ff.getValues();
//				 if (counts.size() >= 1) {
//					 for (Count count : counts){
//				            System.out.println(count.getName()+":"+ count.getCount());
//				            PageData pd = new PageData();
//				            pd.put("name", count.getName());
//				            pd.put("count", count.getCount());
//				            autoComplete.add(pd);
//				     }
//				 }
//			}
//		 }
//		 System.out.println(autoComplete);  
//	}
//	
//	/**solr搜索詞自動補全(suggest模式)
//	 * @param prefix
//	 * @throws Exception
//	 * @return List<String>
//	 */
//	@Test
//	public void getSuggest() throws Exception{
//		String prefix = "喜寶";
//		HttpSolrClient solrClient = this.getsolrClient();
//		SolrQuery query = new SolrQuery();				//封裝查詢參數
//		query.setRequestHandler("/suggest");
//		query.setQuery("auto_spell:*" + prefix + "*");
//		 QueryResponse response = solrClient.query(query);
//		 SpellCheckResponse checkResponse = response.getSpellCheckResponse();
//		 List<String> autoComplete = new ArrayList<>();
//		 if(checkResponse!=null){  
//	         List<Suggestion> suggestions = checkResponse.getSuggestions();  
//	             
//	         for (Suggestion s : suggestions) {  
//		         List<String> list = s.getAlternatives();  
//		         for (String spellword : list) {  
//			         System.out.println(spellword);  
//			         autoComplete.add(spellword);  
//		         }  
//	         }  
//	     }
//		 System.out.println(autoComplete);
//	}	
}



寫的有點亂,當時沒記錄,實際上根據W3CSchool中寫就行,部分百度下。。。

發佈了14 篇原創文章 · 獲贊 7 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章