当前位置: 首页 > news >正文

企业为什么要自助建站/知乎推广渠道

企业为什么要自助建站,知乎推广渠道,路由器设置用来做网站空间吗,wordpress数据备份} 上述查询没有结果的原因,是因为"core java"被当做一个词项去查询了,而title的分词结果中只有"core"、"java"这些分词过的词项,并没有一个叫做"core java"的词项,所以搜不到结果&#…

}

上述查询没有结果的原因,是因为"core java"被当做一个词项去查询了,而title的分词结果中只有"core"、"java"这些分词过的词项,并没有一个叫做"core java"的词项,所以搜不到结果;

  1. 如果输入的查询条件"core java"也被做一次分词处理,再把处理结果"core"和"java"用来搜索,应该就能得到结果了,match query就是用来对输入条件做分词处理的,如下:

GET englishbooks/_search

{

“query”:{

“match”:{“title”:“Core Java”}

}

}

搜索结果如下,包含了java的两条记录都被查出来了:

{

“took”: 8,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 2,

“max_score”: 0.5754429,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “4”,

“_score”: 0.5754429,

“_source”: {

“id”: “4”,

“title”: “Thinking in Java”,

“language”: “java”,

“author”: “Bruce Eckel”,

“price”: 70.1,

“publish_time”: “2015-07-06”,

“description”: “Thinking in Java should be read cover to cover by every Java programmer, then kept close at hand for frequent reference. The exercises are challenging, and the chapter on Collections is superb!”

}

},

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “3”,

“_score”: 0.5753642,

“_source”: {

“id”: “3”,

“title”: “Core Java”,

“language”: “java”,

“author”: “Horstmann”,

“price”: 85.9,

“publish_time”: “2016-06-01”,

“description”: "The book is aimed at experienced programmers who want to learn how to write useful Java applications and applets. "

}

}

]

}

}

  1. 如果我们的本意是只要"Core Java"的匹配结果,上面的结果显然是不符合要求的,此时可以给查询条件加个"operator":"and"属性,就会查询匹配了所有关键词的文档,注意json的结构略有变化,以前title的属性是搜索条件,现在变成了一个json对象,里面的query属性是原来的搜索条件:

GET englishbooks/_search

{

“query”:{

“match”:{

“title”:{

“query”:“Core Java”,

“operator”:“and”

}

}

}

}

这次的搜索结果就是同时匹配了"core"和"java"两个词项的记录了(为什么core和java是小写? 因为"Core Java"被分词后改为了小写,再去搜索的):

{

“took”: 11,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 1,

“max_score”: 0.5753642,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “3”,

“_score”: 0.5753642,

“_source”: {

“id”: “3”,

“title”: “Core Java”,

“language”: “java”,

“author”: “Horstmann”,

“price”: 85.9,

“publish_time”: “2016-06-01”,

“description”: "The book is aimed at experienced programmers who want to learn how to write useful Java applications and applets. "

}

}

]

}

}

match_phrase搜索

match_phrase搜索和前面的match搜索相似,并且有以下两个特点:

  1. 分词后的所有词项都要匹配上,也就是前面的"operator":"and"属性的效果;

  2. 分析后的词项顺序要和搜索字段的顺序一致,才能匹配上;

GET englishbooks/_search

{

“query”:{

“match_phrase”:{“title”:“Core Java”}

}

}

上述查询可以搜索到结果,但如果将"Core Java"改成"Java Core"就搜不到结果了,但是match query用"Java Core"是可以搜到结果的;

match_phrase_prefix搜索

match_phrase_prefix的功能和前面的match_phrase类似,不过match_phrase_prefix支持最后一个词项做前缀匹配,如下所示,"Core J"这个搜索条件用match_phrase是搜不到结果的,但是match_phrase_prefix可以,因为"J"可以作为前缀和"Java"匹配:

GET englishbooks/_search

{

“query”:{

“match_phrase”:{“title”:“Core J”}

}

}

multi_match搜素

multi_match是在match的基础上支持多字段搜索,以下查询就是用"1986"和"deep"这两个词项,同时搜索title和description两个字段:

GET englishbooks/_search

{

“query”:{

“multi_match”:{

“query”:“1986 deep”,

“fields”:[“title”, “description”]

}

}

}

响应如下,可见title和description中含有词项"1986"或者"deep"的文档都被返回了:

{

“took”: 4,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 2,

“max_score”: 0.79237825,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “2”,

“_score”: 0.79237825,

“_source”: {

“id”: “2”,

“title”: “Compilers”,

“language”: “c”,

“author”: “Alfred V.Aho”,

“price”: 62.5,

“publish_time”: “2011-01-01”,

“description”: “In the time since the 1986 edition of this book, the world of compiler designhas changed significantly.”

}

},

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “1”,

