Added index name to unsortable error message

This commit is contained in:
Francesco 2024-02-13 16:16:36 +01:00
parent e6597cd57a
commit e288dd7406
8 changed files with 27 additions and 25 deletions

View File

@ -634,7 +634,6 @@ impl SearchAggregator {
pub fn from_query(query: &SearchQuery, request: &HttpRequest) -> Self {
let SearchQuery {
q,
index_uid,
vector,
offset,
limit,

View File

@ -53,8 +53,8 @@ pub async fn search(
req: HttpRequest,
analytics: web::Data<dyn Analytics>,
) -> Result<HttpResponse, ResponseError> {
let index_uid = IndexUid::try_from(index_uid.into_inner())?;
let index_uid_string = index_uid.into_inner();
let index_uid = IndexUid::try_from(index_uid_string.clone())?;
let query = params.into_inner();
debug!(parameters = ?query, "Facet search");
@ -72,7 +72,14 @@ 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, search_query, facet_query, facet_name, features)
perform_facet_search(
&index,
&index_uid_string,
search_query,
facet_query,
facet_name,
features,
)
})
.await?;
@ -102,7 +109,6 @@ impl From<FacetSearchQuery> for SearchQuery {
SearchQuery {
q,
index_uid: None,
offset: DEFAULT_SEARCH_OFFSET(),
limit: DEFAULT_SEARCH_LIMIT(),
page: None,

View File

@ -128,7 +128,6 @@ impl From<SearchQueryGet> for SearchQuery {
};
Self {
index_uid: None,
q: other.q,
vector: other.vector.map(CS::into_inner),
offset: other.offset.0,
@ -205,7 +204,7 @@ 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)
perform_search(&index, &index_uid.to_string(), query, features, distribution)
})
.await?;
if let Ok(ref search_result) = search_result {
@ -245,7 +244,7 @@ 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)
perform_search(&index, &index_uid.to_string(), query, features, distribution)
})
.await?;
if let Ok(ref search_result) = search_result {

View File

@ -54,7 +54,7 @@ pub async fn multi_search_with_post(
{
debug!(on_index = query_index, parameters = ?query, "Multi-search");
let index_uid_name = &index_uid.clone();
let index_uid_name = index_uid.to_string();
// Check index from API key
if !index_scheduler.filters().is_index_authorized(&index_uid) {
@ -82,13 +82,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.to_string().clone(), query, features, distribution)
perform_search(&index, &index_uid_name.clone(), query, features, distribution)
})
.await
.with_index(query_index)?;
search_results.push(SearchResultWithIndex {
index_uid: index_uid_name.to_string(),
index_uid: index_uid.to_string(),
result: search_result.with_index(query_index)?,
});
}

View File

@ -41,7 +41,6 @@ pub const DEFAULT_SEMANTIC_RATIO: fn() -> SemanticRatio = || SemanticRatio(0.5);
#[derive(Debug, Clone, Default, PartialEq, Deserr)]
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
pub struct SearchQuery {
pub index_uid: Option<String>,
#[deserr(default, error = DeserrJsonError<InvalidSearchQ>)]
pub q: Option<String>,
#[deserr(default, error = DeserrJsonError<InvalidSearchVector>)]
@ -193,7 +192,6 @@ pub struct SearchQueryWithIndex {
impl SearchQueryWithIndex {
pub fn into_index_query(self) -> (IndexUid, SearchQuery) {
let index_uid_name = self.index_uid.clone().to_string().clone();
let SearchQueryWithIndex {
index_uid,
q,
@ -219,11 +217,11 @@ impl SearchQueryWithIndex {
attributes_to_search_on,
hybrid,
} = self;
(
index_uid,
SearchQuery {
q,
index_uid: Some(index_uid_name),
vector,
offset,
limit,
@ -381,13 +379,13 @@ pub fn add_search_rules(query: &mut SearchQuery, rules: IndexSearchRules) {
fn prepare_search<'t>(
index: &'t Index,
index_uid: &String,
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.clone());
let mut search = index.search(rtxn, &index_uid);
if query.vector.is_some() {
features.check_vector("Passing `vector` as a query parameter")?;
@ -490,7 +488,7 @@ fn prepare_search<'t>(
pub fn perform_search(
index: &Index,
index_uid: String,
index_uid: &String,
query: SearchQuery,
features: RoFeatures,
distribution: Option<DistributionShift>,
@ -722,6 +720,7 @@ pub fn perform_search(
pub fn perform_facet_search(
index: &Index,
index_uid: &String,
search_query: SearchQuery,
facet_query: Option<String>,
facet_name: String,
@ -729,9 +728,8 @@ pub fn perform_facet_search(
) -> Result<FacetSearchResult, MeilisearchHttpError> {
let before_search = Instant::now();
let rtxn = index.read_txn()?;
let (search, _, _, _) =
prepare_search(index, &"".to_string(), &rtxn, &search_query, features, None)?;
prepare_search(index, &index_uid, &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

@ -1212,8 +1212,8 @@ impl Index {
FacetDistribution::new(rtxn, self)
}
pub fn search<'a>(&'a self, rtxn: &'a RoTxn, index_uid: String) -> Search<'a> {
Search::new(rtxn, self, index_uid)
pub fn search<'a>(&'a self, rtxn: &'a RoTxn, index_uid: &'a String) -> Search<'a> {
Search::new(rtxn, self, &index_uid)
}
/// Returns the index creation time.

View File

@ -115,7 +115,7 @@ impl<'a> Search<'a> {
// TODO: find classier way to achieve that than to reset vector and query params
// create separate keyword and semantic searches
let mut search = Search {
index_uid: self.index_uid.to_string().clone(),
index_uid: &self.index_uid,
query: self.query.clone(),
vector: self.vector.clone(),
filter: self.filter.clone(),

View File

@ -36,7 +36,7 @@ pub mod hybrid;
pub mod new;
pub struct Search<'a> {
index_uid: String,
index_uid: &'a String,
query: Option<String>,
vector: Option<Vec<f32>>,
// this should be linked to the String in the query
@ -58,7 +58,7 @@ pub struct Search<'a> {
}
impl<'a> Search<'a> {
pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index, index_uid: String) -> Search<'a> {
pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index, index_uid: &'a String) -> Search<'a> {
Search {
index_uid,
query: None,
@ -158,7 +158,7 @@ impl<'a> Search<'a> {
pub fn execute_for_candidates(&self, has_vector_search: bool) -> Result<RoaringBitmap> {
if has_vector_search {
let ctx = SearchContext::new(self.index, self.index_uid.to_string(), self.rtxn);
let ctx = SearchContext::new(self.index, self.index_uid.clone(), self.rtxn);
filtered_universe(&ctx, &self.filter)
} else {
Ok(self.execute()?.candidates)