指尖上的电商---(4).net开发solr

 这一节我们看下怎样把查询数据放到服务器端存储,这里我们需要使用客户端工具来操作与服务端数据打交道,网上有好多基于.NET开发的SOLR客户端,我们这里选择easynet.solr,很方便的一个DLL,

      下载地址:http://easynet.codeplex.com/SourceControl/latest

      这一节主要包括Solr数据索引的添加,修改,删除,查询等简单功能。

      我们先来看下效果图

      

      1.创建对象

 

       

[csharp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. public class Product  
  2.    {  
  3.   
  4.        /// <summary>  
  5.        /// 产品编码  
  6.        /// </summary>  
  7.        public string ProductCode { getset; }  
  8.   
  9.        /// <summary>  
  10.        /// 产品名称  
  11.        /// </summary>  
  12.        public string ProductName { getset; }  
  13.    }  


 

 

 

      2.配置schema.xml

         找到tomcat下的schema.xml配置文件 ,具体位置:C:\Program Files\Apache Software Foundation\Tomcat 8.0\solr\collection1\conf

 

         添加字段节点,这里我们设置ProductCode为主键,注意设置 

<uniqueKey>ProductCode</uniqueKey>
        

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2.   
  3.   
  4. <schema name="example" version="1.5">  
  5.   
  6.    <field name="_version_" type="long" indexed="true" stored="true"/>  
  7.    <field name="_root_" type="string" indexed="true" stored="false"/>  
  8.   
  9.   
  10.    <field name="ProductCode" type="string" indexed="true" stored="true" required="true" multiValued="false" />   
  11.          
  12.   <field name="ProductName" type="text_general" indexed="true" stored="true"/>  
  13.    
  14.    <dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>  
  15.    <dynamicField name="*_is" type="int"    indexed="true"  stored="true"  multiValued="true"/>  
  16.    <dynamicField name="*_s"  type="string"  indexed="true"  stored="true" />  
  17.    <dynamicField name="*_ss" type="string"  indexed="true"  stored="true" multiValued="true"/>  
  18.    <dynamicField name="*_l"  type="long"   indexed="true"  stored="true"/>  
  19.    <dynamicField name="*_ls" type="long"   indexed="true"  stored="true"  multiValued="true"/>  
  20.    <dynamicField name="*_t"  type="text_general"    indexed="true"  stored="true"/>  
  21.    <dynamicField name="*_txt" type="text_general"   indexed="true"  stored="true" multiValued="true"/>  
  22.    <dynamicField name="*_en"  type="text_en"    indexed="true"  stored="true" multiValued="true"/>  
  23.    <dynamicField name="*_b"  type="boolean" indexed="true" stored="true"/>  
  24.    <dynamicField name="*_bs" type="boolean" indexed="true" stored="true"  multiValued="true"/>  
  25.    <dynamicField name="*_f"  type="float"  indexed="true"  stored="true"/>  
  26.    <dynamicField name="*_fs" type="float"  indexed="true"  stored="true"  multiValued="true"/>  
  27.    <dynamicField name="*_d"  type="double" indexed="true"  stored="true"/>  
  28.    <dynamicField name="*_ds" type="double" indexed="true"  stored="true"  multiValued="true"/>  
  29.   
  30.    <!-- Type used to index the lat and lon components for the "location" FieldType -->  
  31.    <dynamicField name="*_coordinate"  type="tdouble" indexed="true"  stored="false" />  
  32.   
  33.    <dynamicField name="*_dt"  type="date"    indexed="true"  stored="true"/>  
  34.    <dynamicField name="*_dts" type="date"    indexed="true"  stored="true" multiValued="true"/>  
  35.    <dynamicField name="*_p"  type="location" indexed="true" stored="true"/>  
  36.   
  37.    <!-- some trie-coded dynamic fields for faster range queries -->  
  38.    <dynamicField name="*_ti" type="tint"    indexed="true"  stored="true"/>  
  39.    <dynamicField name="*_tl" type="tlong"   indexed="true"  stored="true"/>  
  40.    <dynamicField name="*_tf" type="tfloat"  indexed="true"  stored="true"/>  
  41.    <dynamicField name="*_td" type="tdouble" indexed="true"  stored="true"/>  
  42.    <dynamicField name="*_tdt" type="tdate"  indexed="true"  stored="true"/>  
  43.   
  44.    <dynamicField name="*_c"   type="currency" indexed="true"  stored="true"/>  
  45.   
  46.    <dynamicField name="ignored_*" type="ignored" multiValued="true"/>  
  47.    <dynamicField name="attr_*" type="text_general" indexed="true" stored="true" multiValued="true"/>  
  48.   
  49.    <dynamicField name="random_*" type="random" />  
  50.   
  51.    <!-- uncomment the following to ignore any fields that don't already match an existing   
  52.         field name or dynamic field, rather than reporting them as an error.   
  53.         alternately, change the type="ignored" to some other type e.g. "text" if you want   
  54.         unknown fields indexed and/or stored by default -->   
  55.    <!--dynamicField name="*" type="ignored" multiValued="true" /-->  
  56.      
  57.   
  58.   
  59.   
  60.  <!-- Field to use to determine and enforce document uniqueness.   
  61.       Unless this field is marked with required="false", it will be a required field  
  62.    -->  
  63.  <uniqueKey>ProductCode</uniqueKey>  
  64.   
  65.   
  66.   
  67.     <fieldType name="string" class="solr.StrField" sortMissingLast="true" />  
  68.   
  69.     <!-- boolean type: "true" or "false" -->  
  70.     <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>  
  71.   
  72.     <!-- sortMissingLast and sortMissingFirst attributes are optional attributes are  
  73.          currently supported on types that are sorted internally as strings  
  74.          and on numeric types.  
  75.          This includes "string","boolean", and, as of 3.5 (and 4.x),  
  76.          int, float, long, date, double, including the "Trie" variants.  
  77.        - If sortMissingLast="true", then a sort on this field will cause documents  
  78.          without the field to come after documents with the field,  
  79.          regardless of the requested sort order (asc or desc).  
  80.        - If sortMissingFirst="true", then a sort on this field will cause documents  
  81.          without the field to come before documents with the field,  
  82.          regardless of the requested sort order.  
  83.        - If sortMissingLast="false" and sortMissingFirst="false" (the default),  
  84.          then default lucene sorting will be used which places docs without the  
  85.          field first in an ascending sort and last in a descending sort.  
  86.     -->      
  87.   
  88.     <!--  
  89.       Default numeric field types. For faster range queries, consider the tint/tfloat/tlong/tdouble types.  
  90.   
  91.       These fields support doc values, but they require the field to be  
  92.       single-valued and either be required or have a default value.  
  93.     -->  
  94.     <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>  
  95.     <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>  
  96.     <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>  
  97.     <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>  
  98.   
  99.     <!--  
  100.      Numeric field types that index each value at various levels of precision  
  101.      to accelerate range queries when the number of values between the range  
  102.      endpoints is large. See the javadoc for NumericRangeQuery for internal  
  103.      implementation details.  
  104.   
  105.      Smaller precisionStep values (specified in bits) will lead to more tokens  
  106.      indexed per value, slightly larger index size, and faster range queries.  
  107.      A precisionStep of 0 disables indexing at different precision levels.  
  108.     -->  
  109.     <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>  
  110.     <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>  
  111.     <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>  
  112.     <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>  
  113.   
  114.     <!-- The format for this date field is of the form 1995-12-31T23:59:59Z, and  
  115.          is a more restricted form of the canonical representation of dateTime  
  116.          http://www.w3.org/TR/xmlschema-2/#dateTime      
  117.          The trailing "Z" designates UTC time and is mandatory.  
  118.          Optional fractional seconds are allowed: 1995-12-31T23:59:59.999Z  
  119.          All other components are mandatory.  
  120.   
  121.          Expressions can also be used to denote calculations that should be  
  122.          performed relative to "NOW" to determine the value, ie...  
  123.   
  124.                NOW/HOUR  
  125.                   ... Round to the start of the current hour  
  126.                NOW-1DAY  
  127.                   ... Exactly 1 day prior to now  
  128.                NOW/DAY+6MONTHS+3DAYS  
  129.                   ... 6 months and 3 days in the future from the start of  
  130.                       the current day  
  131.                         
  132.          Consult the DateField javadocs for more information.  
  133.   
  134.          Note: For faster range queries, consider the tdate type  
  135.       -->  
  136.     <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>  
  137.   
  138.     <!-- A Trie based date field for faster date range queries and date faceting. -->  
  139.     <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/>  
  140.   
  141.   
  142.     <!--Binary data type. The data should be sent/retrieved in as Base64 encoded Strings -->  
  143.     <fieldtype name="binary" class="solr.BinaryField"/>  
  144.   
  145.     <!--  
  146.       Note:  
  147.       These should only be used for compatibility with existing indexes (created with lucene or older Solr versions).  
  148.       Use Trie based fields instead. As of Solr 3.5 and 4.x, Trie based fields support sortMissingFirst/Last  
  149.   
  150.       Plain numeric field types that store and index the text  
  151.       value verbatim (and hence don't correctly support range queries, since the  
  152.       lexicographic ordering isn't equal to the numeric ordering)  
  153.   
  154.       NOTE: These field types are deprecated will be removed in Solr 5.0!  
  155.     -->  
  156.     <fieldType name="pint" class="solr.IntField"/>  
  157.     <fieldType name="plong" class="solr.LongField"/>  
  158.     <fieldType name="pfloat" class="solr.FloatField"/>  
  159.     <fieldType name="pdouble" class="solr.DoubleField"/>  
  160.     <fieldType name="pdate" class="solr.DateField" sortMissingLast="true"/>  
  161.   
  162.     <!-- The "RandomSortField" is not used to store or search any  
  163.          data.  You can declare fields of this type it in your schema  
  164.          to generate pseudo-random orderings of your docs for sorting   
  165.          or function purposes.  The ordering is generated based on the field  
  166.          name and the version of the index. As long as the index version  
  167.          remains unchanged, and the same field name is reused,  
  168.          the ordering of the docs will be consistent.    
  169.          If you want different psuedo-random orderings of documents,  
  170.          for the same version of the index, use a dynamicField and  
  171.          change the field name in the request.  
  172.      -->  
  173.     <fieldType name="random" class="solr.RandomSortField" indexed="true" />  
  174.   
  175.     <!-- solr.TextField allows the specification of custom text analyzers  
  176.          specified as a tokenizer and a list of token filters. Different  
  177.          analyzers may be specified for indexing and querying.  
  178.   
  179.          The optional positionIncrementGap puts space between multiple fields of  
  180.          this type on the same document, with the purpose of preventing false phrase  
  181.          matching across fields.  
  182.   
  183.          For more info on customizing your analyzer chain, please see  
  184.          http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters  
  185.      -->  
  186.   
  187.     <!-- One can also specify an existing Analyzer class that has a  
  188.          default constructor via the class attribute on the analyzer element.  
  189.          Example:  
  190.     <fieldType name="text_greek" class="solr.TextField">  
  191.       <analyzer class="org.apache.lucene.analysis.el.GreekAnalyzer"/>  
  192.     </fieldType>  
  193.     -->  
  194.   
  195.     <!-- A text field that only splits on whitespace for exact matching of words -->  
  196.     <fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">  
  197.       <analyzer>  
  198.         <tokenizer class="solr.WhitespaceTokenizerFactory"/>  
  199.       </analyzer>  
  200.     </fieldType>  
  201.   
  202.     <!-- A text type for English text where stopwords and synonyms are managed using the REST API -->  
  203.     <fieldType name="managed_en" class="solr.TextField" positionIncrementGap="100">  
  204.       <analyzer>  
  205.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  206.         <filter class="solr.ManagedStopFilterFactory" managed="english" />  
  207.         <filter class="solr.ManagedSynonymFilterFactory" managed="english" />  
  208.       </analyzer>  
  209.     </fieldType>  
  210.   
  211.     <!-- A general text field that has reasonable, generic  
  212.          cross-language defaults: it tokenizes with StandardTokenizer,  
  213.      removes stop words from case-insensitive "stopwords.txt"  
  214.      (empty by default), and down cases.  At query time only, it  
  215.      also applies synonyms. -->  
  216.     <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">  
  217.       <analyzer type="index">  
  218.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  219.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />  
  220.         <!-- in this example, we will only use synonyms at query time  
  221.         <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>  
  222.         -->  
  223.         <filter class="solr.LowerCaseFilterFactory"/>  
  224.       </analyzer>  
  225.       <analyzer type="query">  
  226.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  227.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />  
  228.         <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>  
  229.         <filter class="solr.LowerCaseFilterFactory"/>  
  230.       </analyzer>  
  231.     </fieldType>  
  232.   
  233.     <!-- A text field with defaults appropriate for English: it  
  234.          tokenizes with StandardTokenizer, removes English stop words  
  235.          (lang/stopwords_en.txt), down cases, protects words from protwords.txt, and  
  236.          finally applies Porter's stemming.  The query time analyzer  
  237.          also applies synonyms from synonyms.txt. -->  
  238.     <fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">  
  239.       <analyzer type="index">  
  240.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  241.         <!-- in this example, we will only use synonyms at query time  
  242.         <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>  
  243.         -->  
  244.         <!-- Case insensitive stop word removal. 
  245.         -->  
  246.         <filter class="solr.StopFilterFactory"  
  247.                 ignoreCase="true"  
  248.                 words="lang/stopwords_en.txt"  
  249.                 />  
  250.         <filter class="solr.LowerCaseFilterFactory"/>  
  251.     <filter class="solr.EnglishPossessiveFilterFactory"/>  
  252.         <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>  
  253.     <!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory:  
  254.         <filter class="solr.EnglishMinimalStemFilterFactory"/>  
  255.     -->  
  256.         <filter class="solr.PorterStemFilterFactory"/>  
  257.       </analyzer>  
  258.       <analyzer type="query">  
  259.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  260.         <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>  
  261.         <filter class="solr.StopFilterFactory"  
  262.                 ignoreCase="true"  
  263.                 words="lang/stopwords_en.txt"  
  264.                 />  
  265.         <filter class="solr.LowerCaseFilterFactory"/>  
  266.     <filter class="solr.EnglishPossessiveFilterFactory"/>  
  267.         <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>  
  268.     <!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory:  
  269.         <filter class="solr.EnglishMinimalStemFilterFactory"/>  
  270.     -->  
  271.         <filter class="solr.PorterStemFilterFactory"/>  
  272.       </analyzer>  
  273.     </fieldType>  
  274.   
  275.     <!-- A text field with defaults appropriate for English, plus  
  276.      aggressive word-splitting and autophrase features enabled.  
  277.      This field is just like text_en, except it adds  
  278.      WordDelimiterFilter to enable splitting and matching of  
  279.      words on case-change, alpha numeric boundaries, and  
  280.      non-alphanumeric chars.  This means certain compound word  
  281.      cases will work, for example query "wi fi" will match  
  282.      document "WiFi" or "wi-fi".  
  283.         -->  
  284.     <fieldType name="text_en_splitting" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">  
  285.       <analyzer type="index">  
  286.         <tokenizer class="solr.WhitespaceTokenizerFactory"/>  
  287.         <!-- in this example, we will only use synonyms at query time  
  288.         <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>  
  289.         -->  
  290.         <!-- Case insensitive stop word removal. 
  291.         -->  
  292.         <filter class="solr.StopFilterFactory"  
  293.                 ignoreCase="true"  
  294.                 words="lang/stopwords_en.txt"  
  295.                 />  
  296.         <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>  
  297.         <filter class="solr.LowerCaseFilterFactory"/>  
  298.         <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>  
  299.         <filter class="solr.PorterStemFilterFactory"/>  
  300.       </analyzer>  
  301.       <analyzer type="query">  
  302.         <tokenizer class="solr.WhitespaceTokenizerFactory"/>  
  303.         <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>  
  304.         <filter class="solr.StopFilterFactory"  
  305.                 ignoreCase="true"  
  306.                 words="lang/stopwords_en.txt"  
  307.                 />  
  308.         <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>  
  309.         <filter class="solr.LowerCaseFilterFactory"/>  
  310.         <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>  
  311.         <filter class="solr.PorterStemFilterFactory"/>  
  312.       </analyzer>  
  313.     </fieldType>  
  314.   
  315.     <!-- Less flexible matching, but less false matches.  Probably not ideal for product names,  
  316.          but may be good for SKUs.  Can insert dashes in the wrong place and still match. -->  
  317.     <fieldType name="text_en_splitting_tight" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">  
  318.       <analyzer>  
  319.         <tokenizer class="solr.WhitespaceTokenizerFactory"/>  
  320.         <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="false"/>  
  321.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt"/>  
  322.         <filter class="solr.WordDelimiterFilterFactory" generateWordParts="0" generateNumberParts="0" catenateWords="1" catenateNumbers="1" catenateAll="0"/>  
  323.         <filter class="solr.LowerCaseFilterFactory"/>  
  324.         <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>  
  325.         <filter class="solr.EnglishMinimalStemFilterFactory"/>  
  326.         <!-- this filter can remove any duplicate tokens that appear at the same position - sometimes  
  327.              possible with WordDelimiterFilter in conjuncton with stemming. -->  
  328.         <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>  
  329.       </analyzer>  
  330.     </fieldType>  
  331.   
  332.     <!-- Just like text_general except it reverses the characters of  
  333.      each token, to enable more efficient leading wildcard queries. -->  
  334.     <fieldType name="text_general_rev" class="solr.TextField" positionIncrementGap="100">  
  335.       <analyzer type="index">  
  336.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  337.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />  
  338.         <filter class="solr.LowerCaseFilterFactory"/>  
  339.         <filter class="solr.ReversedWildcardFilterFactory" withOriginal="true"  
  340.            maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33"/>  
  341.       </analyzer>  
  342.       <analyzer type="query">  
  343.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  344.         <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>  
  345.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />  
  346.         <filter class="solr.LowerCaseFilterFactory"/>  
  347.       </analyzer>  
  348.     </fieldType>  
  349.   
  350.     <!-- charFilter + WhitespaceTokenizer  -->  
  351.     <!--  
  352.     <fieldType name="text_char_norm" class="solr.TextField" positionIncrementGap="100" >  
  353.       <analyzer>  
  354.         <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>  
  355.         <tokenizer class="solr.WhitespaceTokenizerFactory"/>  
  356.       </analyzer>  
  357.     </fieldType>  
  358.     -->  
  359.   
  360.     <!-- This is an example of using the KeywordTokenizer along  
  361.          With various TokenFilterFactories to produce a sortable field  
  362.          that does not include some properties of the source text  
  363.       -->  
  364.     <fieldType name="alphaOnlySort" class="solr.TextField" sortMissingLast="true" omitNorms="true">  
  365.       <analyzer>  
  366.         <!-- KeywordTokenizer does no actual tokenizing, so the entire  
  367.              input string is preserved as a single token  
  368.           -->  
  369.         <tokenizer class="solr.KeywordTokenizerFactory"/>  
  370.         <!-- The LowerCase TokenFilter does what you expect, which can be  
  371.              when you want your sorting to be case insensitive  
  372.           -->  
  373.         <filter class="solr.LowerCaseFilterFactory" />  
  374.         <!-- The TrimFilter removes any leading or trailing whitespace -->  
  375.         <filter class="solr.TrimFilterFactory" />  
  376.         <!-- The PatternReplaceFilter gives you the flexibility to use  
  377.              Java Regular expression to replace any sequence of characters  
  378.              matching a pattern with an arbitrary replacement string,   
  379.              which may include back references to portions of the original  
  380.              string matched by the pattern.  
  381.                
  382.              See the Java Regular Expression documentation for more  
  383.              information on pattern and replacement string syntax.  
  384.                
  385.              http://docs.oracle.com/javase/7/docs/api/java/util/regex/package-summary.html  
  386.           -->  
  387.         <filter class="solr.PatternReplaceFilterFactory"  
  388.                 pattern="([^a-z])" replacement="" replace="all"  
  389.         />  
  390.       </analyzer>  
  391.     </fieldType>  
  392.       
  393.     <fieldtype name="phonetic" stored="false" indexed="true" class="solr.TextField" >  
  394.       <analyzer>  
  395.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  396.         <filter class="solr.DoubleMetaphoneFilterFactory" inject="false"/>  
  397.       </analyzer>  
  398.     </fieldtype>  
  399.   
  400.     <fieldtype name="payloads" stored="false" indexed="true" class="solr.TextField" >  
  401.       <analyzer>  
  402.         <tokenizer class="solr.WhitespaceTokenizerFactory"/>  
  403.         <!--  
  404.         The DelimitedPayloadTokenFilter can put payloads on tokens... for example,  
  405.         a token of "foo|1.4"  would be indexed as "foo" with a payload of 1.4f  
  406.         Attributes of the DelimitedPayloadTokenFilterFactory :   
  407.          "delimiter" - a one character delimiter. Default is | (pipe)  
  408.      "encoder" - how to encode the following value into a playload  
  409.         float -> org.apache.lucene.analysis.payloads.FloatEncoder,  
  410.         integer -> o.a.l.a.p.IntegerEncoder  
  411.         identity -> o.a.l.a.p.IdentityEncoder  
  412.             Fully Qualified class name implementing PayloadEncoder, Encoder must have a no arg constructor.  
  413.          -->  
  414.         <filter class="solr.DelimitedPayloadTokenFilterFactory" encoder="float"/>  
  415.       </analyzer>  
  416.     </fieldtype>  
  417.   
  418.     <!-- lowercases the entire field value, keeping it as a single token.  -->  
  419.     <fieldType name="lowercase" class="solr.TextField" positionIncrementGap="100">  
  420.       <analyzer>  
  421.         <tokenizer class="solr.KeywordTokenizerFactory"/>  
  422.         <filter class="solr.LowerCaseFilterFactory" />  
  423.       </analyzer>  
  424.     </fieldType>  
  425.   
  426.     <!--   
  427.       Example of using PathHierarchyTokenizerFactory at index time, so  
  428.       queries for paths match documents at that path, or in descendent paths  
  429.     -->  
  430.     <fieldType name="descendent_path" class="solr.TextField">  
  431.       <analyzer type="index">  
  432.     <tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/" />  
  433.       </analyzer>  
  434.       <analyzer type="query">  
  435.     <tokenizer class="solr.KeywordTokenizerFactory" />  
  436.       </analyzer>  
  437.     </fieldType>  
  438.     <!--   
  439.       Example of using PathHierarchyTokenizerFactory at query time, so  
  440.       queries for paths match documents at that path, or in ancestor paths  
  441.     -->  
  442.     <fieldType name="ancestor_path" class="solr.TextField">  
  443.       <analyzer type="index">  
  444.     <tokenizer class="solr.KeywordTokenizerFactory" />  
  445.       </analyzer>  
  446.       <analyzer type="query">  
  447.     <tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/" />  
  448.       </analyzer>  
  449.     </fieldType>  
  450.   
  451.     <!-- since fields of this type are by default not stored or indexed,  
  452.          any data added to them will be ignored outright.  -->   
  453.     <fieldtype name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField" />  
  454.   
  455.     <!-- This point type indexes the coordinates as separate fields (subFields)  
  456.       If subFieldType is defined, it references a type, and a dynamic field  
  457.       definition is created matching *___<typename>.  Alternately, if   
  458.       subFieldSuffix is defined, that is used to create the subFields.  
  459.       Example: if subFieldType="double", then the coordinates would be  
  460.         indexed in fields myloc_0___double,myloc_1___double.  
  461.       Example: if subFieldSuffix="_d" then the coordinates would be indexed  
  462.         in fields myloc_0_d,myloc_1_d  
  463.       The subFields are an implementation detail of the fieldType, and end  
  464.       users normally should not need to know about them.  
  465.      -->  
  466.     <fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>  
  467.   
  468.     <!-- A specialized field for geospatial search. If indexed, this fieldType must not be multivalued. -->  
  469.     <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>  
  470.   
  471.     <!-- An alternative geospatial field type new to Solr 4.  It supports multiValued and polygon shapes.  
  472.       For more information about this and other Spatial fields new to Solr 4, see:  
  473.       http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4  
  474.     -->  
  475.     <fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"  
  476.         geo="true" distErrPct="0.025" maxDistErr="0.000009" units="degrees" />  
  477.   
  478.    <!-- Money/currency field type. See http://wiki.apache.org/solr/MoneyFieldType  
  479.         Parameters:  
  480.           defaultCurrency: Specifies the default currency if none specified. Defaults to "USD"  
  481.           precisionStep:   Specifies the precisionStep for the TrieLong field used for the amount  
  482.           providerClass:   Lets you plug in other exchange provider backend:  
  483.                            solr.FileExchangeRateProvider is the default and takes one parameter:  
  484.                              currencyConfig: name of an xml file holding exchange rates  
  485.                            solr.OpenExchangeRatesOrgProvider uses rates from openexchangerates.org:  
  486.                              ratesFileLocation: URL or path to rates JSON file (default latest.json on the web)  
  487.                              refreshInterval: Number of minutes between each rates fetch (default: 1440, min: 60)  
  488.    -->  
  489.     <fieldType name="currency" class="solr.CurrencyField" precisionStep="8" defaultCurrency="USD" currencyConfig="currency.xml" />  
  490.                
  491.   
  492.   
  493.    <!-- some examples for different languages (generally ordered by ISO code) -->  
  494.   
  495.     <!-- Arabic -->  
  496.     <fieldType name="text_ar" class="solr.TextField" positionIncrementGap="100">  
  497.       <analyzer>   
  498.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  499.         <!-- for any non-arabic -->  
  500.         <filter class="solr.LowerCaseFilterFactory"/>  
  501.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ar.txt" />  
  502.         <!-- normalizes ﻯ to ﻱ, etc -->  
  503.         <filter class="solr.ArabicNormalizationFilterFactory"/>  
  504.         <filter class="solr.ArabicStemFilterFactory"/>  
  505.       </analyzer>  
  506.     </fieldType>  
  507.   
  508.     <!-- Bulgarian -->  
  509.     <fieldType name="text_bg" class="solr.TextField" positionIncrementGap="100">  
  510.       <analyzer>   
  511.         <tokenizer class="solr.StandardTokenizerFactory"/>   
  512.         <filter class="solr.LowerCaseFilterFactory"/>  
  513.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_bg.txt" />   
  514.         <filter class="solr.BulgarianStemFilterFactory"/>         
  515.       </analyzer>  
  516.     </fieldType>  
  517.       
  518.     <!-- Catalan -->  
  519.     <fieldType name="text_ca" class="solr.TextField" positionIncrementGap="100">  
  520.       <analyzer>   
  521.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  522.         <!-- removes l', etc -->  
  523.         <filter class="solr.ElisionFilterFactory" ignoreCase="true" articles="lang/contractions_ca.txt"/>  
  524.         <filter class="solr.LowerCaseFilterFactory"/>  
  525.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ca.txt" />  
  526.         <filter class="solr.SnowballPorterFilterFactory" language="Catalan"/>         
  527.       </analyzer>  
  528.     </fieldType>  
  529.       
  530.     <!-- CJK bigram (see text_ja for a Japanese configuration using morphological analysis) -->  
  531.     <fieldType name="text_cjk" class="solr.TextField" positionIncrementGap="100">  
  532.       <analyzer>  
  533.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  534.         <!-- normalize width before bigram, as e.g. half-width dakuten combine  -->  
  535.         <filter class="solr.CJKWidthFilterFactory"/>  
  536.         <!-- for any non-CJK -->  
  537.         <filter class="solr.LowerCaseFilterFactory"/>  
  538.         <filter class="solr.CJKBigramFilterFactory"/>  
  539.       </analyzer>  
  540.     </fieldType>  
  541.   
  542.     <!-- Kurdish -->  
  543.     <fieldType name="text_ckb" class="solr.TextField" positionIncrementGap="100">  
  544.       <analyzer>  
  545.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  546.         <filter class="solr.SoraniNormalizationFilterFactory"/>  
  547.         <!-- for any latin text -->  
  548.         <filter class="solr.LowerCaseFilterFactory"/>  
  549.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ckb.txt"/>  
  550.         <filter class="solr.SoraniStemFilterFactory"/>  
  551.       </analyzer>  
  552.     </fieldType>  
  553.   
  554.     <!-- Czech -->  
  555.     <fieldType name="text_cz" class="solr.TextField" positionIncrementGap="100">  
  556.       <analyzer>   
  557.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  558.         <filter class="solr.LowerCaseFilterFactory"/>  
  559.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_cz.txt" />  
  560.         <filter class="solr.CzechStemFilterFactory"/>         
  561.       </analyzer>  
  562.     </fieldType>  
  563.       
  564.     <!-- Danish -->  
  565.     <fieldType name="text_da" class="solr.TextField" positionIncrementGap="100">  
  566.       <analyzer>   
  567.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  568.         <filter class="solr.LowerCaseFilterFactory"/>  
  569.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_da.txt" format="snowball" />  
  570.         <filter class="solr.SnowballPorterFilterFactory" language="Danish"/>         
  571.       </analyzer>  
  572.     </fieldType>  
  573.       
  574.     <!-- German -->  
  575.     <fieldType name="text_de" class="solr.TextField" positionIncrementGap="100">  
  576.       <analyzer>   
  577.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  578.         <filter class="solr.LowerCaseFilterFactory"/>  
  579.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_de.txt" format="snowball" />  
  580.         <filter class="solr.GermanNormalizationFilterFactory"/>  
  581.         <filter class="solr.GermanLightStemFilterFactory"/>  
  582.         <!-- less aggressive: <filter class="solr.GermanMinimalStemFilterFactory"/> -->  
  583.         <!-- more aggressive: <filter class="solr.SnowballPorterFilterFactory" language="German2"/> -->  
  584.       </analyzer>  
  585.     </fieldType>  
  586.       
  587.     <!-- Greek -->  
  588.     <fieldType name="text_el" class="solr.TextField" positionIncrementGap="100">  
  589.       <analyzer>   
  590.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  591.         <!-- greek specific lowercase for sigma -->  
  592.         <filter class="solr.GreekLowerCaseFilterFactory"/>  
  593.         <filter class="solr.StopFilterFactory" ignoreCase="false" words="lang/stopwords_el.txt" />  
  594.         <filter class="solr.GreekStemFilterFactory"/>  
  595.       </analyzer>  
  596.     </fieldType>  
  597.       
  598.     <!-- Spanish -->  
  599.     <fieldType name="text_es" class="solr.TextField" positionIncrementGap="100">  
  600.       <analyzer>   
  601.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  602.         <filter class="solr.LowerCaseFilterFactory"/>  
  603.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_es.txt" format="snowball" />  
  604.         <filter class="solr.SpanishLightStemFilterFactory"/>  
  605.         <!-- more aggressive: <filter class="solr.SnowballPorterFilterFactory" language="Spanish"/> -->  
  606.       </analyzer>  
  607.     </fieldType>  
  608.       
  609.     <!-- Basque -->  
  610.     <fieldType name="text_eu" class="solr.TextField" positionIncrementGap="100">  
  611.       <analyzer>   
  612.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  613.         <filter class="solr.LowerCaseFilterFactory"/>  
  614.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_eu.txt" />  
  615.         <filter class="solr.SnowballPorterFilterFactory" language="Basque"/>  
  616.       </analyzer>  
  617.     </fieldType>  
  618.       
  619.     <!-- Persian -->  
  620.     <fieldType name="text_fa" class="solr.TextField" positionIncrementGap="100">  
  621.       <analyzer>  
  622.         <!-- for ZWNJ -->  
  623.         <charFilter class="solr.PersianCharFilterFactory"/>  
  624.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  625.         <filter class="solr.LowerCaseFilterFactory"/>  
  626.         <filter class="solr.ArabicNormalizationFilterFactory"/>  
  627.         <filter class="solr.PersianNormalizationFilterFactory"/>  
  628.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_fa.txt" />  
  629.       </analyzer>  
  630.     </fieldType>  
  631.       
  632.     <!-- Finnish -->  
  633.     <fieldType name="text_fi" class="solr.TextField" positionIncrementGap="100">  
  634.       <analyzer>   
  635.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  636.         <filter class="solr.LowerCaseFilterFactory"/>  
  637.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_fi.txt" format="snowball" />  
  638.         <filter class="solr.SnowballPorterFilterFactory" language="Finnish"/>  
  639.         <!-- less aggressive: <filter class="solr.FinnishLightStemFilterFactory"/> -->  
  640.       </analyzer>  
  641.     </fieldType>  
  642.       
  643.     <!-- French -->  
  644.     <fieldType name="text_fr" class="solr.TextField" positionIncrementGap="100">  
  645.       <analyzer>   
  646.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  647.         <!-- removes l', etc -->  
  648.         <filter class="solr.ElisionFilterFactory" ignoreCase="true" articles="lang/contractions_fr.txt"/>  
  649.         <filter class="solr.LowerCaseFilterFactory"/>  
  650.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_fr.txt" format="snowball" />  
  651.         <filter class="solr.FrenchLightStemFilterFactory"/>  
  652.         <!-- less aggressive: <filter class="solr.FrenchMinimalStemFilterFactory"/> -->  
  653.         <!-- more aggressive: <filter class="solr.SnowballPorterFilterFactory" language="French"/> -->  
  654.       </analyzer>  
  655.     </fieldType>  
  656.       
  657.     <!-- Irish -->  
  658.     <fieldType name="text_ga" class="solr.TextField" positionIncrementGap="100">  
  659.       <analyzer>   
  660.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  661.         <!-- removes d', etc -->  
  662.         <filter class="solr.ElisionFilterFactory" ignoreCase="true" articles="lang/contractions_ga.txt"/>  
  663.         <!-- removes n-, etc. position increments is intentionally false! -->  
  664.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/hyphenations_ga.txt"/>  
  665.         <filter class="solr.IrishLowerCaseFilterFactory"/>  
  666.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ga.txt"/>  
  667.         <filter class="solr.SnowballPorterFilterFactory" language="Irish"/>  
  668.       </analyzer>  
  669.     </fieldType>  
  670.       
  671.     <!-- Galician -->  
  672.     <fieldType name="text_gl" class="solr.TextField" positionIncrementGap="100">  
  673.       <analyzer>   
  674.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  675.         <filter class="solr.LowerCaseFilterFactory"/>  
  676.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_gl.txt" />  
  677.         <filter class="solr.GalicianStemFilterFactory"/>  
  678.         <!-- less aggressive: <filter class="solr.GalicianMinimalStemFilterFactory"/> -->  
  679.       </analyzer>  
  680.     </fieldType>  
  681.       
  682.     <!-- Hindi -->  
  683.     <fieldType name="text_hi" class="solr.TextField" positionIncrementGap="100">  
  684.       <analyzer>   
  685.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  686.         <filter class="solr.LowerCaseFilterFactory"/>  
  687.         <!-- normalizes unicode representation -->  
  688.         <filter class="solr.IndicNormalizationFilterFactory"/>  
  689.         <!-- normalizes variation in spelling -->  
  690.         <filter class="solr.HindiNormalizationFilterFactory"/>  
  691.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_hi.txt" />  
  692.         <filter class="solr.HindiStemFilterFactory"/>  
  693.       </analyzer>  
  694.     </fieldType>  
  695.       
  696.     <!-- Hungarian -->  
  697.     <fieldType name="text_hu" class="solr.TextField" positionIncrementGap="100">  
  698.       <analyzer>   
  699.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  700.         <filter class="solr.LowerCaseFilterFactory"/>  
  701.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_hu.txt" format="snowball" />  
  702.         <filter class="solr.SnowballPorterFilterFactory" language="Hungarian"/>  
  703.         <!-- less aggressive: <filter class="solr.HungarianLightStemFilterFactory"/> -->     
  704.       </analyzer>  
  705.     </fieldType>  
  706.       
  707.     <!-- Armenian -->  
  708.     <fieldType name="text_hy" class="solr.TextField" positionIncrementGap="100">  
  709.       <analyzer>   
  710.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  711.         <filter class="solr.LowerCaseFilterFactory"/>  
  712.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_hy.txt" />  
  713.         <filter class="solr.SnowballPorterFilterFactory" language="Armenian"/>  
  714.       </analyzer>  
  715.     </fieldType>  
  716.       
  717.     <!-- Indonesian -->  
  718.     <fieldType name="text_id" class="solr.TextField" positionIncrementGap="100">  
  719.       <analyzer>   
  720.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  721.         <filter class="solr.LowerCaseFilterFactory"/>  
  722.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_id.txt" />  
  723.         <!-- for a less aggressive approach (only inflectional suffixes), set stemDerivational to false -->  
  724.         <filter class="solr.IndonesianStemFilterFactory" stemDerivational="true"/>  
  725.       </analyzer>  
  726.     </fieldType>  
  727.       
  728.     <!-- Italian -->  
  729.     <fieldType name="text_it" class="solr.TextField" positionIncrementGap="100">  
  730.       <analyzer>   
  731.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  732.         <!-- removes l', etc -->  
  733.         <filter class="solr.ElisionFilterFactory" ignoreCase="true" articles="lang/contractions_it.txt"/>  
  734.         <filter class="solr.LowerCaseFilterFactory"/>  
  735.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_it.txt" format="snowball" />  
  736.         <filter class="solr.ItalianLightStemFilterFactory"/>  
  737.         <!-- more aggressive: <filter class="solr.SnowballPorterFilterFactory" language="Italian"/> -->  
  738.       </analyzer>  
  739.     </fieldType>  
  740.       
  741.     <!-- Japanese using morphological analysis (see text_cjk for a configuration using bigramming)  
  742.   
  743.          NOTE: If you want to optimize search for precision, use default operator AND in your query  
  744.          parser config with <solrQueryParser defaultOperator="AND"/> further down in this file.  Use   
  745.          OR if you would like to optimize for recall (default).  
  746.     -->  
  747.     <fieldType name="text_ja" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="false">  
  748.       <analyzer>  
  749.       <!-- Kuromoji Japanese morphological analyzer/tokenizer (JapaneseTokenizer)  
  750.   
  751.            Kuromoji has a search mode (default) that does segmentation useful for search.  A heuristic  
  752.            is used to segment compounds into its parts and the compound itself is kept as synonym.  
  753.   
  754.            Valid values for attribute mode are:  
  755.               normal: regular segmentation  
  756.               search: segmentation useful for search with synonyms compounds (default)  
  757.             extended: same as search mode, but unigrams unknown words (experimental)  
  758.   
  759.            For some applications it might be good to use search mode for indexing and normal mode for  
  760.            queries to reduce recall and prevent parts of compounds from being matched and highlighted.  
  761.            Use <analyzer type="index"> and <analyzer type="query"> for this and mode normal in query.  
  762.   
  763.            Kuromoji also has a convenient user dictionary feature that allows overriding the statistical  
  764.            model with your own entries for segmentation, part-of-speech tags and readings without a need  
  765.            to specify weights.  Notice that user dictionaries have not been subject to extensive testing.  
  766.   
  767.            User dictionary attributes are:  
  768.                      userDictionary: user dictionary filename  
  769.              userDictionaryEncoding: user dictionary encoding (default is UTF-8)  
  770.   
  771.            See lang/userdict_ja.txt for a sample user dictionary file.  
  772.   
  773.            Punctuation characters are discarded by default.  Use discardPunctuation="false" to keep them.  
  774.   
  775.            See http://wiki.apache.org/solr/JapaneseLanguageSupport for more on Japanese language support.  
  776.         -->  
  777.         <tokenizer class="solr.JapaneseTokenizerFactory" mode="search"/>  
  778.         <!--<tokenizer class="solr.JapaneseTokenizerFactory" mode="search" userDictionary="lang/userdict_ja.txt"/>-->  
  779.         <!-- Reduces inflected verbs and adjectives to their base/dictionary forms (辞書形) -->  
  780.         <filter class="solr.JapaneseBaseFormFilterFactory"/>  
  781.         <!-- Removes tokens with certain part-of-speech tags -->  
  782.         <filter class="solr.JapanesePartOfSpeechStopFilterFactory" tags="lang/stoptags_ja.txt" />  
  783.         <!-- Normalizes full-width romaji to half-width and half-width kana to full-width (Unicode NFKC subset) -->  
  784.         <filter class="solr.CJKWidthFilterFactory"/>  
  785.         <!-- Removes common tokens typically not useful for search, but have a negative effect on ranking -->  
  786.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ja.txt" />  
  787.         <!-- Normalizes common katakana spelling variations by removing any last long sound character (U+30FC) -->  
  788.         <filter class="solr.JapaneseKatakanaStemFilterFactory" minimumLength="4"/>  
  789.         <!-- Lower-cases romaji characters -->  
  790.         <filter class="solr.LowerCaseFilterFactory"/>  
  791.       </analyzer>  
  792.     </fieldType>  
  793.       
  794.     <!-- Latvian -->  
  795.     <fieldType name="text_lv" class="solr.TextField" positionIncrementGap="100">  
  796.       <analyzer>   
  797.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  798.         <filter class="solr.LowerCaseFilterFactory"/>  
  799.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_lv.txt" />  
  800.         <filter class="solr.LatvianStemFilterFactory"/>  
  801.       </analyzer>  
  802.     </fieldType>  
  803.       
  804.     <!-- Dutch -->  
  805.     <fieldType name="text_nl" class="solr.TextField" positionIncrementGap="100">  
  806.       <analyzer>   
  807.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  808.         <filter class="solr.LowerCaseFilterFactory"/>  
  809.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_nl.txt" format="snowball" />  
  810.         <filter class="solr.StemmerOverrideFilterFactory" dictionary="lang/stemdict_nl.txt" ignoreCase="false"/>  
  811.         <filter class="solr.SnowballPorterFilterFactory" language="Dutch"/>  
  812.       </analyzer>  
  813.     </fieldType>  
  814.       
  815.     <!-- Norwegian -->  
  816.     <fieldType name="text_no" class="solr.TextField" positionIncrementGap="100">  
  817.       <analyzer>   
  818.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  819.         <filter class="solr.LowerCaseFilterFactory"/>  
  820.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_no.txt" format="snowball" />  
  821.         <filter class="solr.SnowballPorterFilterFactory" language="Norwegian"/>  
  822.         <!-- less aggressive: <filter class="solr.NorwegianLightStemFilterFactory" variant="nb"/> -->  
  823.         <!-- singular/plural: <filter class="solr.NorwegianMinimalStemFilterFactory" variant="nb"/> -->  
  824.         <!-- The "light" and "minimal" stemmers support variants: nb=Bokmål, nn=Nynorsk, no=Both -->  
  825.       </analyzer>  
  826.     </fieldType>  
  827.       
  828.     <!-- Portuguese -->  
  829.     <fieldType name="text_pt" class="solr.TextField" positionIncrementGap="100">  
  830.       <analyzer>   
  831.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  832.         <filter class="solr.LowerCaseFilterFactory"/>  
  833.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_pt.txt" format="snowball" />  
  834.         <filter class="solr.PortugueseLightStemFilterFactory"/>  
  835.         <!-- less aggressive: <filter class="solr.PortugueseMinimalStemFilterFactory"/> -->  
  836.         <!-- more aggressive: <filter class="solr.SnowballPorterFilterFactory" language="Portuguese"/> -->  
  837.         <!-- most aggressive: <filter class="solr.PortugueseStemFilterFactory"/> -->  
  838.       </analyzer>  
  839.     </fieldType>  
  840.       
  841.     <!-- Romanian -->  
  842.     <fieldType name="text_ro" class="solr.TextField" positionIncrementGap="100">  
  843.       <analyzer>   
  844.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  845.         <filter class="solr.LowerCaseFilterFactory"/>  
  846.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ro.txt" />  
  847.         <filter class="solr.SnowballPorterFilterFactory" language="Romanian"/>  
  848.       </analyzer>  
  849.     </fieldType>  
  850.       
  851.     <!-- Russian -->  
  852.     <fieldType name="text_ru" class="solr.TextField" positionIncrementGap="100">  
  853.       <analyzer>   
  854.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  855.         <filter class="solr.LowerCaseFilterFactory"/>  
  856.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ru.txt" format="snowball" />  
  857.         <filter class="solr.SnowballPorterFilterFactory" language="Russian"/>  
  858.         <!-- less aggressive: <filter class="solr.RussianLightStemFilterFactory"/> -->  
  859.       </analyzer>  
  860.     </fieldType>  
  861.       
  862.     <!-- Swedish -->  
  863.     <fieldType name="text_sv" class="solr.TextField" positionIncrementGap="100">  
  864.       <analyzer>   
  865.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  866.         <filter class="solr.LowerCaseFilterFactory"/>  
  867.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_sv.txt" format="snowball" />  
  868.         <filter class="solr.SnowballPorterFilterFactory" language="Swedish"/>  
  869.         <!-- less aggressive: <filter class="solr.SwedishLightStemFilterFactory"/> -->  
  870.       </analyzer>  
  871.     </fieldType>  
  872.       
  873.     <!-- Thai -->  
  874.     <fieldType name="text_th" class="solr.TextField" positionIncrementGap="100">  
  875.       <analyzer>   
  876.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  877.         <filter class="solr.LowerCaseFilterFactory"/>  
  878.         <filter class="solr.ThaiWordFilterFactory"/>  
  879.         <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_th.txt" />  
  880.       </analyzer>  
  881.     </fieldType>  
  882.       
  883.     <!-- Turkish -->  
  884.     <fieldType name="text_tr" class="solr.TextField" positionIncrementGap="100">  
  885.       <analyzer>   
  886.         <tokenizer class="solr.StandardTokenizerFactory"/>  
  887.         <filter class="solr.ApostropheFilterFactory"/>  
  888.         <filter class="solr.TurkishLowerCaseFilterFactory"/>  
  889.         <filter class="solr.StopFilterFactory" ignoreCase="false" words="lang/stopwords_tr.txt" />  
  890.         <filter class="solr.SnowballPorterFilterFactory" language="Turkish"/>  
  891.       </analyzer>  
  892.     </fieldType>  
  893.     
  894.   <!-- Similarity is the scoring routine for each document vs. a query.  
  895.        A custom Similarity or SimilarityFactory may be specified here, but   
  896.        the default is fine for most applications.    
  897.        For more info: http://wiki.apache.org/solr/SchemaXml#Similarity  
  898.     -->  
  899.   <!--  
  900.      <similarity class="com.example.solr.CustomSimilarityFactory">  
  901.        <str name="paramkey">param value</str>  
  902.      </similarity>  
  903.     -->  
  904.   
  905. </schema>  


          3.创建序列化器

            

[csharp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. public class Product  
  2.    {  
  3.   
  4.        /// <summary>  
  5.        /// 产品编码  
  6.        /// </summary>  
  7.        public string ProductCode { getset; }  
  8.   
  9.        /// <summary>  
  10.        /// 产品名称  
  11.        /// </summary>  
  12.        public string ProductName { getset; }  
  13.    }  
  14.   
  15.    /// <summary>  
  16.    /// 反序列化器  
  17.    /// </summary>  
  18.    class ProductDeserializer : IObjectDeserializer<Product>  
  19.    {  
  20.        public IEnumerable<Product> Deserialize(SolrDocumentList result)  
  21.        {  
  22.            foreach (SolrDocument doc in result)  
  23.            {  
  24.                yield return new Product()  
  25.                {  
  26.                    ProductCode = doc["ProductCode"].ToString(),  
  27.                    ProductName = doc["ProductName"].ToString()  
  28.   
  29.                };  
  30.            }  
  31.        }  
  32.    }  


          4.查询数据

            

[csharp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. static OptimizeOptions optimizeOptions = new OptimizeOptions();  
  2. static ISolrResponseParser<NamedList, ResponseHeader> binaryResponseHeaderParser = new BinaryResponseHeaderParser();  
  3. static IUpdateParametersConvert<NamedList> updateParametersConvert = new BinaryUpdateParametersConvert();  
  4. static ISolrUpdateConnection<NamedList, NamedList> solrUpdateConnection = new SolrUpdateConnection<NamedList, NamedList>() { ServerUrl = "http://localhost:8040/Solr/" };  
  5. static ISolrUpdateOperations<NamedList> updateOperations = new SolrUpdateOperations<NamedList, NamedList>(solrUpdateConnection, updateParametersConvert) { ResponseWriter = "javabin" };  
  6.   
  7. static ISolrQueryConnection<NamedList> connection = new SolrQueryConnection<NamedList>() { ServerUrl = "http://localhost:8040/Solr/" };  
  8. static ISolrQueryOperations<NamedList> operations = new SolrQueryOperations<NamedList>(connection) { ResponseWriter = "javabin" };  
  9.   
  10. static IObjectDeserializer<Product> exampleDeserializer = new ProductDeserializer();  
  11. static ISolrResponseParser<NamedList, QueryResults<Product>> binaryQueryResultsParser = new BinaryQueryResultsParser<Product>(exampleDeserializer);  
  12.   
  13. public void Query()  
  14. {  
  15.     //查询  
  16.     var result = operations.Query("collection1""/select", SolrQuery.All, null);  
  17.     var header = binaryResponseHeaderParser.Parse(result);  
  18.     var examples = binaryQueryResultsParser.Parse(result);  
  19.     this.dataGridView1.DataSource = examples.ToList();  
  20. }  
  21. private void button2_Click(object sender, EventArgs e)  
  22. {  
  23.     Query();  
  24.   
  25. }  


          5.添加索引数据

          

[csharp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. private void button1_Click(object sender, EventArgs e)  
  2. {  
  3.     if (string.IsNullOrWhiteSpace(textBox1.Text)||string.IsNullOrWhiteSpace(textBox2.Text))  
  4.     {  
  5.         MessageBox.Show("编码和名称不能为空");  
  6.         return;  
  7.     }  
  8.   
  9.     var docs = new List<SolrInputDocument>();  
  10.     var doc = new SolrInputDocument();  
  11.     doc.Add("ProductCode"new SolrInputField("ProductCode",textBox1.Text));  
  12.     doc.Add("ProductName"new SolrInputField("ProductName",textBox2.Text));  
  13.     docs.Add(doc);  
  14.     var result = updateOperations.Update("collection1""/update"new UpdateOptions() { OptimizeOptions = optimizeOptions, Docs = docs });  
  15.     var header = binaryResponseHeaderParser.Parse(result);  
  16.   
  17.     this.DialogResult = DialogResult.OK;  
  18. }  


       6.删除索引数据

      

[csharp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. private void button3_Click(object sender, EventArgs e)  
  2.      {  
  3.          //删除  
  4.          if (this.dataGridView1.SelectedRows.Count != 1)  
  5.          {  
  6.              return;  
  7.          }  
  8.   
  9.          string code = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();  
  10.          var result = updateOperations.Update("collection1""/update"new UpdateOptions() { OptimizeOptions = optimizeOptions, DelById = new string[] { code } });  
  11.          var header = binaryResponseHeaderParser.Parse(result);  
  12.   
  13.          System.Console.WriteLine(string.Format("Update Status:{0} QTime:{1}", header.Status, header.QTime));  
  14.          System.Console.ReadLine();  
  15.          Query();  
  16.      }  


              有兴趣的同学可以加QQ群

             Demo下载:http://download.csdn.net/detail/zx13525079024/7296129

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值