前往主页Meilisearch标志
返回文章

引入多索引搜索

联邦搜索通过跨多个索引进行搜索,提升了用户体验和结果相关性。

Carolina Ferreira
Carolina FerreiraMeilisearch 开发者布道师@CarolainFG
Introducing multi-index search

Meilisearch v1.1 引入了 /multi-search 端点。通过此端点,用户现在可以将多个搜索查询捆绑到单个 HTTP 请求中,对一个或多个索引进行搜索。本质上,/multi-search 端点为 联邦搜索 铺平了道路。

联邦搜索Meilisearch 1.10 及更高版本中可用。

使用 Meilisearch 进行多索引搜索

联邦搜索获得了 277 票,是 最受期待的功能 之一。我们很高兴能最终宣布该功能的第一阶段。

我们引入了一个 /multi-search 路由,它允许通过单个 HTTP 请求在多个索引中进行搜索。假设我们有两个索引:moviesactors。使用 /multi-search 端点,我们可以搜索女演员的名字,并在搜索结果中同时检索她的传记和电影。

例如,以下是多索引搜索请求

curl 
-X POST 'http://localhost:7700/multi-search' 
-H 'Content-Type: application/json' 
--data-binary '{
  "queries": [
     {
       "indexUid": "movies",
       "q": "Kate Winslet",
       "limit": 1
     },
    {
       "indexUid": "actors",
       "q": "Kate Winslet",
       "limit": 1
    }
  ]
}'

响应将包含每个被搜索索引的一组搜索结果

{
   "results": [
     {
       "indexUid": "movies",
       "hits": [
         {
           "title": "The Reader",
           "overview": "The story of Michael Berg, a German lawyer who, as a teenager in the late 1950s, had an affair with an older woman, Hanna, who then disappeared only to resurface years later as one of the defendants in a war crimes trial stemming from her actions as a concentration camp guard late in the war. He alone realizes that Hanna is illiterate and may be concealing that fact at the expense of her freedom.",
           "crew": [...],
           "cast": [
		...
             {
               "character": "Hanna Schmitz",
               "name": "Kate Winslet",
               "profile_path": "/e3tdop3WhseRnn8KwMVLAV25Ybv.jpg"
             },
		...
           ]
         }
       ],
// other search results fields: processingTimeMs, limit, ...
     },
     {
       "indexUid": "actors",
       "hits": [
     {
       "name": "Kate Winslet",
       "known_for": [
           "Titanic",
           "Eternal Sunshine of the Spotless Mind",
           "The Reader"
       ],
       "birthday": "1975-10-05",
       "deathday": null,
       "biography": "Kate Elizabeth Winslet (born 5 October 1975) is an English actress. Known for her work in independent films..."
     }
       ],
	// other search results fields: processingTimeMs, limit, ...
     }
   ]
 }

如您所见,在结果数组中,索引的排序顺序与查询中的顺序相同。响应包含传统搜索返回的 常见字段 以及索引 UID。请注意,在此示例中,我们使用 limit 参数将返回的文档数量限制为仅一个。

多索引搜索演示

Searching for 'Kate Winslet' returns both her biography and movies in which she starred, while searching for 'Titanic' returns the movie itself as well as actors who starred in it.

亲自 尝试 一下!

此演示使用了两个数据集:电影(movies)和演员(actors)。每个数据集都存储在自己的索引中,拥有自己的设置,并且如上例所示,拥有自己的模式(schema)。

由于这两个索引具有不同的模式,它们具有不同的 可搜索属性。在电影索引中,您可以根据电影的标题、角色、演员、制片人、导演或电影概述进行搜索。

//movies index 
searchableAttributes: [
   'title',
   'crew.name',
   'cast.name',
   'cast.character',
   'overview',
 ]

演员索引允许您按姓名搜索演员,以及他们最著名的电影或节目,以及其传记中发现的关键词。

//actors index 
searchableAttributes: ['name', 'known_for', 'biography']

完整的设置、数据集和代码都可在 GitHub 上获取,您可以随意自行探索。请随意调整设置以根据您的需求自定义行为。如果您有改进演示的想法,例如添加分面(facets),请随时提交拉取请求(pull request)。欢迎所有贡献!

总结

我们很高兴推出联邦搜索的首次迭代,并将努力推动聚合搜索结果。如果没有我们开发者社区提供的宝贵反馈和见解,我们不可能实现这一点。您的反馈在帮助我们确定优先级并塑造该功能以满足您的需求方面发挥了关键作用。

如果您有兴趣了解我们的进展,我们鼓励您查看我们的 产品路线图,加入我们在 GitHub 上的 讨论,或在 Discord 上与我们联系。

一如既往,我们致力于为用户提供最佳的搜索体验,并感谢您为此目标提供的帮助。

Meilisearch indexes embeddings 7x faster with binary quantization

Meilisearch 通过二进制量化将嵌入索引速度提升 7 倍

通过与向量存储 Arroy 结合实施二进制量化,在保持搜索相关性和效率的同时,大大减少了大型嵌入的磁盘空间使用和索引时间。

Tamo
Tamo29 Nov 2024
How to add AI-powered search to a React app

如何在 React 应用中添加 AI 驱动的搜索

使用 Meilisearch 的 AI 驱动搜索构建一个 React 电影搜索和推荐应用。

Carolina Ferreira
Carolina Ferreira24 Sept 2024
Meilisearch is too slow

Meilisearch 太慢了

在这篇博客文章中,我们将探讨 Meilisearch 文档索引器所需的改进。我们将讨论当前的索引引擎、其缺点以及优化性能的新技术。

Clément Renault
Clément Renault20 Aug 2024