您现在的位置是:首页 > 博客日记 > Search搜索 Search搜索

Solr的schema.xml配置文件

2018-11-05 17:28:00 【Search搜索】 人已围观

1.需求一个solr库存储三种类型数据 (视频数据,新闻数据 注:两种数据id可能重复)
  • 1.配置将主键id改为了_id,为了避免与数据库id冲突
  1. <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false"/>
  2. <uniqueKey>id</uniqueKey>
  3. 改为:
  4. <field name="_id" type="string" indexed="true" stored="true" required="true" multiValued="false"/>
  5. <uniqueKey>_id</uniqueKey>
  • 2.将主键id设置成自增

添加uuid字段类型,修改字段id的类型。

  1. <field name="id" type="uuid" indexed="true" stored="true" required="true" multiValued="false" />
  2. <!--添加这行配置-->
  3. <fieldType name="uuid" class="solr.UUIDField" indexed="true"/>
  • 2.1修改配置solrconfig.xml文件

添加更新策略配置,调用Solr中的UUIDUpdateProcessorFactory生成全局唯一的UUID。

  1. <updateRequestProcessorChain name="uuid">
  2. <processor class="solr.UUIDUpdateProcessorFactory">
  3. <str name="fieldName">_id</str>
  4. </processor>
  5. <processor class="solr.LogUpdateProcessorFactory" />
  6. <processor class="solr.DistributedUpdateProcessorFactory" />
  7. <processor class="solr.RunUpdateProcessorFactory" />
  8. </updateRequestProcessorChain>

配置requestHandler,保证dataimport和update操作都可以自动生成UUID。

添加这一行<str name="update.chain">uuid</str>

  1. <initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell">
  2. <lst name="defaults">
  3. <!--添加这一行 start -->
  4. <str name="update.chain">uuid</str>
  5. <!--添加这一行 start -->
  6. <str name="df">text</str>
  7. </lst>
  8. </initParams>
  • 3.搜索时同时搜索titlecontent两个字段
  1. <!-- 设置搜索虚拟字段 searchText 的搜索分词器 -->
  2. <field name="searchText" type="text_ik" indexed="true" stored="false" multiValued="true" />
  3. <!-- 复制title内容和content内容到searchText虚拟字段 -->
  4. <copyField source="title" dest="searchText" />
  5. <copyField source="content" dest="searchText" />
  • 4.Filed中indexed、stored、multiValued属性

indexed=”true” 可以被搜索

stored=”true” 结果集中有这个字段

