Update API to fit the proto needs

This commit is contained in:
ManyTheFish 2022-07-11 17:27:07 +02:00
parent 96acbf815d
commit b1bf6722e8
4 changed files with 88 additions and 21 deletions

View file

@ -10,7 +10,7 @@ use http::header::CONTENT_TYPE;
use meilisearch_auth::SearchRules;
use meilisearch_lib::index::{
SearchQuery, SearchResult, DEFAULT_CROP_LENGTH, DEFAULT_CROP_MARKER,
DEFAULT_HIGHLIGHT_POST_TAG, DEFAULT_HIGHLIGHT_PRE_TAG,
DEFAULT_HIGHLIGHT_POST_TAG, DEFAULT_HIGHLIGHT_PRE_TAG, DEFAULT_SEARCH_LIMIT,
};
use meilisearch_lib::index_controller::Stats;
use meilisearch_lib::MeiliSearch;
@ -373,6 +373,7 @@ pub struct SearchAggregator {
// pagination
max_limit: usize,
max_offset: usize,
finite_pagination: bool,
// formatting
highlight_pre_tag: bool,
@ -427,12 +428,19 @@ impl SearchAggregator {
ret.max_terms_number = q.split_whitespace().count();
}
if query.limit.is_none() && query.offset.is_none() {
ret.max_limit = query.hits_per_page;
ret.max_offset = query.page.saturating_sub(1) * query.hits_per_page;
ret.finite_pagination = true;
} else {
ret.max_limit = query.limit.unwrap_or_else(DEFAULT_SEARCH_LIMIT);
ret.max_offset = query.offset.unwrap_or_default();
ret.finite_pagination = false;
}
ret.matching_strategy
.insert(format!("{:?}", query.matching_strategy), 1);
ret.max_limit = query.limit;
ret.max_offset = query.offset.unwrap_or_default();
ret.highlight_pre_tag = query.highlight_pre_tag != DEFAULT_HIGHLIGHT_PRE_TAG();
ret.highlight_post_tag = query.highlight_post_tag != DEFAULT_HIGHLIGHT_POST_TAG();
ret.crop_marker = query.crop_marker != DEFAULT_CROP_MARKER();

View file

@ -2,8 +2,8 @@ use actix_web::{web, HttpRequest, HttpResponse};
use log::debug;
use meilisearch_auth::IndexSearchRules;
use meilisearch_lib::index::{
MatchingStrategy, SearchQuery, DEFAULT_CROP_LENGTH, DEFAULT_CROP_MARKER,
DEFAULT_HIGHLIGHT_POST_TAG, DEFAULT_HIGHLIGHT_PRE_TAG, DEFAULT_SEARCH_LIMIT,
SearchQuery, DEFAULT_CROP_LENGTH, DEFAULT_CROP_MARKER, DEFAULT_HIGHLIGHT_POST_TAG,
DEFAULT_HIGHLIGHT_PRE_TAG, DEFAULT_HIT_PER_PAGE, DEFAULT_PAGE, MatchingStrategy
};
use meilisearch_lib::MeiliSearch;
use meilisearch_types::error::ResponseError;
@ -29,6 +29,10 @@ pub struct SearchQueryGet {
q: Option<String>,
offset: Option<usize>,
limit: Option<usize>,
#[serde(default = "DEFAULT_PAGE")]
page: usize,
#[serde(default = "DEFAULT_HIT_PER_PAGE")]
hits_per_page: usize,
attributes_to_retrieve: Option<CS<String>>,
attributes_to_crop: Option<CS<String>>,
#[serde(default = "DEFAULT_CROP_LENGTH")]
@ -62,7 +66,9 @@ impl From<SearchQueryGet> for SearchQuery {
Self {
q: other.q,
offset: other.offset,
limit: other.limit.unwrap_or_else(DEFAULT_SEARCH_LIMIT),
limit: other.limit,
page: other.page,
hits_per_page: other.hits_per_page,
attributes_to_retrieve: other
.attributes_to_retrieve
.map(|o| o.into_iter().collect()),