“_score”: 0.2876821,

“_source”: {

“id”: “1”,

“title”: “Deep Learning”,

“language”: “python”,

“author”: “Yoshua Bengio”,

“price”: 549,

“publish_time”: “2016-11-18”,

“description”: “written by three experts in the field, deep learning is the only comprehensive book on the subject.”

}

}

]

}

}

terms query

terms是term查询的升级,用来查询多个词项:

GET englishbooks/_search

{

“query”:{

“terms”:{

“title”:[“deep”, “core”]

}

}

}

响应如下,title中含有deep和core的文档都被查到:

{

“took”: 5,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 2,

“max_score”: 1,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “1”,

“_score”: 1,

“_source”: {

“id”: “1”,

“title”: “Deep Learning”,

“language”: “python”,

“author”: “Yoshua Bengio”,

“price”: 549,

“publish_time”: “2016-11-18”,

“description”: “written by three experts in the field, deep learning is the only comprehensive book on the subject.”

}

},

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “3”,

“_score”: 1,

“_source”: {

“id”: “3”,

“title”: “Core Java”,

“language”: “java”,

“author”: “Horstmann”,

“price”: 85.9,

“publish_time”: “2016-06-01”,

“description”: "The book is aimed at experienced programmers who want to learn how to write useful Java applications and applets. "

}

}

]

}

}

范围查询

range query是范围查询,例如查询publish_time在"2016-01-01"到"2016-12-31"之间的文档:

GET englishbooks/_search

{

“query”:{

“range”:{

“publish_time”:{

“gte”:“2016-01-01”,

“lte”:“2016-12-31”,

“format”:“yyyy-MM-dd”

}

}

}

}

篇幅所限,此处略去返回结果;

exists query

exists query返回的是字段中至少有一个非空值的文档:

GET englishbooks/_search

{

“query”:{

“exists”:{

“field”:“author”

}

}

}

前缀查询

用于查询某个字段是否以给定前缀开始:

GET englishbooks/_search

{

“query”:{

“prefix”:{

“title”:“cor”

}

}

}

以上请求可以查到title字段为"Core Java"的文档:

{

“took”: 6,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 1,

“max_score”: 1,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “3”,

“_score”: 1,

“_source”: {

“id”: “3”,

“title”: “Core Java”,

“language”: “java”,

“author”: “Horstmann”,

“price”: 85.9,

“publish_time”: “2016-06-01”,

“description”: "The book is aimed at experienced programmers who want to learn how to write useful Java applications and applets. "

}

}

]

}

}

通配符查询

以下查询,可以搜到title字段中含有"core"的文档,另外需要注意的是,"?“匹配一个字符,”*"匹配零个或者多个字符:

GET englishbooks/_search

{

“query”:{

“wildcard”:{

“title”:“cor?”

}

}

}

正则表达式

使用属性regexp可以进行正则表达式查询,例如查找description字段带有4位数字的分词的文档:

GET englishbooks/_search

{

“query”:{

“regexp”:{

“description”:"[0-9]{4}"

}

}

}

查找结果如下,description字段中带有数字1986:

{

“took”: 4,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 1,

“max_score”: 1,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “2”,

“_score”: 1,

“_source”: {

“id”: “2”,

“title”: “Compilers”,

“language”: “c”,

“author”: “Alfred V.Aho”,

“price”: 62.5,

“publish_time”: “2011-01-01”,

“description”: “In the time since the 1986 edition of this book, the world of compiler designhas changed significantly.”

}

}

]

}

}

模糊查询(fuzzy query)

fuzzy是通过计算词项与文档的编辑距离来得到结果的,例如查找description

《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享

字段还有分词"1986"的时候,不小心输入了"1987",通过fuzzy查询也能得到结果,只是得分变低了,请求内容如下所示:

GET englishbooks/_search

{

“query”:{

“fuzzy”:{

“description”:“1987”

}

}

}

搜索到的文档如下所示,得分只有0.5942837,低于用"1986"查询的0.79237825:

{

“took”: 5,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 1,

“max_score”: 0.5942837,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “2”,

“_score”: 0.5942837,

“_source”: {

“id”: “2”,

“title”: “Compilers”,

“language”: “c”,

“author”: “Alfred V.Aho”,

“price”: 62.5,

“publish_time”: “2011-01-01”,

“description”: “In the time since the 1986 edition of this book, the world of compiler designhas changed significantly.”

}

}

]

}

}

需要注意的是,fuzzy查询时消耗资源较大;

