mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
add the multi-search
This commit is contained in:
parent
11ce3b9636
commit
9473a2a6ca
5 changed files with 153 additions and 20 deletions
|
@ -190,7 +190,6 @@ impl<Method: AggregateMethod> Aggregate for DocumentsFetchAggregator<Method> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Get one document
|
||||
///
|
||||
/// Get one document from its primary key.
|
||||
|
@ -303,7 +302,6 @@ impl Aggregate for DocumentsDeletionAggregator {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Delete a document
|
||||
///
|
||||
/// Delete a single document by id.
|
||||
|
@ -1197,13 +1195,16 @@ pub async fn delete_documents_by_filter(
|
|||
Ok(HttpResponse::Accepted().json(task))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserr, IntoParams)]
|
||||
#[derive(Debug, Deserr, ToSchema)]
|
||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
||||
pub struct DocumentEditionByFunction {
|
||||
/// A string containing a RHAI function.
|
||||
#[deserr(default, error = DeserrJsonError<InvalidDocumentFilter>)]
|
||||
pub filter: Option<Value>,
|
||||
/// A string containing a filter expression.
|
||||
#[deserr(default, error = DeserrJsonError<InvalidDocumentEditionContext>)]
|
||||
pub context: Option<Value>,
|
||||
/// An object with data Meilisearch should make available for the editing function.
|
||||
#[deserr(error = DeserrJsonError<InvalidDocumentEditionFunctionFilter>, missing_field_error = DeserrJsonError::missing_document_edition_function)]
|
||||
pub function: String,
|
||||
}
|
||||
|
@ -1246,8 +1247,8 @@ impl Aggregate for EditDocumentsByFunctionAggregator {
|
|||
security(("Bearer" = ["documents.*", "*"])),
|
||||
params(
|
||||
("indexUid", example = "movies", description = "Index Unique Identifier", nullable = false),
|
||||
DocumentEditionByFunction,
|
||||
),
|
||||
request_body = DocumentEditionByFunction,
|
||||
responses(
|
||||
(status = 202, description = "Task successfully enqueued", body = SummarizedTaskView, content_type = "application/json", example = json!(
|
||||
{
|
||||
|
|
|
@ -2,7 +2,12 @@ use std::collections::BTreeMap;
|
|||
|
||||
use crate::extractors::authentication::policies::*;
|
||||
use crate::extractors::authentication::GuardedData;
|
||||
use crate::search::{SimilarQuery, SimilarResult};
|
||||
use crate::routes::indexes::documents::DocumentEditionByFunction;
|
||||
use crate::routes::multi_search::SearchResults;
|
||||
use crate::search::{
|
||||
FederatedSearch, FederatedSearchResult, Federation, FederationOptions, MergeFacets,
|
||||
SearchQueryWithIndex, SearchResultWithIndex, SimilarQuery, SimilarResult,
|
||||
};
|
||||
use crate::search_queue::SearchQueue;
|
||||
use crate::Opt;
|
||||
use actix_web::web::Data;
|
||||
|
@ -64,13 +69,14 @@ pub mod tasks;
|
|||
(path = "/keys", api = api_key::ApiKeyApi),
|
||||
(path = "/metrics", api = metrics::MetricApi),
|
||||
(path = "/logs", api = logs::LogsApi),
|
||||
(path = "/multi-search", api = multi_search::MultiSearchApi),
|
||||
),
|
||||
paths(get_health, get_version, get_stats),
|
||||
tags(
|
||||
(name = "Stats", description = "Stats gives extended information and metrics about indexes and the Meilisearch database."),
|
||||
),
|
||||
modifiers(&OpenApiAuth),
|
||||
components(schemas(SimilarQuery, SimilarResult, PaginationView<serde_json::Value>, BrowseQuery, UpdateIndexRequest, IndexUid, IndexCreateRequest, KeyView, Action, CreateApiKey, UpdateStderrLogs, LogMode, GetLogs, IndexStats, Stats, HealthStatus, HealthResponse, VersionResponse, Code, ErrorType, AllTasks, TaskView, Status, DetailsView, ResponseError, Settings<Unchecked>, Settings<Checked>, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings, SummarizedTaskView, Kind))
|
||||
components(schemas(DocumentEditionByFunction, MergeFacets, FederationOptions, SearchQueryWithIndex, Federation, FederatedSearch, FederatedSearchResult, SearchResults, SearchResultWithIndex, SimilarQuery, SimilarResult, PaginationView<serde_json::Value>, BrowseQuery, UpdateIndexRequest, IndexUid, IndexCreateRequest, KeyView, Action, CreateApiKey, UpdateStderrLogs, LogMode, GetLogs, IndexStats, Stats, HealthStatus, HealthResponse, VersionResponse, Code, ErrorType, AllTasks, TaskView, Status, DetailsView, ResponseError, Settings<Unchecked>, Settings<Checked>, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings, SummarizedTaskView, Kind))
|
||||
)]
|
||||
pub struct MeilisearchApi;
|
||||
|
||||
|
@ -89,7 +95,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||
.service(web::scope("/snapshots").configure(snapshot::configure)) // done
|
||||
.service(web::resource("/stats").route(web::get().to(get_stats))) // done
|
||||
.service(web::resource("/version").route(web::get().to(get_version))) // done
|
||||
.service(web::scope("/indexes").configure(indexes::configure)) // WIP
|
||||
.service(web::scope("/indexes").configure(indexes::configure)) // done
|
||||
.service(web::scope("/multi-search").configure(multi_search::configure)) // TODO
|
||||
.service(web::scope("/swap-indexes").configure(swap_indexes::configure)) // TODO
|
||||
.service(web::scope("/metrics").configure(metrics::configure)) // done
|
||||
|
|
|
@ -8,6 +8,7 @@ use meilisearch_types::error::ResponseError;
|
|||
use meilisearch_types::keys::actions;
|
||||
use serde::Serialize;
|
||||
use tracing::debug;
|
||||
use utoipa::{OpenApi, ToSchema};
|
||||
|
||||
use super::multi_search_analytics::MultiSearchAggregator;
|
||||
use crate::analytics::Analytics;
|
||||
|
@ -17,20 +18,129 @@ use crate::extractors::authentication::{AuthenticationError, GuardedData};
|
|||
use crate::extractors::sequential_extractor::SeqHandler;
|
||||
use crate::routes::indexes::search::search_kind;
|
||||
use crate::search::{
|
||||
add_search_rules, perform_federated_search, perform_search, FederatedSearch, RetrieveVectors,
|
||||
add_search_rules, perform_federated_search, perform_search, FederatedSearch, FederatedSearchResult, RetrieveVectors,
|
||||
SearchQueryWithIndex, SearchResultWithIndex,
|
||||
};
|
||||
use crate::search_queue::SearchQueue;
|
||||
|
||||
|
||||
#[derive(OpenApi)]
|
||||
#[openapi(
|
||||
paths(multi_search_with_post),
|
||||
tags((
|
||||
name = "Multi-search",
|
||||
description = "The `/multi-search` route allows you to perform multiple search queries on one or more indexes by bundling them into a single HTTP request. Multi-search is also known as federated search.",
|
||||
external_docs(url = "https://www.meilisearch.com/docs/reference/api/multi_search"),
|
||||
|
||||
)),
|
||||
)]
|
||||
pub struct MultiSearchApi;
|
||||
|
||||
pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(web::resource("").route(web::post().to(SeqHandler(multi_search_with_post))));
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct SearchResults {
|
||||
#[derive(Serialize, ToSchema)]
|
||||
pub struct SearchResults {
|
||||
results: Vec<SearchResultWithIndex>,
|
||||
}
|
||||
|
||||
/// Perform a multi-search
|
||||
///
|
||||
/// Bundle multiple search queries in a single API request. Use this endpoint to search through multiple indexes at once.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/",
|
||||
tag = "Multi-search",
|
||||
security(("Bearer" = ["search", "*"])),
|
||||
responses(
|
||||
(status = OK, description = "Non federated multi-search", body = SearchResults, content_type = "application/json", example = json!(
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"indexUid":"movies",
|
||||
"hits":[
|
||||
{
|
||||
"id":13682,
|
||||
"title":"Pooh's Heffalump Movie",
|
||||
},
|
||||
],
|
||||
"query":"pooh",
|
||||
"processingTimeMs":26,
|
||||
"limit":1,
|
||||
"offset":0,
|
||||
"estimatedTotalHits":22
|
||||
},
|
||||
{
|
||||
"indexUid":"movies",
|
||||
"hits":[
|
||||
{
|
||||
"id":12,
|
||||
"title":"Finding Nemo",
|
||||
},
|
||||
],
|
||||
"query":"nemo",
|
||||
"processingTimeMs":5,
|
||||
"limit":1,
|
||||
"offset":0,
|
||||
"estimatedTotalHits":11
|
||||
},
|
||||
{
|
||||
"indexUid":"movie_ratings",
|
||||
"hits":[
|
||||
{
|
||||
"id":"Us",
|
||||
"director": "Jordan Peele",
|
||||
}
|
||||
],
|
||||
"query":"Us",
|
||||
"processingTimeMs":0,
|
||||
"limit":1,
|
||||
"offset":0,
|
||||
"estimatedTotalHits":1
|
||||
}
|
||||
]
|
||||
}
|
||||
)),
|
||||
(status = OK, description = "Federated multi-search", body = FederatedSearchResult, content_type = "application/json", example = json!(
|
||||
{
|
||||
"hits": [
|
||||
{
|
||||
"id": 42,
|
||||
"title": "Batman returns",
|
||||
"overview": "The overview of batman returns",
|
||||
"_federation": {
|
||||
"indexUid": "movies",
|
||||
"queriesPosition": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"comicsId": "batman-killing-joke",
|
||||
"description": "This comic is really awesome",
|
||||
"title": "Batman: the killing joke",
|
||||
"_federation": {
|
||||
"indexUid": "comics",
|
||||
"queriesPosition": 1
|
||||
}
|
||||
},
|
||||
],
|
||||
"processingTimeMs": 0,
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"estimatedTotalHits": 2,
|
||||
"semanticHitCount": 0
|
||||
}
|
||||
)),
|
||||
(status = 401, description = "The authorization header is missing", body = ResponseError, content_type = "application/json", example = json!(
|
||||
{
|
||||
"message": "The Authorization header is missing. It must use the bearer authorization method.",
|
||||
"code": "missing_authorization_header",
|
||||
"type": "auth",
|
||||
"link": "https://docs.meilisearch.com/errors#missing_authorization_header"
|
||||
}
|
||||
)),
|
||||
)
|
||||
)]
|
||||
pub async fn multi_search_with_post(
|
||||
index_scheduler: GuardedData<ActionPolicy<{ actions::SEARCH }>, Data<IndexScheduler>>,
|
||||
search_queue: Data<SearchQueue>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue