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

在师出名门的基于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. [BZOJ1601][Usaco2008 Oct]灌水 最小生成树水题

    1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 2121  Solved: 1393[Submit][St ...

  2. HDU 3966 Aragorn's Story(树链剖分)(线段树区间修改)

    Aragorn's Story Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. django-useren配置

    http://bobbyong.com/blog/step-by-step-guide-on-configuring-django-userena/

  4. 在cnBlogs上使用MarsEdit发blog

    工欲善其事,必先利其器.既然决定了要经常使用blog,就要给自己一个好环境! 1.Mac下优秀的发博客工具--MarsEdit 网上有许多有用的文章教你如何使用它. 比如 http://fduo.or ...

  5. 关于spring.net的面向切面编程 (Aspect Oriented Programming with Spring.NET)-使用工厂创建代理(Using the ProxyFactoryObject to create AOP proxies)

    本文翻译自Spring.NET官方文档Version 1.3.2. 受限于个人知识水平,有些地方翻译可能不准确,但是我还是希望我的这些微薄的努力能为他人提供帮助. 侵删. 如果你正在为你的业务模型使用 ...

  6. IOS提示控件UIActionSheet,UIAlertView

    iphone中常用的消息提示控件,就是UIActionSheet和UIAlertView了,在Web开发中,UIActionSheet就像是confirm(),而UIAlertView就像是alert ...

  7. Javascript Apply和Call的使用

    Apply Function.apply(obj,args)方法能接收两个参数obj:这个对象将代替Function类里this对象args:这个是数组,它将作为参数传给Function(args-- ...

  8. asp.net原理笔记----页面控件类型,页面状况和asp.net编译过程

    通过查看asp.net的整个生命周期之后 了解到在aspx的页面生命周期中 调用了BuildControlTree()方法生成页面控件树 之后再调用Rend()方法根据控件树生成html返回 aspx ...

  9. 代码验证C#执行”文件打开关闭操作“耗时

    2017-04-19 部门经理习惯用C#做数据清洗,遇到个需要验证的问题,在一个万次左右循环内对文件执行打开关闭操作,比在循环前打开文件.循环后关闭文件耗时多多少. using System; usi ...

  10. iptables 的学习资源

    慕课网:https://www.imooc.com/video/7617 马哥linux视频:http://edu.51cto.com//center/course/lesson/index?id=9 ...