复合查询

常用到的复合查询是bool query,可以用下表中的条件组合查询:

| 属性 | 作用 |

| — | — |

| must | 必须匹配,相当于SQL中的AND |

| should | 可以匹配,相当于SQL中的OR |

| must_not | 必须不匹配 |

| filter | 和must一样,但是不评分 |

以下条件,搜索的是title中带有java,但是不包含core的文档:

GET englishbooks/_search

{

“query”:{

“bool”:{

“must”:{

“term”:{“title”:“java”}

},

“must_not”:[

{“term”:{“title”:“core”}}

]

}

}

}

得到的文档中,带有core词项的已经被过滤了:

{

“took”: 3,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 1,

“max_score”: 0.5754429,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “4”,

“_score”: 0.5754429,

“_source”: {

“id”: “4”,

“title”: “Thinking in Java”,

“language”: “java”,

“author”: “Bruce Eckel”,

“price”: 70.1,

“publish_time”: “2015-07-06”,

“description”: “Thinking in Java should be read cover to cover by every Java programmer, then kept close at hand for frequent reference. The exercises are challenging, and the chapter on Collections is superb!”

}

}

]

}

}

脚本查询

可用脚本进行查询,如下是查询价格大于100的所有文档:

GET englishbooks/_search

{

“query”:{

“bool”:{

“must”:{

“script”:{

“script”:{

“inline”:“doc[‘price’].value>500”,

“lang”:“painless”

}

}

}

}

}

}

得到的结果只有price大于500的文档:

{

“took”: 8,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 1,

“max_score”: 1,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “1”,

“_score”: 1,

“_source”: {

“id”: “1”,

“title”: “Deep Learning”,

“language”: “python”,

“author”: “Yoshua Bengio”,

“price”: 549,

“publish_time”: “2016-11-18”,

“description”: “written by three experts in the field, deep learning is the only comprehensive book on the subject.”

}

}

]

}

}

指定排序字段

默认的排序方式是按照评分来排序的(也就是相关度排序),可以用sort属性来设置排序字段,下面的请求指定了按照price字段降序排序:

{

“query”:{

“term”:{“title”:“java”}

},

“sort”:[

{“price”:{“order”:“desc”}}

]

}

得到结果:

{

“took”: 4,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“skipped”: 0,

“failed”: 0

},

“hits”: {

“total”: 2,

“max_score”: null,

“hits”: [

{

“_index”: “englishbooks”,

“_type”: “IT”,

“_id”: “3”,

“_score”: null,

“_source”: {

“id”: “3”,

“title”: “Core Java”,

“language”: “java”,

“author”: “Horstmann”,

“price”: 85.9,

“publish_time”: “2016-06-01”,

“description”: "The book is aimed at experienced programmers who want to learn how to write useful Java applications and applets. "

},

“sort”: [

http://www.jmfq.cn/news/4747015.html

相关文章:

  • 网上兼职做效果图网站/网站关键词提升
  • 网站建设国内外研究进展/网上推广培训
  • wordpress主题 大/seo网站平台
  • 源代码代做网站/百度搜索词热度查询
  • 添加网站备案号链接/营销培训课程
  • 垂直门户网站/google store
  • 电商运营培训课程/谷歌优化排名怎么做
  • 网站开发明细/口碑营销策划方案
  • 杭州网站专业制作/网站排名优化怎么做
  • 专业企业网站建设公司价格/资源最全的网盘搜索引擎
  • 兰州优化网站推广/东莞网络营销优化
  • 《网站开发与应用》试题/百度极速版app下载
  • 网页制作的网站/选择宁波seo优化公司
  • 可以做音乐mv视频网站/网站权重查询工具
  • wordpress 欲思/南宁seo推广服务
  • 长沙房产集团网站建设/怎么在百度上推广产品
  • 惠州网站开发公司/成都网站关键词排名
  • 怎么制作网站的二维码/免费下载百度软件
  • 做av网站赚钱吗/谷歌sem服务商
  • 途牛网网站是哪家公司做的/百度一下子就知道了
  • 哪个网站可以做市场调研报告/百度推广优化工具
  • 厦门网站建设首选厦门一联网络/百度无锡营销中心
  • 网站开发包括什么/站长之家爱站网
  • 杭州网站建设响应式/seo营销课程培训
  • matlab代做网站/万网域名交易
  • 郑州中企业网站建设/找相似图片 识别
  • 自己在线制作logo免费生成器/常熟seo关键词优化公司
  • 施工建设集团网站/地推网
  • 推荐一些电商平台/首页排名优化公司
  • 上海网上做鸭子的网站/网络广告推广