Dynamics 365的新特性Relevance Search介绍

【Dynamics 365的新特性Relevance Search介绍】知识的价值不在于占有,而在于使用。这篇文章主要讲述Dynamics 365的新特性Relevance Search介绍相关的知识,希望能为你提供帮助。
我是微软Dynamics 365 & Power Platform方面的工程师/顾问罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面的微软最有价值专家(Microsoft MVP),欢迎关注我的微信公众号 MSFTDynamics365erLuoYong ,回复441或者20210507可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!
Dynamics 365中搜索记录的方式有好几种,最常见的就是快速查找(Quick Find)和高级查找(Advanced Find),后来又新增了 Categorized Search,在2020 release wave 2中又新增了一种新的搜索体验Relevance Search (有些人翻译成关联搜索),这个Feature宣布的文档请见 New, improved global search experience in model-driven apps ,是在2020年11月GA的,默认是关闭的,但是它会逐步取代Categorized Search。Relevance Search是关闭的情况下,点击全局搜索图标出来的是 Categorized Search,效果如下。

Dynamics 365的新特性Relevance Search介绍

文章图片

我们参考官方文档 Configure Relevance Search to improve search results and performance 来启用和配置Relevance Search。登录 Power Platform admin center,选择要启用的Environment后,点击 Settings.
Dynamics 365的新特性Relevance Search介绍

文章图片

然后点击 Product > Features 。
Dynamics 365的新特性Relevance Search介绍

文章图片


将Search这个分组下 Relevance Search这个Feature设置为On状态然后保存就完成启用了。这是个Environment级别的全局选项,启用它会为这个Environment的所有Model-Driven App启用。
Dynamics 365的新特性Relevance Search介绍

文章图片


过一会儿Relevance Search就可以用了,界面如下:
Dynamics 365的新特性Relevance Search介绍

文章图片


搜索结果示例如下,对于这个体验比较全面的说明请参考官方文档Search for tables and rows by using relevance search ,我这里不一一讲解,摘录一些重要的简单翻译下。
对于这个搜索结果界面,Top results是按照关联性显示数据,按照表Table分组(Table以前叫实体Entity),最多显示20条数据。每条数据显示六个列,就是这个表的快速查找视图显示的前六个列,第一个列总是表的主属性字段。
然后横向的Tab的接下来的三个(第二个到第四个Tab)是按照关联性展示的三个表的搜索结果。
然后其他的Tab的顺序是按照查找表符合条件的记录数来排列的,符合条件记录数比较多的排在前面,少的排在后面。Tab标题中()中的数字便是该表搜索结果中符合条件的记录数。
右边有个Filters面板,可以方便地进行再筛选。
Dynamics 365的新特性Relevance Search介绍

文章图片

将鼠标放到搜搜结果的第一列旁边会出来一些快捷操作按钮,会出来那些呢?默认如下,摘自官方文档。可以对这些快捷按钮做定制吗?比如显示某些按钮,可以,使用 Mscrm.ShowOnQuickAction 类似这种Enable Rule让他仅仅显示在这个快捷操作中,而不显示在表单或者列表的按钮清单中,其他 ShowOnGridAndQuickAction 和 ShowOnGrid 两个Enable Rule的含义参考官方文档。
还可以看到Tab下面的那行字告知了搜索了这个实体的哪些字段。
Table Quick actions
Account Assign, Share, Email a link
Contact Assign, Share, Email a link
Appointment Mark complete, Cancel, Set Regarding, Assign, Email a link
Task Mark complete, Cancel, Set Regarding, Assign, Email a link
Phone Call Mark complete, Cancel, Set Regarding, Assign, Email a link
Email Cancel, Set Regarding, Email a link

Dynamics 365的新特性Relevance Search介绍

文章图片


一个自然的问题就是这个搜索的列包括哪些?首先能加入到作为被搜索列的需要是 Single line of text (单行文本), Multiple lines of text (多行文本), Choice (选项集), 或者 Lookup (查找)这些字段类型。其余的字段类型比如日期和数字是不支持搜索的。那怎么配置那些实体,以及这些实体的哪些列启用搜索呢。打开默认解决方案,选择左边的 Entities 节点,然后点击 Configure RElevance Search 按钮。
Dynamics 365的新特性Relevance Search介绍

文章图片


