电商搜索中要实现这么一块功能,当输入文字时候。下拉框提示。类似于百度搜索

在师出名门的基于lucene的solr搜索引擎中。提供了 拼写检查和智能提示这块功能。

  拼写检查就是用来检查用户输入的检索内容是否存在,假设不存在则,给它提示出相近,或相似的内容。

  而检索建议则是用户输入某个检索条件后。会立马友好的给出一系列提示内容,并推荐首个出现的相似的词,作为推荐词。

也就是说 拼写检查是能够作为一个单独功能使用,但suggest一般引用拼写检查组件

实现过程。配置solrconfig.xml

  <searchComponent name="suggest" class="solr.SpellCheckComponent">
<!-- <str name="queryAnalyzerFieldType">text_general</str> -->
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<str name="field">article</str>
<float name="threshold">0.0001</float>
<!-- 使用自己定义suggest词库词能够将例如以下两行的凝视取消
<str name="sourceLocation">suggest.txt</str>
<str name="spellcheckIndexDir">spellchecker</str>
-->
<str name="comparatorClass">freq</str>
<str name="buildOnOptimize">true</str>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="solr.SearchHandler">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.count">11</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.extendedResults">false</str>
<str name="spellcheck.collate">true</str>
<!--<str name="spellcheck.build">true</str> -->
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>

重新启动solr服务。运行solrjclient代码

	/**
* @method: spellcheck
* @Description: 智能提示 Solr里叫做Suggest模块
*/
public static List<Map<String, String>> suggest(String word,String corename) {
SolrServer server=Indexer.getHttpSolrServer(corename);
List<Map<String, String>> wordList = new ArrayList<Map<String, String>>();
try {
SolrQuery query = new SolrQuery();
query.set("q", word);// 查询的词
query.set("qt", "/suggest");// 请求到suggest中
// query.set("spellcheck.count", "");// 返回数量
QueryResponse rsp = server.query(query); // 上面取结果的代码
SpellCheckResponse re = rsp.getSpellCheckResponse();// 获取拼写检查的结果集
if (re != null) {
for (Suggestion s : re.getSuggestions()) {
List<String> list = s.getAlternatives();// 获取全部 的检索词
for (String spellWord : list) {
Map<String, String> map = new HashMap<String, String>();
map.put("code", spellWord);
wordList.add(map);
}
}
// String t = re.getFirstSuggestion(word);// 获取第一个推荐词
}
} catch (Exception e) {
e.printStackTrace();
}
return wordList;
}

前端简单效果图:

智能提示(一) Solr (suggest)的更多相关文章

  1. solr suggest智能提示配置

    目录 配置文件 Java代码 遇到的问题 回到顶部 配置文件 solrconfig.xml <searchComponent name="suggest" class=&qu ...

  2. 搜索引擎keyword智能提示的一种实现

    问题背景 搜索关键字智能提示是一个搜索应用的标配.主要作用是避免用户输入错误的搜索词,并将用户引导到相应的关键词上,以提升用户搜索体验. 美团CRM系统中存在数以百万计的商家,为了让用户高速查找到目标 ...

  3. winform下的智能提示框

    winform下的智能提示框 最近在搞winform的程序,接触到有些可能以后还会用到的功能,所以写到博客园里去,第一可以加深自己的印象,第二可以在以后再遇到同样问题的时候忘记了可以马上回来看看,第三 ...

  4. jquery php 百度搜索框智能提示效果

    这个程序是利用php+ajax+jquery 实现的一个仿baidu智能提示的效果,有须要的朋友能够下载測试哦. 代码例如以下 index.html文件,保保存成index.htm <!DOCT ...

  5. Solr Suggest组件的使用

    使用suggest的原因,最主要就是相比于search速度快,In general, we need the autosuggest feature to satisfy two main requi ...

  6. Eclipse代码和xml文件的智能提示

    一.代码智能提示 Windows → Preferences → Java→ Editor → Content Assist 将 Auto activation delay(ms): 改为 0 将 A ...

  7. Laravel 安装代码智能提示扩展「laravel-ide-helper」

    ========================laravel-ide-helper======================== 使用 Laravel 框架IDE居然没有智能提示?这感觉实在太糟糕 ...

  8. 利用typescript使backbone强类型智能提示

    模型类一旦多了没有强类型和智能提示是相当痛苦的,所以. 仅仅用ts定义一个模型类: class Person extends Backbone.Model { defaults = { Name:&q ...

  9. Visual Studio Code 智能提示文件

    Visual Studio Code 开发前端和node智能提示 visual studio code 是一个很好的编辑器,可以用来编写前端代码和nodejs. 我很喜欢使用VSC,现在流行框架对VS ...

随机推荐

  1. HDU 1203 【01背包/小数/概率DP】

    I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...

  2. 51nod 1420 数袋鼠好有趣【贪心】

    1420 数袋鼠好有趣 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 有n只袋鼠.每只袋鼠的大小用一个整数表示. ...

  3. Mybatis批量添加,删除与修改

    1.批量添加元素session.insert(String string,object O) public void batchInsertStudent(){ List<Student> ...

  4. Nginx配置文件分析

    #user nobody; #启动进程数,即启动ngnix服务的个数,通常设置和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 #error_log logs/e ...

  5. [Bzoj5285][洛谷P4424][HNOI/AHOI2018]寻宝游戏(bitset)

    P4424 [HNOI/AHOI2018]寻宝游戏 某大学每年都会有一次Mystery Hunt的活动,玩家需要根据设置的线索解谜,找到宝藏的位置,前一年获胜的队伍可以获得这一年出题的机会. 作为新生 ...

  6. (转)Unity3D研究院之异步加载游戏场景与异步加载游戏资源进度条(三十一)

    http://www.xuanyusong.com/archives/1427  异步任务相信大家应该不会陌生,那么本章内容MOMO将带领大家学习Unity中的一些异步任务.在同步加载游戏场景的时候通 ...

  7. Apache2 httpd.conf 配置详解

    Apache2 httpd.conf 配置详解 <第一部分> 常用配置指令说明 1. ServerRoot:服务器的基础目录,一般来说它将包含conf/和logs/子目录,其它配置文件的相 ...

  8. 【转载】uboot的工具mkimage使用方法

    uboot源代码的tools/目录下有mkimage工具,这个工具可以用来制作不压缩或者压缩的多种可启动映象文件. mkimage在制作映象文件的时候,是在原来的可执行映象文件的前面加上一个0x40字 ...

  9. sql server 老外博客

    Aaron Bertrand Grant Fritchey Brent Ozar Thomas LaRock Pinal Dave Phil Factor SQL Skills w/ Paul Ran ...

  10. windows上的docker容器内安装vim

    Reading package lists... Done Building dependency tree Reading state information... Done E: Unable t ...