Solr4.7如何实现拼写检查

技术solr4.7拼写检查怎么实现本篇内容主要讲解“solr4.7拼写检查怎么实现”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“solr4.7拼写检查怎么实现”吧!①拼写检查

本篇内容主要讲解“solr4.7拼写检查怎么实现",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“solr4.7拼写检查怎么实现"吧!

拼写检查不同于其他域,它在建立索引时需要分词,但是检索时不需要分词,所以要建立一个特殊的域,以供拼写检查:

在schema.xml文件里设置所需的拼写检查域都有哪些字段:

字段名=“拼写”类型=“文本_拼写”索引=“真”存储=“假”多字符=“真”

copyfield source=' name ' dest='拼写"/

copyFieldsource='content'dest='拼写'/

字段TYPeNAmE=' text _拼写' class=' Solr .TextField ' positionincrementgap=' 100 '

analyzertype='index '

tokenizerclass=' org。沃尔特。分析仪。露西。iktokenizerfactory ' usesmart=' false ' conf=' ik。conf /

filterclass='solr .stop filter factory ' ignore case=' true ' words=' stop words。“txt”使能位置增量=“真”/

/分析仪

analyzertype='query '

tokenizerclass='solr .WhitespaceTokenizerFactory'/

/分析仪

/fieldType在solrconfig.xml文件里设置:

搜索组件名称='拼写错误' class=' Solr ."拼写检查组件"

strname=' querylyzerfieldtype ' text _拼写/str

!-作为索引的一部分-

lstname='拼写检查器'

strname='name'default/str

strname='field '拼写/str

strname=' class name ' Solr。directsolrspellicker/str

strnbs

p;name="distanceMeasure">internal</str>
      <float name="accuracy">0.5</float>
      <int name="maxEdits">2</int>
      <int name="minPrefix">1</int>
      <int name="maxInspections">5</int>
      <int name="minQueryLength">2</int>
      <float name="maxQueryFrequency">0.01</float>
    </lst>
 <lst name="spellchecker">
   <str name="classname">solr.FileBasedSpellChecker</str>
   <str name="name">file</str>
   <str name="sourceLocation">spellings.txt</str>
   <str name="characterEncoding">UTF-8</str>
   <str name="spellcheckIndexDir">spellcheckerFile</str>
    </lst>
  </searchComponent>
  <requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
      <str name="df">spell</str>
      <str name="spellcheck.dictionary">default</str>
      <str name="spellcheck">on</str>
      <!-- <str name="spellcheck.extendedResults">true</str>       
      <str name="spellcheck.count">10</str>
      <str name="spellcheck.alternativeTermCount">5</str>
      <str name="spellcheck.maxResultsForSuggest">5</str> -->       
      <str name="spellcheck.collate">true</str>
      <str name="spellcheck.collateExtendedResults">true</str>  
      <!-- <str name="spellcheck.maxCollationTries">10</str>
      <str name="spellcheck.maxCollations">5</str> -->          
    </lst>
    <arr name="last-components">
      <str>spellerror</str>
    </arr>
  </requestHandler>

③solrj里的代码

/**
    * @method: testSpellCheck
    * @Description: 拼写检查 
    * 
    * @author: ChenYW
    * @date 2014-4-15 下午06:14:56
    */
    public String spellCheck(String word){
        SolrQuery query = new SolrQuery();  
        query.set("defType","edismax");//加权
        query.set("qf","name^20.0");
        
        query.set("spellcheck", "true");  
        query.set("spellcheck.q", word);
        query.set("qt", "/spell");  
        query.set("spellcheck.build", "true");//遇到新的检查词,会自动添加到索引里面  
        query.set("spellcheck.count", 5);
           
        try {  
         QueryResponse rsp = server.query(query);  
         SpellCheckResponse re=rsp.getSpellCheckResponse();  
         if (re != null) {  
          if(!re.isCorrectlySpelled()){
              String t = re.getFirstSuggestion(word);//获取第一个推荐词  
     System.out.println("推荐词:" + t);
     return t;
          }                  
         } 
        } catch (SolrServerException e) {  
            e.printStackTrace();  
        }  
        return null;
    }

到此,相信大家对“solr4.7拼写检查怎么实现”有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/155610.html

(0)

相关推荐

  • mysql中pt-online-schema-change怎么用

    技术mysql中pt-online-schema-change怎么用这篇文章主要介绍了mysql中pt-online-schema-change怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后

    攻略 2021年11月2日
  • Netty中怎么实现websocket发消息

    技术Netty中怎么实现websocket发消息本篇内容介绍了“Netty中怎么实现websocket发消息”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧

    攻略 2021年11月16日
  • Oracle11g新增视图查询表空间使用率分析

    技术Oracle11g新增视图查询表空间使用率分析本篇内容主要讲解“Oracle11g新增视图查询表空间使用率分析”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Oracle1

    攻略 2021年11月9日
  • properties文件怎么读取里面数据(properties文件数据怎么获取)

    技术怎样读取properties或yml文件数据并匹配今天就跟大家聊聊有关怎样读取properties或yml文件数据并匹配,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有

    攻略 2021年12月18日
  • 苏轼的古诗有哪些,苏轼写的诗有哪些,古诗三百首

    技术苏轼的古诗有哪些,苏轼写的诗有哪些,古诗三百首1、 《题西林壁》 宋代:苏轼 横看成岭侧成峰苏轼的古诗有哪些,远近高低各不同。 不识庐山真面目,只缘身在此山中。 2、 《饮湖上初晴后雨二首》 宋代:苏轼 水光潋滟晴方

    生活 2021年10月29日
  • netty组件化设计(net有类似netty的框架吗)

    技术基于NIO的网络编程框架Netty有哪些组件本篇内容介绍了“基于NIO的网络编程框架Netty有哪些组件”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧

    攻略 2021年12月21日