功能背景
在日常的应用使用过程中,存在大量希望使用全文检索技术的场景,对资料库中的内容进行查询。Mendix默认的结构化查询方式,适合对特定业务实体进行类似数据库单表的基于SQL语句的查询。那如何在Mendix实现全文检索的功能呢?
Mendix提供了Global Search模块(https://marketplace.mendix.com/link/component/115019)来帮助用户实现全文检索功能。本文将通过一个示例,来介绍如何在项目中使用和配置全文检索功能。
操作步骤
本文档基于Studio Pro 9/24.2中进行操作
- 创建一个新的项目
![](https://file.jishuzhan.net/article/1742339315930763265/69169c865ceaf763cef3bb02f4e1c149.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/ce1cc6c7b2e10bb427ad6c1ec74cf469.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/fb50f4faafa5f6a068244b1e483d7dbd.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/3868f18c0e429b33c0630bad529ae10e.webp)
- 导入Community Commons组件
![](https://file.jishuzhan.net/article/1742339315930763265/9eb57bbd76459bef22551cce5a225cca.webp)
如遇到Studio Pro中Marketplace连接超时的问题,请可以直接访问网站下载,再手工导入项目工程
https://marketplace.mendix.com/link/component/170
![](https://file.jishuzhan.net/article/1742339315930763265/eaaf04dda33d9440d2710de04ebc7b42.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/fa6fdfc3ba2095833fedbb15879d99c4.webp)
确认组件被正常导入到工程
![](https://file.jishuzhan.net/article/1742339315930763265/33662f6374ad7455fda7f387c8fa8687.webp)
重复上述步骤,导入Global Search 组件
![](https://file.jishuzhan.net/article/1742339315930763265/ddea86fe17e3ef07af52d33c2df823d7.webp)
- 修复新模块后的一些页面格式错误。右键点击第一条错误信息
![](https://file.jishuzhan.net/article/1742339315930763265/35987cd2ad21cb533b76fe78f9a0e69b.webp)
点击"Go to Content for placeholder Main"后,打开以下画面
![](https://file.jishuzhan.net/article/1742339315930763265/a8b1d17399a11adf266edd21ddef98a4.webp)
双击左侧对应的项目条目,然后再右侧属性栏中,修改Layout选项,选择'Atlas_Default'
![](https://file.jishuzhan.net/article/1742339315930763265/0ce6473549d864ce45cfad1e90a06c7d.webp)
重复以上步骤,修复所有UI错误
所有UI Layout错误修复后,会看到Mendix Studio报属性需要刷新的错误提示。右键单击任意错误,点击"Update all renamed design properties in project",刷新属性信息
![](https://file.jishuzhan.net/article/1742339315930763265/ba88150239d7736f6f0bac616d7ba535.webp)
双击打开GlobalSearch->_USE_ME->5. Example Implementation->Pages->Actor_Select页面
![](https://file.jishuzhan.net/article/1742339315930763265/edea68780addd8bb9b529384e12d9cdb.webp)
在页面属性Layout-Type中,选择"Modal Pop-up"
![](https://file.jishuzhan.net/article/1742339315930763265/83fda9c66df78e683e93b2a1a666d6ed.webp)
打开GlobalSearch->_USE_ME->5. Example Implementation->Pages->Genre_Select页面,重复以上步骤。
保存项目修改后,所有问题得到修复。
- 创建一个新的业务实体。模拟一个客户投诉,实体属性如下:
![](https://file.jishuzhan.net/article/1742339315930763265/d016f8e3e9686813e3c4377f47d1704d.webp)
通过Generalization,选择此业务实体集成SearchableObject
![](https://file.jishuzhan.net/article/1742339315930763265/a2de4df80d3ac24f28e822761a89658d.webp)
通过这一步的操作,Global Search启动后会自动为此业务事业进行索引创建和维护。
- 打开Settings->runtime配置页签,点击"After Startup"的"Select"按钮
![](https://file.jishuzhan.net/article/1742339315930763265/a3829b8abd0dc4caf49a68143f483919.webp)
选择Global Search->_USE_ME->0.After Startup->ASU_GlobalSearch
![](https://file.jishuzhan.net/article/1742339315930763265/b10caf251c59b47d09f78f6c332c5e4c.webp)
- 将Global Search->_USE_ME->1. Indexing下面,SUB_IndexObject 和 SUB_DeleteIndex两个Microflow复制到项目模块中
![](https://file.jishuzhan.net/article/1742339315930763265/7a23e267ee5dbd9a6b6eacb6b688730a.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/7848c65a26ea792bddd5672c61423e8f.webp)
- 修改Global Search->_USE_ME->1. Indexing下面的连个Microflow ACO_SearchableObject 和 BDE_SearchableObject, 使用在上一步复制到项目模块的UB_IndexObject 和 SUB_DeleteIndex
![](https://file.jishuzhan.net/article/1742339315930763265/04316117cda0900efe5c9402eb081277.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/9dadd981693dc285e451fee9a8a584ac.webp)
- 右键MyFirstModule,创建新的MicoFlow
![](https://file.jishuzhan.net/article/1742339315930763265/297f12eb8ce1477efc75d51b9051d37d.webp)
命名为SUB_Incident_Index
![](https://file.jishuzhan.net/article/1742339315930763265/ab6f2ecba09b3bb5ed8be6e0987aa748.webp)
添加一个Input Parameter,类型为MyFirstModule.Incidents
![](https://file.jishuzhan.net/article/1742339315930763265/70a08e38c283659311c8b65f78ffb7ed.webp)
依次使用一下Activity配置
![](https://file.jishuzhan.net/article/1742339315930763265/c7ecfdcb0ec439f8181a655ca257711b.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/8b9a98f6f5ed47fd0ebb3828fa7a9915.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/a7e55863e7b0d708d6524c2fe1814ced.webp)
完整的Microflow如下:
![](https://file.jishuzhan.net/article/1742339315930763265/c558f68fdd31a3ab5364799633f91954.webp)
- 修改MyFirstModule->SUB_IndexObject,修改后MicroFlow如下
![](https://file.jishuzhan.net/article/1742339315930763265/899c323d53276f325ac7b17ed704a2d8.webp)
- 修改MyFirstModule->SUB_DeleteIndex,修改后截图如下
![](https://file.jishuzhan.net/article/1742339315930763265/97d1eb72626b1063066199d47d1767dc.webp)
- 在MyFirstModule中创建一个新的页面,GlobalSearchPage
![](https://file.jishuzhan.net/article/1742339315930763265/855d63e2d8a100ee53d62f37a3ebc95f.webp)
拖拽一个Snippet Call 控件到画布上,然后选择GlobalSearch->_USE_ME->5. Example Implementation->Snippets->SNIP_Search
![](https://file.jishuzhan.net/article/1742339315930763265/f544d7249e833d57e02bd3f38c9e6f85.webp)
双击打开GlobalSearch->_USE_ME->5. Example Implementation->Snippets->SNIP_Search,添加一个模板
![](https://file.jishuzhan.net/article/1742339315930763265/f5cde3e113093615db02aa0fa8411c03.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/8374307d60053194df3496b76a5d8cb1.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/7a34265625fbeeb18bca79ae47c03253.webp)
- 将GlobalSearchPage设置为首页
![](https://file.jishuzhan.net/article/1742339315930763265/7e057fa6e75f1f3f1ee28549f694b98d.webp)
13 创建测试页面录入测试数据
![](https://file.jishuzhan.net/article/1742339315930763265/15b07e4e889d2d9e5de61489f576ef02.webp)
![](https://file.jishuzhan.net/article/1742339315930763265/dc7d656e3624eb09a58375b4c1cdfdc6.webp)
配置完成,接下来就是见证奇迹的时刻:
![](https://file.jishuzhan.net/article/1742339315930763265/c72e75cb6759df4439a358ef993f89a2.webp)
我们来做一个查询
![](https://file.jishuzhan.net/article/1742339315930763265/03210f05683fd612cbc5e6ef6ee199bc.webp)
测试成功!
以上就是如何在Mendix中基于Global Search组件,进行全文检索配置的全过程。
GO MAKE IT!
关于Mendix
作为西门子Xcelerator平台的低代码引擎,Mendix正在迅速成为推动企业数字化发展的首选应用程序开发平台。Mendix让企业能够以前所未有的速度构建应用程序、促进IT团队与业务专家之间开展有意义的协作,并帮助IT团队保持对整个应用程序环境的控制。作为一直被领先的行业分析师视为"领军者和远见者"的低代码平台,Mendix是云原生的、开放的、可扩展的、敏捷的,并且经过实践验证。从人工智能和增强现实,到智能自动化和原生移动,Mendix和西门子Xcelerator已成为"数字优先"企业的中坚力量。Mendix已被46个国家的4,000多家企业采用,并建立了由30多万名开发人员组成的活跃社区,这些开发人员使用该平台创建了20多万款应用程序。