弹出来的界面如下,可以比较清楚的看到哪些实体已经加入到Relevance Search中,实体后括号中的数字则是这个实体有多少个字段加入到了Relevance Search中。
多少实体能加入到Relevance Search中没有规定上线,但是总计只有1000个字段能加入到Relevance Search中,这个窗口的左下角也显示了目前已经有多少个字段加入到Relevance Search中了。部分字段会自动加入到Relevance Search中,还有值得注意的是并不是一个字段就占用一个搜索字段的名额,有的会占用多个,怎么计算如下。还有个特别需要注意的就是Relevance Search的配置不能通过Solution解决方案进行迁移,需要手工到不同的环境进行配置,但是我的理解应该有API,如果你不辞辛劳,应该可以做个自动化部署小工具。
Field type Number of fields used in the Relevance Search index
Lookup (customer, owner, or Lookup type attribute) 3
Option Set (state, or status type attribute) 2
All other types of fields 1
Dynamics 365的新特性Relevance Search介绍

文章图片


那如何定义搜索实体的哪些字段呢?这个和修改实体的快速查找列是一样的,我就不详细说明了,简单来说就是打开实体的快速查找视图,点击【Add Find Columns】按钮来配置,当然这些对实体配置需要发布才会生效。
这里提一下常见的搜索操作符,逻辑操作符包括 逻辑且操作符 + ,逻辑或操作符 | ,逻辑否操作符 - ,还有通配符 * ,还有精确匹配操作符,就是将搜索文本用双引号引起来。
前面讲的都是界面上的操作,那么可以通过编程的方式执行Relevance Search吗?答案是可以的,参考官方文档 Search across table data using relevance search ,我这里演示个简单的代码如下,大概意思就是搜索 Lit,要求返回符合条件的记录数量(默认不返回),只对account实体进行搜索(默认对所有启用了Relevance Search的尸体进行搜索),返回符合条件的前100行(默认返回50行)。
var clientUrl = Xrm.Utility.getGlobalContext().getClientUrl(); var req = new XMLHttpRequest() req.open("POST", clientUrl + "/api/search/v1.0/query", true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { var responseJSON = JSON.parse(this.responseText); console.log(responseJSON); } else { var error = JSON.parse(this.responseText).error; Xrm.Utility.alertDialog("Error." + error.message); } } }; var reqContent = { "search": "Lit", "returntotalrecordcount": true, "entities":["account"], "top":100 }; req.send(JSON.stringify(reqContent));


