多索引搜尋簡介
聯合搜尋透過跨多個索引搜尋來提升使用者體驗和結果相關性。

Meilisearch v1.1 引入了 /multi-search
端點。透過此端點,使用者現在可以透過將多個搜尋查詢捆綁到單個 HTTP 請求中,對一個或多個索引發送多個搜尋查詢。本質上,/multi-search
端點為 聯合搜尋 鋪平了道路
聯合搜尋在 Meilisearch 1.10 和更高版本中可用。
使用 Meilisearch 進行多索引搜尋
聯合搜尋以 277 票成為 最受歡迎的功能之一。我們很高興終於宣布該功能的第一階段。
我們引入了一個 /multi-search
路由,允許透過單個 HTTP 請求在多個索引中搜尋。假設我們有兩個索引:movies
和 actors
。使用 /multi-search
端點,我們可以搜尋一位女演員的名字,並在搜尋結果中檢索她的傳記和電影。
舉例來說,以下是一個多重搜尋請求
curl -X POST 'https://127.0.0.1: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
參數將傳回的文件數量限制為只有一個。
多索引搜尋演示
此演示使用兩個資料集:電影和演員。每個資料集都儲存在自己的索引中,有自己的設定,如您在上面的範例中所見,也有自己的綱要。
由於這兩個索引具有不同的綱要,因此它們具有不同的可搜尋屬性。在電影索引中,您可以依電影的標題、角色、演員、製片人、導演或電影概述來搜尋電影。
//movies index searchableAttributes: [ 'title', 'crew.name', 'cast.name', 'cast.character', 'overview', ]
演員索引允許您依姓名、他們最知名的電影或節目,以及其傳記中找到的關鍵字來搜尋演員。
//actors index searchableAttributes: ['name', 'known_for', 'biography']
設定、資料集和程式碼的完整清單都可在 GitHub 上找到,因此您可以自行探索。請隨意調整設定,以自訂符合您需求的行為。如果您有任何改進演示的想法(例如新增分面),請隨時提交提取請求。歡迎大家貢獻!
結論
我們很高興推出聯合搜尋的第一個迭代版本,並且我們將努力推動彙總搜尋結果。如果沒有我們開發者社群提供的寶貴意見和見解,我們不可能實現這一目標。您的意見對於幫助我們優先處理和塑造該功能以滿足您的需求至關重要。
如果您有興趣了解我們的進展,我們鼓勵您查看我們的產品路線圖、加入我們在 GitHub 上的討論,或在 Discord 上與我們聯繫。
一如既往,我們致力於為使用者提供最佳的搜尋體驗,並感謝您協助我們實現這一目標。