
⚡ Rust를 위해 작성된 Meilisearch API 클라이언트?
Meilisearch Rust 는 Rust 개발자를위한 Meilisearch API 클라이언트입니다.
Meilisearch 는 오픈 소스 검색 엔진입니다. Meilisearch에 대해 자세히 알아보십시오.
이 readme에는이 meilisearch sdk를 사용하는 데 필요한 모든 문서가 포함되어 있습니다.
API 참조, 튜토리얼, 가이드 및 심층 기사와 같은 Meilisearch를 사용하는 방법에 대한 일반적인 정보는 주요 문서 웹 사이트로 참조하십시오.
Meilisearch Cloud로 서버 배포 및 수동 업데이트에 작별 인사를하십시오. 14 일 무료 평가판으로 시작하십시오! 신용 카드가 필요하지 않습니다.
meilisearch-sdk 사용하려면 이것을 Cargo.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 기능을 활성화하여 대부분의 structs가 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 ( ) ;이 작업을 한 번만 수행하면됩니다.
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 클라이언트를 사용자 정의 할 수 있습니다. futures-unsend 기능에 관심이있을 수 있으며,이 기능을 사용하면 비 중지 HTTP 클라이언트를 지정할 수 있습니다.
SDK는 REQWEST를 통해 WASM을 지원합니다. 그러나 미래를 가져 오는 동안 futures-unsend 기능을 활성화해야합니다.
이 상자는 WASM을 전적으로지지합니다.
WASM과 기본 버전의 유일한 차이점은 기본 버전이 오류 열거에 하나 더 변형 ( Error::Http )이 있다는 것입니다. 그것은 그다지 중요하지 않지만 WASM 에도이 변형을 추가 할 수 있습니다.
그러나 웹 브라우저에서 실행하려는 프로그램을 만들려면 CLI 프로그램과 매우 다른 디자인이 필요합니다. Meilisearch를 사용하여 간단한 Rust 웹 앱의 예를 보려면 Demo를 참조하십시오.
경고 : Window가없는 경우 meilisearch-sdk 공황 상태에 빠집니다 (예 : 웹 확장).
이 패키지는 Meilisearch의 버전 v1.x와의 호환성을 보장하지만 일부 기능은 존재하지 않을 수 있습니다. 자세한 정보는 문제를 확인하십시오.
이 프로젝트에서 새로운 기여는 환영받는 것 이상입니다!
개발 워크 플로우에 대해 더 알고 싶거나 기여하고 싶다면 자세한 지침은 기고 가이드 라인을 방문하십시오!
Meilisearch는 이와 같은 많은 SDK 및 통합 도구를 제공하고 유지 관리합니다. 우리는 모든 사람에게 모든 종류의 프로젝트에 대한 놀라운 검색 경험을 제공하고 싶습니다. 기여하고 싶거나 제안하거나 지금 무슨 일이 일어나고 있는지 아는 경우 Integration-Guides 저장소에서 우리를 방문하십시오.