
meilisearch apiクライアントは錆のために書かれていますか?
Meilisearch Rustは、 Rust開発者向けのMeilisearch APIクライアントです。
Meilisearchはオープンソースの検索エンジンです。 Meilisearchの詳細をご覧ください。
このREADMEには、このMeilisearch SDKの使用を開始するために必要なすべてのドキュメントが含まれています。
APIリファレンス、チュートリアル、ガイド、詳細な記事など、Meilisearchの使用方法に関する一般的な情報については、メインドキュメントWebサイトを参照してください。
Meilisearch Cloudを使用したサーバーの展開と手動の更新に別れを告げます。 14日間の無料トライアルを始めましょう!クレジットカードは必要ありません。
meilisearch-sdkを使用するには、これをCargo.tomlに追加します。toml:
[ dependencies ]
meilisearch-sdk = " 0.27.1 "次のオプションの依存関係も役立つ場合があります。
futures = " 0.3 " # To be able to block on async functions if you are not using an async runtime
serde = { version = " 1.0 " , features = [ " derive " ] }このクレートはasyncですが、Tokioのような非同期ランタイムを使用したり、先物をブロックしたりすることを選択できます。 sync機能を有効にして、ほとんどの構造体をSyncさせることができます。少し遅いかもしれません。
このクレートを使用することはSerdeなしでは可能ですが、多くの機能にはSerdeが必要です。
このクレートでは、Meilisearchサーバーを実行する必要があります。
Meilisearchインスタンスをダウンロードして実行する簡単な方法がたくさんあります。
たとえば、端末のcurlコマンドを使用してください。
# Install Meilisearch
curl -L https://install.meilisearch.com | sh
# Launch Meilisearch
./meilisearch --master-key=masterKeyNB: HomeBrewまたはAptからMeilisearchをダウンロードすることもできます。
use meilisearch_sdk :: client :: * ;
use serde :: { Serialize , Deserialize } ;
use futures :: executor :: block_on ;
# [ derive ( Serialize , Deserialize , Debug ) ]
struct Movie {
id : usize ,
title : String ,
genres : Vec < String > ,
}
# [ tokio :: main ( flavor = "current_thread" ) ]
async fn main ( ) {
// Create a client (without sending any request so that can't fail)
let client = Client :: new ( MEILISEARCH_URL , Some ( MEILISEARCH_API_KEY ) ) . unwrap ( ) ;
// An index is where the documents are stored.
let movies = client . index ( "movies" ) ;
// Add some movies in the index. If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
movies . add_documents ( & [
Movie { id : 1 , title : String :: from ( "Carol" ) , genres : vec ! [ "Romance" .to_string ( ) , "Drama" .to_string ( ) ] } ,
Movie { id : 2 , title : String :: from ( "Wonder Woman" ) , genres : vec ! [ "Action" .to_string ( ) , "Adventure" .to_string ( ) ] } ,
Movie { id : 3 , title : String :: from ( "Life of Pi" ) , genres : vec ! [ "Adventure" .to_string ( ) , "Drama" .to_string ( ) ] } ,
Movie { id : 4 , title : String :: from ( "Mad Max" ) , genres : vec ! [ "Adventure" .to_string ( ) , "Science Fiction" .to_string ( ) ] } ,
Movie { id : 5 , title : String :: from ( "Moana" ) , genres : vec ! [ "Fantasy" .to_string ( ) , "Action" .to_string ( ) ] } ,
Movie { id : 6 , title : String :: from ( "Philadelphia" ) , genres : vec ! [ "Drama" .to_string ( ) ] } ,
] , Some ( "id" ) ) . await . unwrap ( ) ;
} uidを使用すると、タスクを使用してドキュメントの追加のステータス( enqueued 、 canceled 、 processing 、 succeeded 、またはfailed )を確認できます。
// Meilisearch is typo-tolerant:
println ! ( "{:?}" , client.index ( "movies_2" ) .search ( ) .with_query ( "caorl" ) .execute::< Movie > ( ) . await .unwrap ( ) .hits ) ;出力:
[Movie { id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"] }]
JSON出力:
{
"hits" : [{
"id" : 1 ,
"title" : " Carol " ,
"genres" : [ " Romance " , " Drama " ]
}],
"offset" : 0 ,
"limit" : 10 ,
"processingTimeMs" : 1 ,
"query" : " caorl "
} let search_result = client . index ( "movies_3" )
. search ( )
. with_query ( "phil" )
. with_attributes_to_highlight ( Selectors :: Some ( & [ "*" ] ) )
. execute :: < Movie > ( )
. await
. unwrap ( ) ;
println ! ( "{:?}" , search_result.hits ) ;JSON出力:
{
"hits" : [
{
"id" : 6 ,
"title" : " Philadelphia " ,
"_formatted" : {
"id" : 6 ,
"title" : " <em>Phil</em>adelphia " ,
"genre" : [ " Drama " ]
}
}
],
"offset" : 0 ,
"limit" : 20 ,
"processingTimeMs" : 0 ,
"query" : " phil "
}フィルタリングを有効にする場合は、属性をfilterableAttributesインデックス設定に追加する必要があります。
let filterable_attributes = [
"id" ,
"genres" ,
] ;
client . index ( "movies_4" ) . set_filterable_attributes ( & filterable_attributes ) . await . unwrap ( ) ;この操作を1回だけ実行する必要があります。
Meilisearchは、 filterableAttributes更新するたびにインデックスを再構築することに注意してください。データセットのサイズに応じて、これには時間がかかる場合があります。タスクを使用してプロセスを追跡できます。
次に、検索を実行できます。
let search_result = client . index ( "movies_5" )
. search ( )
. with_query ( "wonder" )
. with_filter ( "id > 1 AND genres = Action" )
. execute :: < Movie > ( )
. await
. unwrap ( ) ;
println ! ( "{:?}" , search_result.hits ) ;JSON出力:
{
"hits" : [
{
"id" : 2 ,
"title" : " Wonder Woman " ,
"genres" : [ " Action " , " Adventure " ]
}
],
"offset" : 0 ,
"limit" : 20 ,
"estimatedTotalHits" : 1 ,
"processingTimeMs" : 0 ,
"query" : " wonder "
}HttpClientをカスタマイズしますデフォルトでは、SDKはreqwestを使用してHTTP呼び出しを行います。 SDKを使用すると、 HttpClient特性を自分で実装し、 new_with_clientメソッドでClientを初期化することにより、HTTPクライアントをカスタマイズできます。非センドHTTPクライアントを指定できるfutures-unsend機能に興味があるかもしれません。
SDKは、Reqwestを通じてWASMをサポートしています。ただし、インポート中にfutures-unsend機能を有効にする必要があります。
このクレートはWASMを完全にサポートしています。
WASMとネイティブバージョンの唯一の違いは、ネイティブバージョンにエラー列挙にもう1つのバリアント( Error::Http )があることです。それはそれほど重要ではありませんが、WASMにもこのバリアントを追加することができます。
ただし、Webブラウザで実行することを目的としたプログラムを作成するには、CLIプログラムとは非常に異なるデザインが必要です。 Meilisearchを使用した単純なRust Webアプリの例を見るには、デモを参照してください。
警告:Windowが利用できない場合、 meilisearch-sdkパニックになります(例:Web拡張機能)。
このパッケージは、MeilisearchのバージョンV1.xとの互換性を保証しますが、一部の機能は存在しない場合があります。詳細については、問題を確認してください。
このプロジェクトでは、新しい貢献は大歓迎です!
開発ワークフローについて詳しく知りたい場合、または貢献したい場合は、詳細な指示については、寄付ガイドラインをご覧ください。
Meilisearchは、このような多くのSDKと統合ツールを提供および維持しています。あらゆる種類のプロジェクトの素晴らしい検索体験を全員に提供したいと考えています。貢献したい、提案をしたい場合、または今何が起こっているのかを知りたい場合は、Integration-Guidesリポジトリにアクセスしてください。