<field name="hanzi" type="string" indexed="true" stored="false" multiValued="false"/> <field name="pinyin" type="kw_pinyin" indexed="true" stored="false" multiValued="true"/> <field name="py" type="kw_py" indexed="true" stored="false" multiValued="false" />
步骤2: 在schema.xml文件中添加如下配置。
然后把汉子转化成拼音和拼音首字母
<copyField source="
hanzi
" dest="pinyin"/> <copyField source="
hanzi
" dest="py"/>
<fieldType name="kw_pinyin" class="solr.TextField" positionIncrementGap="0"> <analyzer type="index"> <tokenizer class="solr.KeywordTokenizerFactory"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_cn.txt" /> <filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" minTermLenght="2" /> <filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" minGram="1" maxGram="20" /> </analyzer> <analyzer type="query"> <tokenizer class="solr.KeywordTokenizerFactory"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_cn.txt" /> </analyzer> </fieldType> <fieldType name="kw_py" class="solr.TextField" positionIncrementGap="0"> <analyzer type="index"> <tokenizer class="solr.KeywordTokenizerFactory"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_cn.txt" /> <filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" isFirstChar="true" minTermLenght="2"/> </analyzer> <analyzer type="query"> <tokenizer class="solr.KeywordTokenizerFactory"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_cn.txt" /> </analyzer> </fieldType>步骤3: 通过q=hanzi:value* OR pinyin:value OR py:value&fl:hanzi 如果想加权重还可以在q后面拼接字符串酒OK,比如 : defType:edismax
bf:abs(weight)^40 让某个分类、品牌、点击量等优先显示的权重设置。