solr之模糊搜索(Fuzzy matching)
solr的模糊搜索主要有通配符,范围查询,近距离搜索等几类。下面分别探讨一下用法。
1. 通配符查询
通配符只是对单个term有效,对短语不起作用,ps:短语就是在查询条件上加双引号,比如 title:”xxx yyy”。
其实也就跟一般的通配符的匹配方式差不多了,比如我要查询title里有evaluat开头的文档:
title:evaluat*
- 1
Note that:查询语句里一定要用小写,还没研究清楚大小写的区分,但是用大写的不行
另外通配符有很大的性能开销,尤其在匹配到大量数据时,比如:e*,建议不要这样用。
其他例子:
title:evaluat* cipro
- 1
title:evaluat?
- 1
solr in action 例子:
Query: offi* Matches office, officer, official, and so on
Query: off*r Matches offer, officer, officiator, and so on
Query: off?r Matches offer, but not officer
Works: softwar* eng?neering
Does not work: "softwar* eng?neering"
- 1
- 2
- 3
- 4
- 5
- 6
2. 范围查询
范围查询可以支持时间范围,数值范围,字符串范围等
1. 时间范围:
查询2015-06-07T19:11:45Z TO 2015-06-10T19:11:45Z这个范围的文档,这里要注意格式必须是solr的日期格式,也就是2015-06-07T19:11:45Z这样的格式,必须大写TO
received_date:[2015-06-07T19:11:45Z TO 2015-06-10T19:11:45Z]
- 1
- 数值范围
Query: yearsOld:[18 TO 21] Matches 18, 19, 20, 21
- 1
- 文本范围
source:[kyowa TO kyowb]
- 1
实际匹配kyowa ….kyowb => a->b的范围,也就是只能包含kyowa, kyowb这两个单词
solr in action 例子:
Query: created:[2012-02-01T00:00.0Z TO 2012-08-02T00:00.0Z]
Query: title:[boat TO boulder] Matches boat, boil, book, boulder, etc.
Query: price:[12.99 TO 14.99] Matches 12.99, 13.000009, 14.99, etc
// 这是带边界的例子
Query: yearsOld:{18 TO 21} Matches 19 and 20 but not 18 or 21
Query: yearsOld:[18 TO 21} Matches 18, 19, 20, but not 21
- 1
- 2
- 3
- 4
- 5
- 6
3. 近距离搜索(FUZZY/EDIT-DISTANCE SEARCHING/PROXIMITY SEARCHING)
- EDIT-DISTANCE SEARCHING
这主要是为了解决输入错误的问题,比如输入good时错误的输入为goob了怎么办,solr用波浪…….
线来容错,比如
source:kyowb~1
- 1
这里本来要输入kyowa,结果输成了kyowb,那么加上~1就能把正确的kyowa查询出来,~N也就是允许有几个编辑位置错误,这里是1个位置错误,如果你输入kyoab~1,就查询不出来了,因为输入错误两个位置,这时就需要~2了,默认情况下是~2.
1个位置错误时:
2个位置错误时:
fixed
solr in action 例子:
Query: administrator~1 Matches within one edit distance.
Query: administrator~2 Matches within two edit distances. (This is the default
if no edit distance is provided.)
Query: administrator~N Matches within N edit distances.
Please
- 1
- 2
- 3
- 4
- 5
- 邻近搜索(PROXIMITY SEARCHING)
这个功能主要用来解决短语的模糊搜索问题,比如你要查找chief executive officer,chief financial
officer,chief marketing officer….等等如chief x
officer的短语怎么办,用OR连起来显然麻烦,这就是邻近搜索的作用了,只需”chief officer”~1即可,~1表示chief
officer之间最多只有一个单词,是最多,不是只有一个,也可以是0个,如果有N个单词,即~N,注意,一定要加双引号,这才表示是短语,不然就是一个term了。
solr in action 例子:
Query: "chief officer"~1
– Meaning: chief and officer must be a maximum of one position away.
– Examples: "chief executive officer", "chief financial officer"
Query: "chief officer"~2
– Meaning: chief and officer must be a maximum of two edit distances away.
– Examples: "chief business development officer",
"officer chief"
Query: "chief officer"~N
– Meaning: Finds chief within N positions of officer.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
By David_Ao
solr之模糊搜索(Fuzzy matching)的更多相关文章
- solr :term 查询, phrase查询, boolean 查询
搜索总体有:term 查询, phrase查询, boolean 查询 1. SOLR搜索覆盖度和准确度保证的三个搜索方式: 保证准确率: AND: Search for two different ...
- Elasticsearch 常用基本查询
安装启动很简单,参考官网步骤:https://www.elastic.co/downloads/elasticsearch 为了介绍Elasticsearch中的不同查询类型,我们将对带有下列字段的文 ...
- [原]CentOS7部署PostGis
转载请注明原作者(think8848)和出处(http://think8848.cnblogs.com) 本文参考了<An almost idiot's guide to install Pos ...
- 10 行 Python 代码写的模糊查询
导语: 模糊匹配可以算是现代编辑器(在选择要打开的文件时)的一个必备特性了,它所做的就是根据用户输入的部分内容,猜测用户想要的文件名,并提供一个推荐列表供用户选择. 样例如下: Vim (Ctrl-P ...
- Linux下Awk详解(转载)
什么是Awk Awk是一种小巧的编程语言及命令行工具.(其名称得自于它的创始人Alfred Aho.Peter Weinberger 和 Brian Kernighan姓氏的首个字母).它非常适合服务 ...
- Query DSL for elasticsearch Query
Query DSL Query DSL (资料来自: http://www.elasticsearch.cn/guide/reference/query-dsl/) http://elasticsea ...
- Python的regex模块——更强大的正则表达式引擎
Python自带了正则表达式引擎(内置的re模块),但是不支持一些高级特性,比如下面这几个: 固化分组 Atomic grouping 占有优先量词 Possessive quantifi ...
- Python 代码实现模糊查询
Python 代码实现模糊查询 1.导语: 模糊匹配可以算是现代编辑器(如 Eclipse 等各种 IDE)的一个必备特性了,它所做的就是根据用户输入的部分内容,猜测用户想要的文件名,并提供一个推荐列 ...
- PostgreSQL9.1 with PostGIS 2.1.4 for mapping coordinates on linux/ubuntu 已经打包成deb 可下载
For location based service, I try to use postgresql with postgis. You can download postgis from here ...
随机推荐
- Python+Requests接口测试教程(2):requests
开讲前,告诉大家requests有他自己的官方文档:http://cn.python-requests.org/zh_CN/latest/ 2.1 发get请求 前言requests模块,也就是老污龟 ...
- 8.1 服务器开发 API 函数封装,select 优化服务器和客户端
#include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <ne ...
- node+mongoose使用例子
https://github.com/Aquarius1993/nodeNotes 功能 1. 注册 2. 登录 3. 修改密码 4. 修改头像 5. 获取用户笔记 6. 添加,删除,更新笔记 安装部 ...
- Learning from delayed reward (Q-Learning的提出) (Watkins博士毕业论文)(建立了现在的reinforcement Learning模型)
最近在在学习强化学习方面的东西, 对于现有的很多文章中关于强化学习的知识很是不理解,很多都是一个公式套一个公式,也没有什么太多的解释,感觉像是在看天书一般,经过了较长时间的挣扎最后决定从一些基础的东西 ...
- [LeetCode&Python] Problem 917. Reverse Only Letters
Given a string S, return the "reversed" string where all characters that are not a letter ...
- UVA 156:Ananagrams (vector+map+sort)
题意:一大堆单词中间有空格隔开,以'#'结束输出,问只出现一次的的单词有哪些(如果两个具有相同的长度,相同的字母也算是相同的,不区分大小写,如:noel和lone属于一个单词出现两次).最后按照字典序 ...
- WIFI_仿手机写wifi应用程序_WDS
2-1.1_15节_使用WIFI网卡6_仿手机写wifi操作程序============================== 1. 仿手机写一个WIFI操作程序,作为STA,有这几个功能:a. 自动扫 ...
- systemd学习笔记
一.systemd介绍 systemd即为system daemon,是linux下的一种init软件与多数发行版使用的System V风格init相比,systemd采用了以下新技术: (1) 采用 ...
- js 数组方法比较
js 数组方法比较 table th:first-of-type { width: 80px; } table th:nth-of-type(2) { width: 120px; } table th ...
- spring cloud 知识点
优秀的介绍资料: 资料 地址 spring cloud 中文网 https://springcloud.cc/ spring cloud 介绍 https://www.jianshu.com/p/74 ...