我这里摘录下返回的内容如下:
{ "searchterms": "Lit", "value": [ { "@search.score": 8.6395950317382813, "@search.highlights": { "name": [ "City Power & {crmhit}Light{/crmhit} (sample)" ] }, "@search.entityname": "account", "@search.objectid": "6a76d7bb-3aa3-eb11-b1ac-00224816920b", "ownerid": "41833657-63a0-eb11-b1ac-00224816946c", "owneridname": "System Administrator", "@search.ownerid.logicalname": "systemuser", "@search.objecttypecode": 1, "name": "City Power & Light (sample)", "entityimage_url": null, "createdon": "4/22/2021 3:18 PM", "modifiedon": "4/22/2021 3:18 PM", "emailaddress1": "someone6@example.com", "address1_city": "Redmond", "@search.primarycontactid.logicalname": "contact", "primarycontactid": "d076d7bb-3aa3-eb11-b1ac-00224816920b", "primarycontactidname": "Scott Konersmann (sample)", "accountnumber": null, "telephone1": "555-0155" }, { "@search.score": 0.53000789880752563, "@search.highlights": { "name": [ "City Power & {crmhit}Light{/crmhit}" ] }, "@search.entityname": "account", "@search.objectid": "aea19cdd-88df-e311-b8e5-6c3be5a8b200", "ownerid": "4d833657-63a0-eb11-b1ac-00224816946c", "owneridname": "Allie Bellew (Sample Data)", "@search.ownerid.logicalname": "systemuser", "@search.objecttypecode": 1, "name": "City Power & Light", "entityimage_url": null, "createdon": "1/21/2017 6:39 AM", "modifiedon": "4/19/2021 12:56 AM", "emailaddress1": "walter@cpandl.com", "address1_city": "Los Angeles", "@search.primarycontactid.logicalname": "contact", "primarycontactid": null, "primarycontactidname": null, "accountnumber": "ACSHN2S4", "telephone1": "+1-785-555-1333" }, { "@search.score": 0.53000789880752563, "@search.highlights": { "name": [ "City Power & {crmhit}Light{/crmhit}" ] }, "@search.entityname": "account", "@search.objectid": "cb6b3f4b-1be7-e611-8101-e0071b6af231", "ownerid": "8c70e42a-19a0-eb11-b1ac-00224816946c", "owneridname": "--- ---", "@search.ownerid.logicalname": "systemuser", "@search.objecttypecode": 1, "name": "City Power & Light", "entityimage_url": null, "createdon": "4/19/2021 1:04 AM", "modifiedon": "4/19/2021 1:04 AM", "emailaddress1": null, "address1_city": "London", "@search.primarycontactid.logicalname": "contact", "primarycontactid": null, "primarycontactidname": null, "accountnumber": null, "telephone1": "+44 20 7946 9702" }, { "@search.score": -0.3622155487537384, "@search.highlights": { "name": [ "City Power & {crmhit}Light{/crmhit} Engineering" ] }, "@search.entityname": "account", "@search.objectid": "cd6b3f4b-1be7-e611-8101-e0071b6af231", "ownerid": "8c70e42a-19a0-eb11-b1ac-00224816946c", "owneridname": "--- ---", "@search.ownerid.logicalname": "systemuser", "@search.objecttypecode": 1, "name": "City Power & Light Engineering", "entityimage_url": null, "createdon": "4/19/2021 1:04 AM", "modifiedon": "4/19/2021 1:04 AM", "emailaddress1": null, "address1_city": "London", "@search.primarycontactid.logicalname": "contact", "primarycontactid": null, "primarycontactidname": null, "accountnumber": null, "telephone1": "+44 20 7946 6735" }, { "@search.score": -0.3622155487537384, "@search.highlights": { "name": [ "City Power & {crmhit}Light{/crmhit} Electronics" ] }, "@search.entityname": "account", "@search.objectid": "d16b3f4b-1be7-e611-8101-e0071b6af231", "ownerid": "8c70e42a-19a0-eb11-b1ac-00224816946c", "owneridname": "--- ---", "@search.ownerid.logicalname": "systemuser", "@search.objecttypecode": 1, "name": "City Power & Light Electronics", "entityimage_url": null, "createdon": "4/19/2021 1:04 AM", "modifiedon": "4/19/2021 1:04 AM", "emailaddress1": null, "address1_city": "Seattle", "@search.primarycontactid.logicalname": "contact", "primarycontactid": null, "primarycontactidname": null, "accountnumber": null, "telephone1": "425-555-8535" }, { "@search.score": -0.3622155487537384, "@search.highlights": { "name": [ "City Power & {crmhit}Light{/crmhit} Instrumentation" ] }, "@search.entityname": "account", "@search.objectid": "d36b3f4b-1be7-e611-8101-e0071b6af231", "ownerid": "8c70e42a-19a0-eb11-b1ac-00224816946c", "owneridname": "--- ---", "@search.ownerid.logicalname": "systemuser", "@search.objecttypecode": 1, "name": "City Power & Light Instrumentation", "entityimage_url": null, "createdon": "4/19/2021 1:04 AM", "modifiedon": "4/19/2021 1:04 AM", "emailaddress1": null, "address1_city": "Seattle", "@search.primarycontactid.logicalname": "contact", "primarycontactid": null, "primarycontactidname": null, "accountnumber": null, "telephone1": "425-555-1080" }, { "@search.score": -0.3622155487537384, "@search.highlights": { "name": [ "City Power & {crmhit}Light{/crmhit} Assembly" ] }, "@search.entityname": "account", "@search.objectid": "d56b3f4b-1be7-e611-8101-e0071b6af231", "ownerid": "8c70e42a-19a0-eb11-b1ac-00224816946c", "owneridname": "--- ---", "@search.ownerid.logicalname": "systemuser", "@search.objecttypecode": 1, "name": "City Power & Light Assembly", "entityimage_url": null, "createdon": "4/19/2021 1:04 AM", "modifiedon": "4/19/2021 1:04 AM", "emailaddress1": null, "address1_city": "Seattle", "@search.primarycontactid.logicalname": "contact", "primarycontactid": null, "primarycontactidname": null, "accountnumber": null, "telephone1": "425-555-7824" }, { "@search.score": -0.3622155487537384, "@search.highlights": { "name": [ "City Power & {crmhit}Light{/crmhit} Integration" ] }, "@search.entityname": "account", "@search.objectid": "d76b3f4b-1be7-e611-8101-e0071b6af231", "ownerid": "8c70e42a-19a0-eb11-b1ac-00224816946c", "owneridname": "--- ---", "@search.ownerid.logicalname": "systemuser", "@search.objecttypecode": 1, "name": "City Power & Light Integration", "entityimage_url": null, "createdon": "4/19/2021 1:04 AM", "modifiedon": "4/19/2021 1:04 AM", "emailaddress1": null, "address1_city": "Bothell", "@search.primarycontactid.logicalname": "contact", "primarycontactid": null, "primarycontactidname": null, "accountnumber": null, "telephone1": "425-555-4885" } ], "facets": {}, "totalrecordcount": 8 }