multiValued=”true” 可以有多个值,适用于搜索时,两个字段copy出来的虚拟字段

  • 注: 修改配置文件需要重启服务

  • 完整schema.xml配置文件

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. //www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!--
  17. This is the Solr schema file. This file should be named "schema.xml" and
  18. should be in the conf directory under the solr home
  19. (i.e. ./solr/conf/schema.xml by default)
  20. or located where the classloader for the Solr webapp can find it.
  21. This example schema is the recommended starting point for users.
  22. It should be kept correct and concise, usable out-of-the-box.
  23. For more information, on how to customize this file, please see
  24. //wiki.apache.org/solr/SchemaXml
  25. -->
  26. <schema name="example" version="1.5">
  27. <!-- attribute "name" is the name of this schema and is only used for display purposes.
  28. version="x.y" is Solr's version number for the schema syntax and
  29. semantics. It should not normally be changed by applications.
  30. 1.0: multiValued attribute did not exist, all fields are multiValued
  31. by nature
  32. 1.1: multiValued attribute introduced, false by default
  33. 1.2: omitTermFreqAndPositions attribute introduced, true by default
  34. except for text fields.
  35. 1.3: removed optional field compress feature
  36. 1.4: autoGeneratePhraseQueries attribute introduced to drive QueryParser
  37. behavior when a single string produces multiple tokens. Defaults
  38. to off for version >= 1.4
  39. 1.5: omitNorms defaults to true for primitive field types
  40. (int, float, boolean, string...)
  41. -->
  42. <!-- Valid attributes for fields:
  43. name: mandatory - the name for the field
  44. type: mandatory - the name of a field type from the
  45. <types> fieldType section
  46. indexed: true if this field should be indexed (searchable or sortable)
  47. stored: true if this field should be retrievable
  48. docValues: true if this field should have doc values. Doc values are
  49. useful for faceting, grouping, sorting and function queries. Although not
  50. required, doc values will make the index faster to load, more
  51. NRT-friendly and more memory-efficient. They however come with some
  52. limitations: they are currently only supported by StrField, UUIDField
  53. and all Trie*Fields, and depending on the field type, they might
  54. require the field to be single-valued, be required or have a default
  55. value (check the documentation of the field type you're interested in
  56. for more information)
  57. multiValued: true if this field may contain multiple values per document
  58. omitNorms: (expert) set to true to omit the norms associated with
  59. this field (this disables length normalization and index-time
  60. boosting for the field, and saves some memory). Only full-text
  61. fields or fields that need an index-time boost need norms.
  62. Norms are omitted for primitive (non-analyzed) types by default.
  63. termVectors: [false] set to true to store the term vector for a
  64. given field.
  65. When using MoreLikeThis, fields used for similarity should be
  66. stored for best performance.
  67. termPositions: Store position information with the term vector.
  68. This will increase storage costs.
  69. termOffsets: Store offset information with the term vector. This
  70. will increase storage costs.
  71. required: The field is required. It will throw an error if the
  72. value does not exist
  73. default: a value that should be used if no value is specified
  74. when adding a document.
  75. -->
  76. <!-- field names should consist of alphanumeric or underscore characters only and
  77. not start with a digit. This is not currently strictly enforced,
  78. but other field names will not have first class support from all components
  79. and back compatibility is not guaranteed. Names with both leading and
  80. trailing underscores (e.g. _version_) are reserved.
  81. -->
  82. <!-- If you remove this field, you must _also_ disable the update log in solrconfig.xml
  83. or Solr won't start. _version_ and update log are required for SolrCloud
  84. -->
  85. <field name="_version_" type="long" indexed="true" stored="true"/>
  86. <!-- points to the root document of a block of nested documents. Required for nested
  87. document support, may be removed otherwise
  88. -->
  89. <field name="_root_" type="string" indexed="true" stored="false"/>
  90. <!-- Only remove the "id" field if you have a very good reason to. While not strictly
  91. required, it is highly recommended. A <uniqueKey> is present in almost all Solr
  92. installations. See the <uniqueKey> declaration below where <uniqueKey> is set to "id".
  93. Do NOT change the type and apply index-time analysis to the <uniqueKey> as it will likely
  94. make routing in SolrCloud and document replacement in general fail. Limited _query_ time
  95. analysis is possible as long as the indexing process is guaranteed to index the term
  96. in a compatible way. Any analysis applied to the <uniqueKey> should _not_ produce multiple
  97. tokens
  98. -->
  99. <!-- 这是主键id,修改成了_id -->
  100. <field name="_id" type="uuid" indexed="true" stored="true" required="true" multiValued="false"/>
  101. <!-- 将主键id设置成自增 -->
  102. <fieldType name="uuid" class="solr.UUIDField" indexed="true"/>
  103. <!-- 搜索字段 copy的title and item_title -->
  104. <field name="searchText" type="text_ik" indexed="true" stored="false" multiValued="true" />
  105. <!-- index 库存储字段 -->
  106. <field name="id" type="int" default="0" indexed="true" stored="true"/>
  107. <field name="type" type="int" default="0" indexed="true" stored="true"/>
  108. <field name="title" type="text_ik" default="" indexed="true" stored="true"/>
  109. <field name="inputtime" type="int" default="0" indexed="true" stored="true"/>
  110. <field name="updatetime" type="int" default="0" indexed="true" stored="true"/>
  111. <field name="status" type="int" default="0" indexed="true" stored="true"/>
  112. <field name="share_url" type="string" default="" indexed="true" stored="true"/>
  113. <!-- 视频字段 -->
  114. <field name="user_id" type="int" indexed="true" stored="true"/>
  115. <field name="project_id" type="int" indexed="true" stored="true"/>
  116. <field name="slogan" type="string" indexed="true" stored="true"/>
  117. <field name="type_id" type="int" indexed="true" stored="true"/>
  118. <field name="cate_id" type="int" indexed="true" stored="true"/>
  119. <field name="views" type="int" indexed="true" stored="true"/>
  120. <field name="describe" type="string" indexed="true" stored="true"/>
  121. <field name="is_hot" type="int" indexed="true" stored="true"/>
  122. <field name="type_name" type="string" indexed="true" stored="true"/>
  123. <field name="cate_name" type="string" indexed="true" stored="true"/>
  124. <field name="cover_url" type="string" indexed="true" stored="true"/>
  125. <field name="video_url" type="string" indexed="true" stored="true"/>
  126. <field name="play_time_format" type="string" indexed="true" stored="true"/>
  127. <field name="file_size" type="string" indexed="true" stored="true"/>
  128. <field name="item_logo" type="string" indexed="true" stored="true"/>
  129. <!--项目 -->
  130. <field name="catid" type="int" indexed="true" stored="true"/>
  131. <field name="ispay" type="int" indexed="true" stored="true"/>
  132. <field name="item_title" type="text_ik" indexed="true" stored="true"/>
  133. <field name="item_brandword" type="string" indexed="true" stored="true"/>
  134. <field name="brand" type="string" indexed="true" stored="true"/>
  135. <field name="brandword" type="string" indexed="true" stored="true"/>
  136. <field name="logo" type="string" indexed="true" stored="true"/>
  137. <field name="funds" type="string" indexed="true" stored="true"/>
  138. <field name="franchisee" type="string" indexed="true" stored="true"/>
  139. <field name="3gurl" type="string" indexed="true" stored="true"/>
  140. <field name="mobile_url" type="string" indexed="true" stored="true"/>
  141. <field name="companyId" type="string" indexed="true" stored="true"/>
  142. <field name="app_url" type="string" indexed="true" stored="true"/>
  143. <field name="gbooks" type="string" indexed="true" stored="true"/>
  144. <field name="dpa_item_logo" type="string" indexed="true" stored="true"/>
  145. <field name="dpa_img_dan1" type="string" indexed="true" stored="true"/>
  146. <field name="dpa_img_dan2" type="string" indexed="true" stored="true"/>
  147. <!--资讯 -->
  148. <field name="img" type="string" indexed="true" stored="true"/>
  149. <field name="itemid" type="string" indexed="true" stored="true"/>
  150. <field name="create_time" type="string" indexed="true" stored="true"/>
  151. <field name="announcer" type="string" indexed="true" stored="true"/>
  152. <field name="tag" type="string" indexed="true" stored="true"/>
  153. <field name="flag" type="int" indexed="true" stored="true"/>
  154. <field name="uid" type="int" indexed="true" stored="true"/>
  155. <field name="touid" type="int" indexed="true" stored="true"/>
  156. <field name="username" type="string" indexed="true" stored="true"/>
  157. <field name="content" type="string" indexed="true" stored="true"/>
  158. <field name="answercount" type="string" indexed="true" stored="true"/>
  159. <field name="anonymity" type="string" indexed="true" stored="true"/>
  160. <field name="praise" type="string" indexed="true" stored="true"/>
  161. <field name="resource" type="string" indexed="true" stored="true"/>
  162. <!-- Dynamic field definitions allow using convention over configuration
  163. for fields via the specification of patterns to match field names.
  164. EXAMPLE: name="*_i" will match any field ending in _i (like myid_i, z_i)
  165. RESTRICTION: the glob-like pattern in the name attribute must have
  166. a "*" only at the start or the end. -->
  167. <dynamicField name="*_i" type="int" indexed="true" stored="true"/>
  168. <dynamicField name="*_is" type="int" indexed="true" stored="true" multiValued="true"/>
  169. <dynamicField name="*_s" type="string" indexed="true" stored="true"/>
  170. <dynamicField name="*_ss" type="string" indexed="true" stored="true" multiValued="true"/>
  171. <dynamicField name="*_l" type="long" indexed="true" stored="true"/>
  172. <dynamicField name="*_ls" type="long" indexed="true" stored="true" multiValued="true"/>
  173. <dynamicField name="*_t" type="text_general" indexed="true" stored="true"/>
  174. <dynamicField name="*_txt" type="text_general" indexed="true" stored="true" multiValued="true"/>
  175. <dynamicField name="*_en" type="text_en" indexed="true" stored="true" multiValued="true"/>
  176. <dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>
  177. <dynamicField name="*_bs" type="boolean" indexed="true" stored="true" multiValued="true"/>
  178. <dynamicField name="*_f" type="float" indexed="true" stored="true"/>
  179. <dynamicField name="*_fs" type="float" indexed="true" stored="true" multiValued="true"/>
  180. <dynamicField name="*_d" type="double" indexed="true" stored="true"/>
  181. <dynamicField name="*_ds" type="double" indexed="true" stored="true" multiValued="true"/>
  182. <!-- Type used to index the lat and lon components for the "location" FieldType -->
  183. <dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false"/>
  184. <dynamicField name="*_dt" type="date" indexed="true" stored="true"/>
  185. <dynamicField name="*_dts" type="date" indexed="true" stored="true" multiValued="true"/>
  186. <dynamicField name="*_p" type="location" indexed="true" stored="true"/>
  187. <!-- some trie-coded dynamic fields for faster range queries -->
  188. <dynamicField name="*_ti" type="tint" indexed="true" stored="true"/>
  189. <dynamicField name="*_tl" type="tlong" indexed="true" stored="true"/>
  190. <dynamicField name="*_tf" type="tfloat" indexed="true" stored="true"/>
  191. <dynamicField name="*_td" type="tdouble" indexed="true" stored="true"/>
  192. <dynamicField name="*_tdt" type="tdate" indexed="true" stored="true"/>
  193. <dynamicField name="*_c" type="currency" indexed="true" stored="true"/>
  194. <dynamicField name="ignored_*" type="ignored" multiValued="true"/>
  195. <dynamicField name="attr_*" type="text_general" indexed="true" stored="true" multiValued="true"/>
  196. <dynamicField name="random_*" type="random"/>
  197. <!-- uncomment the following to ignore any fields that don't already match an existing
  198. field name or dynamic field, rather than reporting them as an error.
  199. alternately, change the type="ignored" to some other type e.g. "text" if you want
  200. unknown fields indexed and/or stored by default -->
  201. <!--dynamicField name="*" type="ignored" multiValued="true" /-->
  202. <!-- Field to use to determine and enforce document uniqueness.
  203. Unless this field is marked with required="false", it will be a required field
  204. -->
  205. <!-- 这是主键唯一id,修改成了_id -->
  206. <uniqueKey>_id</uniqueKey>
  207. <!-- copyField commands copy one field to another at the time a document
  208. is added to the index. It's used either to index the same field differently,
  209. or to add multiple fields to the same field for easier/faster searching. -->
  210. <copyField source="title" dest="searchText" />
  211. <copyField source="item_title" dest="searchText" />
  212. <!--
  213. <copyField source="title" dest="text"/>
  214. <copyField source="body" dest="text"/>
  215. -->
  216. <!-- field type definitions. The "name" attribute is
  217. just a label to be used by field definitions. The "class"
  218. attribute and any other attributes determine the real
  219. behavior of the fieldType.
  220. Class names starting with "solr" refer to java classes in a
  221. standard package such as org.apache.solr.analysis
  222. -->
  223. <!-- The StrField type is not analyzed, but indexed/stored verbatim.
  224. It supports doc values but in that case the field needs to be
  225. single-valued and either required or have a default value.
  226. -->
  227. <fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
  228. <!-- boolean type: "true" or "false" -->
  229. <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
  230. <!-- sortMissingLast and sortMissingFirst attributes are optional attributes are
  231. currently supported on types that are sorted internally as strings
  232. and on numeric types.
  233. This includes "string","boolean", and, as of 3.5 (and 4.x),
  234. int, float, long, date, double, including the "Trie" variants.
  235. - If sortMissingLast="true", then a sort on this field will cause documents
  236. without the field to come after documents with the field,
  237. regardless of the requested sort order (asc or desc).
  238. - If sortMissingFirst="true", then a sort on this field will cause documents
  239. without the field to come before documents with the field,
  240. regardless of the requested sort order.
  241. - If sortMissingLast="false" and sortMissingFirst="false" (the default),
  242. then default lucene sorting will be used which places docs without the
  243. field first in an ascending sort and last in a descending sort.
  244. -->
  245. <!--
  246. Default numeric field types. For faster range queries, consider the tint/tfloat/tlong/tdouble types.
  247. These fields support doc values, but they require the field to be
  248. single-valued and either be required or have a default value.
  249. -->
  250. <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
  251. <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
  252. <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
  253. <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
  254. <!--
  255. Numeric field types that index each value at various levels of precision
  256. to accelerate range queries when the number of values between the range
  257. endpoints is large. See the javadoc for NumericRangeQuery for internal
  258. implementation details.
  259. Smaller precisionStep values (specified in bits) will lead to more tokens
  260. indexed per value, slightly larger index size, and faster range queries.
  261. A precisionStep of 0 disables indexing at different precision levels.
  262. -->
  263. <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>
  264. <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>
  265. <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>
  266. <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>
  267. <!-- The format for this date field is of the form 1995-12-31T23:59:59Z, and
  268. is a more restricted form of the canonical representation of dateTime
  269. //www.w3.org/TR/xmlschema-2/#dateTime
  270. The trailing "Z" designates UTC time and is mandatory.
  271. Optional fractional seconds are allowed: 1995-12-31T23:59:59.999Z
  272. All other components are mandatory.
  273. Expressions can also be used to denote calculations that should be
  274. performed relative to "NOW" to determine the value, ie...
  275. NOW/HOUR
  276. ... Round to the start of the current hour
  277. NOW-1DAY
  278. ... Exactly 1 day prior to now
  279. NOW/DAY+6MONTHS+3DAYS
  280. ... 6 months and 3 days in the future from the start of
  281. the current day
  282. Consult the TrieDateField javadocs for more information.
  283. Note: For faster range queries, consider the tdate type
  284. -->
  285. <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>
  286. <!-- A Trie based date field for faster date range queries and date faceting. -->
  287. <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/>
  288. <!--Binary data type. The data should be sent/retrieved in as Base64 encoded Strings -->
  289. <fieldType name="binary" class="solr.BinaryField"/>
  290. <!-- The "RandomSortField" is not used to store or search any
  291. data. You can declare fields of this type it in your schema
  292. to generate pseudo-random orderings of your docs for sorting
  293. or function purposes. The ordering is generated based on the field
  294. name and the version of the index. As long as the index version
  295. remains unchanged, and the same field name is reused,
  296. the ordering of the docs will be consistent.
  297. If you want different psuedo-random orderings of documents,
  298. for the same version of the index, use a dynamicField and
  299. change the field name in the request.
  300. -->
  301. <fieldType name="random" class="solr.RandomSortField" indexed="true"/>
  302. <!-- solr.TextField allows the specification of custom text analyzers
  303. specified as a tokenizer and a list of token filters. Different
  304. analyzers may be specified for indexing and querying.
  305. The optional positionIncrementGap puts space between multiple fields of
  306. this type on the same document, with the purpose of preventing false phrase
  307. matching across fields.
  308. For more info on customizing your analyzer chain, please see
  309. //wiki.apache.org/solr/AnalyzersTokenizersTokenFilters
  310. -->
  311. <!-- One can also specify an existing Analyzer class that has a
  312. default constructor via the class attribute on the analyzer element.
  313. Example:
  314. <fieldType name="text_greek" class="solr.TextField">
  315. <analyzer class="org.apache.lucene.analysis.el.GreekAnalyzer"/>
  316. </fieldType>
  317. -->
  318. <!-- A text field that only splits on whitespace for exact matching of words -->
  319. <fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">
  320. <analyzer>
  321. <tokenizer class="solr.WhitespaceTokenizerFactory"/>
  322. </analyzer>
  323. </fieldType>
  324. <!-- A general text field that has reasonable, generic
  325. cross-language defaults: it tokenizes with StandardTokenizer,
  326. removes stop words from case-insensitive "stopwords.txt"
  327. (empty by default), and down cases. At query time only, it
  328. also applies synonyms. -->
  329. <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
  330. <analyzer type="index">
  331. <tokenizer class="solr.StandardTokenizerFactory"/>
  332. <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
  333. <!-- in this example, we will only use synonyms at query time
  334. <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
  335. -->
  336. <filter class="solr.LowerCaseFilterFactory"/>
  337. </analyzer>
  338. <analyzer type="query">
  339. <tokenizer class="solr.StandardTokenizerFactory"/>
  340. <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
  341. <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
  342. <filter class="solr.LowerCaseFilterFactory"/>
  343. </analyzer>
  344. </fieldType>
  345. <!-- A text field with defaults appropriate for English: it
  346. tokenizes with StandardTokenizer, removes English stop words
  347. (lang/stopwords_en.txt), down cases, protects words from protwords.txt, and
  348. finally applies Porter's stemming. The query time analyzer
  349. also applies synonyms from synonyms.txt. -->
  350. <fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">
  351. <analyzer type="index">
  352. <tokenizer class="solr.StandardTokenizerFactory"/>
  353. <!-- in this example, we will only use synonyms at query time
  354. <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
  355. -->
  356. <!-- Case insensitive stop word removal.
  357. -->
  358. <filter class="solr.StopFilterFactory"
  359. ignoreCase="true"
  360. words="lang/stopwords_en.txt"
  361. />
  362. <filter class="solr.LowerCaseFilterFactory"/>
  363. <filter class="solr.EnglishPossessiveFilterFactory"/>
  364. <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
  365. <!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory:
  366. <filter class="solr.EnglishMinimalStemFilterFactory"/>
  367. -->
  368. <filter class="solr.PorterStemFilterFactory"/>
  369. </analyzer>
  370. <analyzer type="query">
  371. <tokenizer class="solr.StandardTokenizerFactory"/>
  372. <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
  373. <filter class="solr.StopFilterFactory"
  374. ignoreCase="true"
  375. words="lang/stopwords_en.txt"
  376. />
  377. <filter class="solr.LowerCaseFilterFactory"/>
  378. <filter class="solr.EnglishPossessiveFilterFactory"/>
  379. <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
  380. <!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory:
  381. <filter class="solr.EnglishMinimalStemFilterFactory"/>
  382. -->
  383. <filter class="solr.PorterStemFilterFactory"/>
  384. </analyzer>
  385. </fieldType>
  386. <!-- A text field with defaults appropriate for English, plus
  387. aggressive word-splitting and autophrase features enabled.
  388. This field is just like text_en, except it adds
  389. WordDelimiterFilter to enable splitting and matching of
  390. words on case-change, alpha numeric boundaries, and
  391. non-alphanumeric chars. This means certain compound word
  392. cases will work, for example query "wi fi" will match
  393. document "WiFi" or "wi-fi".
  394. -->
  395. <fieldType name="text_en_splitting" class="solr.TextField" positionIncrementGap="100"
  396. autoGeneratePhraseQueries="true">
  397. <analyzer type="index">
  398. <tokenizer class="solr.WhitespaceTokenizerFactory"/>
  399. <!-- in this example, we will only use synonyms at query time
  400. <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
  401. -->
  402. <!-- Case insensitive stop word removal.
  403. -->
  404. <filter class="solr.StopFilterFactory"
  405. ignoreCase="true"
  406. words="lang/stopwords_en.txt"
  407. />
  408. <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1"
  409. catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
  410. <filter class="solr.LowerCaseFilterFactory"/>
  411. <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
  412. <filter class="solr.PorterStemFilterFactory"/>
  413. </analyzer>
  414. <analyzer type="query">
  415. <tokenizer class="solr.WhitespaceTokenizerFactory"/>
  416. <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
  417. <filter class="solr.StopFilterFactory"
  418. ignoreCase="true"
  419. words="lang/stopwords_en.txt"
  420. />
  421. <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1"
  422. catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
  423. <filter class="solr.LowerCaseFilterFactory"/>
  424. <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
  425. <filter class="solr.PorterStemFilterFactory"/>
  426. </analyzer>
  427. </fieldType>
  428. <!-- Less flexible matching, but less false matches. Probably not ideal for product names,
  429. but may be good for SKUs. Can insert dashes in the wrong place and still match. -->
  430. <fieldType name="text_en_splitting_tight" class="solr.TextField" positionIncrementGap="100"
  431. autoGeneratePhraseQueries="true">
  432. <analyzer>
  433. <tokenizer class="solr.WhitespaceTokenizerFactory"/>
  434. <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="false"/>
  435. <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt"/>
  436. <filter class="solr.WordDelimiterFilterFactory" generateWordParts="0" generateNumberParts="0"
  437. catenateWords="1" catenateNumbers="1" catenateAll="0"/>
  438. <filter class="solr.LowerCaseFilterFactory"/>
  439. <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
  440. <filter class="solr.EnglishMinimalStemFilterFactory"/>
  441. <!-- this filter can remove any duplicate tokens that appear at the same position - sometimes
  442. possible with WordDelimiterFilter in conjuncton with stemming. -->
  443. <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  444. </analyzer>
  445. </fieldType>
  446. <!-- Just like text_general except it reverses the characters of
  447. each token, to enable more efficient leading wildcard queries. -->
  448. <fieldType name="text_general_rev" class="solr.TextField" positionIncrementGap="100">
  449. <analyzer type="index">
  450. <tokenizer class="solr.StandardTokenizerFactory"/>
  451. <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
  452. <filter class="solr.LowerCaseFilterFactory"/>
  453. <filter class="solr.ReversedWildcardFilterFactory" withOriginal="true"
  454. maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33"/>
  455. </analyzer>
  456. <analyzer type="query">
  457. <tokenizer class="solr.StandardTokenizerFactory"/>
  458. <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
  459. <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
  460. <filter class="solr.LowerCaseFilterFactory"/>
  461. </analyzer>
  462. </fieldType>
  463. <!-- This is an example of using the KeywordTokenizer along
  464. With various TokenFilterFactories to produce a sortable field
  465. that does not include some properties of the source text
  466. -->
  467. <fieldType name="alphaOnlySort" class="solr.TextField" sortMissingLast="true" omitNorms="true">
  468. <analyzer>
  469. <!-- KeywordTokenizer does no actual tokenizing, so the entire
  470. input string is preserved as a single token
  471. -->
  472. <tokenizer class="solr.KeywordTokenizerFactory"/>
  473. <!-- The LowerCase TokenFilter does what you expect, which can be
  474. when you want your sorting to be case insensitive
  475. -->
  476. <filter class="solr.LowerCaseFilterFactory"/>
  477. <!-- The TrimFilter removes any leading or trailing whitespace -->
  478. <filter class="solr.TrimFilterFactory"/>
  479. <!-- The PatternReplaceFilter gives you the flexibility to use
  480. Java Regular expression to replace any sequence of characters
  481. matching a pattern with an arbitrary replacement string,
  482. which may include back references to portions of the original
  483. string matched by the pattern.
  484. See the Java Regular Expression documentation for more
  485. information on pattern and replacement string syntax.
  486. //docs.oracle.com/javase/7/docs/api/java/util/regex/package-summary.html
  487. -->
  488. <filter class="solr.PatternReplaceFilterFactory"
  489. pattern="([^a-z])" replacement="" replace="all"
  490. />
  491. </analyzer>
  492. </fieldType>
  493. <!-- lowercases the entire field value, keeping it as a single token. -->
  494. <fieldType name="lowercase" class="solr.TextField" positionIncrementGap="100">
  495. <analyzer>
  496. <tokenizer class="solr.KeywordTokenizerFactory"/>
  497. <filter class="solr.LowerCaseFilterFactory"/>
  498. </analyzer>
  499. </fieldType>
  500. <!-- since fields of this type are by default not stored or indexed,
  501. any data added to them will be ignored outright. -->
  502. <fieldType name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField"/>
  503. <!-- This point type indexes the coordinates as separate fields (subFields)
  504. If subFieldType is defined, it references a type, and a dynamic field
  505. definition is created matching *___<typename>. Alternately, if
  506. subFieldSuffix is defined, that is used to create the subFields.
  507. Example: if subFieldType="double", then the coordinates would be
  508. indexed in fields myloc_0___double,myloc_1___double.
  509. Example: if subFieldSuffix="_d" then the coordinates would be indexed
  510. in fields myloc_0_d,myloc_1_d
  511. The subFields are an implementation detail of the fieldType, and end
  512. users normally should not need to know about them.
  513. -->
  514. <fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
  515. <!-- A specialized field for geospatial search. If indexed, this fieldType must not be multivalued. -->
  516. <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
  517. <!-- An alternative geospatial field type new to Solr 4. It supports multiValued and polygon shapes.
  518. For more information about this and other Spatial fields new to Solr 4, see:
  519. //wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4
  520. -->
  521. <fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
  522. geo="true" distErrPct="0.025" maxDistErr="0.001" distanceUnits="kilometers"/>
  523. <!-- Spatial rectangle (bounding box) field. It supports most spatial predicates, and has
  524. special relevancy modes: score=overlapRatio|area|area2D (local-param to the query). DocValues is recommended for
  525. relevancy. -->
  526. <fieldType name="bbox" class="solr.BBoxField"
  527. geo="true" distanceUnits="kilometers" numberType="_bbox_coord"/>
  528. <fieldType name="_bbox_coord" class="solr.TrieDoubleField" precisionStep="8" docValues="true" stored="false"/>
  529. <!-- Money/currency field type. See //wiki.apache.org/solr/MoneyFieldType
  530. Parameters:
  531. defaultCurrency: Specifies the default currency if none specified. Defaults to "USD"
  532. precisionStep: Specifies the precisionStep for the TrieLong field used for the amount
  533. providerClass: Lets you plug in other exchange provider backend:
  534. solr.FileExchangeRateProvider is the default and takes one parameter:
  535. currencyConfig: name of an xml file holding exchange rates
  536. solr.OpenExchangeRatesOrgProvider uses rates from openexchangerates.org:
  537. ratesFileLocation: URL or path to rates JSON file (default latest.json on the web)
  538. refreshInterval: Number of minutes between each rates fetch (default: 1440, min: 60)
  539. -->
  540. <fieldType name="currency" class="solr.CurrencyField" precisionStep="8" defaultCurrency="USD"
  541. currencyConfig="currency.xml"/>
  542. <fieldType name="text_ik" class="solr.TextField">
  543. <analyzer type="index">
  544. <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/>
  545. <filter class="solr.LowerCaseFilterFactory"/>
  546. </analyzer>
  547. <analyzer type="query">
  548. <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/>
  549. <filter class="solr.LowerCaseFilterFactory"/>
  550. </analyzer>
  551. </fieldType>
  552. </schema>


关注TinyMeng博客,更多精彩分享,敬请期待!
 

很赞哦! ()