solr4.9 拼音检索

编程入门 行业动态 更新时间:2024-10-28 14:22:48

solr4.9  <a href=https://www.elefans.com/category/jswz/34/1767611.html style=拼音检索"/>

solr4.9 拼音检索

1、在apache-tomcat-8.0.9\webapps\solr\WEB-INF\lib目录下,添加pinyin4j-2.5.0.jar、pinyinAnalyzer4.3.1.jar、lucene-analyzers-smartcn-4.9.0.jar jar包

2、创建用于拼音检索的字段类型:

<fieldType name="text_pinyin" class="solr.TextField" positionIncrementGap="0"> <analyzer type="index"> <tokenizer class="org.apache.lucene.analysis.smart.SmartChineseSentenceTokenizerFactory"/> <filter class="org.apache.lucene.analysis.smart.SmartChineseWordTokenFilterFactory"/> <filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" minTermLenght="2" /> <filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" minGram="6" maxGram="20" /> </analyzer> <analyzer type="query"> <tokenizer class="org.apache.lucene.analysis.smart.SmartChineseSentenceTokenizerFactory" /> <filter class="org.apache.lucene.analysis.smart.SmartChineseWordTokenFilterFactory" /> <filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" minTermLenght="2" /> <filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" minGram="6" maxGram="20" /> </analyzer> 
</fieldType>

3、创建需要使用的拼音检索的字段

<field name="news_pinyin" type="text_pinyin" indexed="true" stored="true" multiValued="true" />
<copyField source="news_title" dest="news_pinyin" />
<copyField source="news_source" dest="news_pinyin" />


4、测试用例:

<span style="white-space:pre">	</span>/*** 拼音检索* @param pinyin 中文拼音串*/public static void pinyinQuery(String pinyin) {try {SolrServer server = SolrUtils.getInstance().getSolrServer();SolrQuery query = new SolrQuery();query.set("q", "news_pinyin:" + pinyin); QueryResponse qr = server.query(query); SolrDocumentList dlist = qr.getResults();System.out.println("总数:" + dlist.getNumFound());for (SolrDocument doc : dlist) {System.out.println("newsId: " + doc.getFieldValue("id").toString() + ", news_title: " + doc.getFieldValue("news_title") + ", news_source: " + doc.getFieldValue("news_source")+ ", url: " + doc.getFieldValue("source_url"));}} catch (SolrServerException e) {e.printStackTrace();}}



更多推荐

solr4.9 拼音检索

本文发布于:2024-03-06 18:22:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1716039.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:拼音

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!