Fix tests

This commit is contained in:
Francesco Allara 2024-02-13 21:33:09 +01:00
parent c9708f7d0c
commit a082f14c69
25 changed files with 94 additions and 115 deletions

View file

@ -53,8 +53,8 @@ pub async fn search(
req: HttpRequest,
analytics: web::Data<dyn Analytics>,
) -> Result<HttpResponse, ResponseError> {
let index_uid_string = index_uid.into_inner();
let index_uid = IndexUid::try_from(index_uid_string.clone())?;
let index_uid = IndexUid::try_from(index_uid.into_inner())?;
let query = params.into_inner();
debug!(parameters = ?query, "Facet search");
@ -72,14 +72,7 @@ pub async fn search(
let index = index_scheduler.index(&index_uid)?;
let features = index_scheduler.features();
let search_result = tokio::task::spawn_blocking(move || {
perform_facet_search(
&index,
&index_uid_string,
search_query,
facet_query,
facet_name,
features,
)
perform_facet_search(&index, search_query, facet_query, facet_name, features)
})
.await?;

View file

@ -203,10 +203,9 @@ pub async fn search_with_url_query(
let distribution = embed(&mut query, index_scheduler.get_ref(), &index).await?;
let search_result = tokio::task::spawn_blocking(move || {
perform_search(&index, &index_uid.to_string(), query, features, distribution)
})
.await?;
let search_result =
tokio::task::spawn_blocking(move || perform_search(&index, query, features, distribution))
.await?;
if let Ok(ref search_result) = search_result {
aggregate.succeed(search_result);
}
@ -243,10 +242,9 @@ pub async fn search_with_post(
let distribution = embed(&mut query, index_scheduler.get_ref(), &index).await?;
let search_result = tokio::task::spawn_blocking(move || {
perform_search(&index, &index_uid.to_string(), query, features, distribution)
})
.await?;
let search_result =
tokio::task::spawn_blocking(move || perform_search(&index, query, features, distribution))
.await?;
if let Ok(ref search_result) = search_result {
aggregate.succeed(search_result);
}

View file

@ -54,8 +54,6 @@ pub async fn multi_search_with_post(
{
debug!(on_index = query_index, parameters = ?query, "Multi-search");
let index_uid_name = index_uid.to_string();
// Check index from API key
if !index_scheduler.filters().is_index_authorized(&index_uid) {
return Err(AuthenticationError::InvalidToken).with_index(query_index);
@ -82,13 +80,13 @@ pub async fn multi_search_with_post(
.with_index(query_index)?;
let search_result = tokio::task::spawn_blocking(move || {
perform_search(&index, &index_uid_name.clone(), query, features, distribution)
perform_search(&index, query, features, distribution)
})
.await
.with_index(query_index)?;
search_results.push(SearchResultWithIndex {
index_uid: index_uid.to_string(),
index_uid: index_uid.into_inner(),
result: search_result.with_index(query_index)?,
});
}

View file

@ -217,7 +217,6 @@ impl SearchQueryWithIndex {
attributes_to_search_on,
hybrid,
} = self;
(
index_uid,
SearchQuery {
@ -379,13 +378,12 @@ pub fn add_search_rules(query: &mut SearchQuery, rules: IndexSearchRules) {
fn prepare_search<'t>(
index: &'t Index,
index_uid: &'t String,
rtxn: &'t RoTxn,
query: &'t SearchQuery,
features: RoFeatures,
distribution: Option<DistributionShift>,
) -> Result<(milli::Search<'t>, bool, usize, usize), MeilisearchHttpError> {
let mut search = index.search(rtxn, &index_uid);
let mut search = index.search(rtxn);
if query.vector.is_some() {
features.check_vector("Passing `vector` as a query parameter")?;
@ -488,7 +486,6 @@ fn prepare_search<'t>(
pub fn perform_search(
index: &Index,
index_uid: &String,
query: SearchQuery,
features: RoFeatures,
distribution: Option<DistributionShift>,
@ -497,7 +494,7 @@ pub fn perform_search(
let rtxn = index.read_txn()?;
let (search, is_finite_pagination, max_total_hits, offset) =
prepare_search(index, &index_uid, &rtxn, &query, features, distribution)?;
prepare_search(index, &rtxn, &query, features, distribution)?;
let milli::SearchResult { documents_ids, matching_words, candidates, document_scores, .. } =
match &query.hybrid {
@ -720,7 +717,6 @@ pub fn perform_search(
pub fn perform_facet_search(
index: &Index,
index_uid: &String,
search_query: SearchQuery,
facet_query: Option<String>,
facet_name: String,
@ -728,8 +724,8 @@ pub fn perform_facet_search(
) -> Result<FacetSearchResult, MeilisearchHttpError> {
let before_search = Instant::now();
let rtxn = index.read_txn()?;
let (search, _, _, _) =
prepare_search(index, &index_uid, &rtxn, &search_query, features, None)?;
let (search, _, _, _) = prepare_search(index, &rtxn, &search_query, features, None)?;
let mut facet_search =
SearchForFacetValues::new(facet_name, search, search_query.hybrid.is_some());
if let Some(facet_query) = &facet_query {

View file

@ -882,7 +882,7 @@ async fn sort_unsortable_attribute() {
index.wait_task(1).await;
let expected_response = json!({
"message": "Attribute `title` is not sortable. Available sortable attributes are: `id`.",
"message": "Attribute `title` of index `test` is not sortable. Available sortable attributes are: `id`.",
"code": "invalid_search_sort",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_search_sort"