还有个searchtype的参数可以设置,默认是simple,如果改成full的话搜索结果会包括模糊搜索内容,如下搜索若不设置searchtype为full则搜索结果为空,设置为full后能出来搜索结果。
var clientUrl = Xrm.Utility.getGlobalContext().getClientUrl(); var req = new XMLHttpRequest() req.open("POST", clientUrl + "/api/search/v1.0/query", true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { var responseJSON = JSON.parse(this.responseText); console.log(responseJSON); } else { var error = JSON.parse(this.responseText).error; Xrm.Utility.alertDialog("Error." + error.message); } } }; var reqContent = { "search": "Cit +Power", "returntotalrecordcount": true, "entities":["account"], "searchtype":"full" }; req.send(JSON.stringify(reqContent));


官方文档说能搜索到附件,邮件附件中的内容,我上传了一个一个餐饮服务的电子发票也就是一个PDF作为一个客户的附件,用类似如下代码真的可以搜索到:
var clientUrl = Xrm.Utility.getGlobalContext().getClientUrl(); var req = new XMLHttpRequest() req.open("POST", clientUrl + "/api/search/v1.0/query", true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { var responseJSON = JSON.parse(this.responseText); console.log(responseJSON); } else { var error = JSON.parse(this.responseText).error; Xrm.Utility.alertDialog("Error." + error.message); } } }; var reqContent = { "search": "餐饮服务" }; req.send(JSON.stringify(reqContent));


返回的结果如下:
{ "searchterms": "餐饮服务", "value": [ { "@search.score": -8.6599922180175781, "@search.highlights": { "documentbody": [ "661705211017 011002000911 63328729 2021 04 29 宋艳平 董凤雪 赵佳 91110108662189842D 91110108600040399G 44558 96679 15730 04151 3237/97-14/5< 762-34+7< < > 17- *//1+4< < > > 4> *25-91+00013-52 > 5+62699< 886> 2/8*7< 4924< 366 /07> < > > 3+48< > > 4> 8159/1369+5 叁佰圆整 300.00 283.02 16.98 *{crmhit}餐饮服务{/crmhit}*餐费 283.02 6% 16.98 微软(中国)有限公司 北京健力源餐饮管理有限公司 北京市海淀区天秀路10号中国农大国际创业园3号楼6068010-82601503 中信银行北京首体南路支行8110701013001243119 发票代码: 发票号码: 开票日期: 年 月 日 校 验 码: 名 称: 纳税人识别号: 地址、 电话: 开户行及账号: 购 买 方 货物或应税劳务、服务名称 规格型号 单位 数 量 金 额 税率 税 额 合 计 价税合计(大写) (小写) 名 称: 纳税人识别号: 地址、 电话: 开户行及账号: 收 款 人: 复 核: 开 票 人: 销售方 : (章) 密 码 区 销 售 方 备 注 单 价 机器编号: 全 国 统 一 发 票 监 制 章 国家税务总局 北京市税务局 北京增值税电子普通发票 2021-04-29T15:15:01+0800 location sign" ] }, "@search.entityname": "annotation", "@search.objectid": "ba17a293-eaa4-088d-bfa8-23a6bd7a96cf", "ownerid": "41833657-63a0-eb11-b1ac-00224816946c", "owneridname": "System Administrator", "@search.ownerid.logicalname": "systemuser", "@search.objecttypecode": 5, "subject": "发票", "versionnumber": 5817190, "createdon": "5/8/2021 10:05 AM", "modifiedon": "5/8/2021 10:05 AM", "notetext": null, "objecttypecode": "account", "objectid": "7076d7bb-3aa3-eb11-b1ac-00224816920b", "objectidname": "", "@search.objectid.logicalname": "account" } ], "facets": {}, "totalrecordcount": -1 }



    推荐阅读