mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 16:51:01 +00:00
Don't use Deserr for ExternalDocumentId, instead convert to error afterward
This commit is contained in:
@ -635,7 +635,7 @@ impl SearchQueryWithIndex {
|
||||
pub struct SimilarQuery {
|
||||
#[deserr(error = DeserrJsonError<InvalidSimilarId>)]
|
||||
#[schema(value_type = String)]
|
||||
pub id: ExternalDocumentId,
|
||||
pub id: serde_json::Value,
|
||||
#[deserr(default = DEFAULT_SEARCH_OFFSET(), error = DeserrJsonError<InvalidSimilarOffset>)]
|
||||
pub offset: usize,
|
||||
#[deserr(default = DEFAULT_SEARCH_LIMIT(), error = DeserrJsonError<InvalidSimilarLimit>)]
|
||||
@ -657,8 +657,7 @@ pub struct SimilarQuery {
|
||||
pub ranking_score_threshold: Option<RankingScoreThresholdSimilar>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserr)]
|
||||
#[deserr(try_from(Value) = TryFrom::try_from -> InvalidSimilarId)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ExternalDocumentId(String);
|
||||
|
||||
impl AsRef<str> for ExternalDocumentId {
|
||||
@ -674,7 +673,7 @@ impl ExternalDocumentId {
|
||||
}
|
||||
|
||||
impl TryFrom<String> for ExternalDocumentId {
|
||||
type Error = InvalidSimilarId;
|
||||
type Error = milli::UserError;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
serde_json::Value::String(value).try_into()
|
||||
@ -682,10 +681,10 @@ impl TryFrom<String> for ExternalDocumentId {
|
||||
}
|
||||
|
||||
impl TryFrom<Value> for ExternalDocumentId {
|
||||
type Error = InvalidSimilarId;
|
||||
type Error = milli::UserError;
|
||||
|
||||
fn try_from(value: Value) -> Result<Self, Self::Error> {
|
||||
Ok(Self(milli::documents::validate_document_id_value(value).map_err(|_| InvalidSimilarId)?))
|
||||
Ok(Self(milli::documents::validate_document_id_value(value)?))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1597,6 +1596,11 @@ pub fn perform_similar(
|
||||
ranking_score_threshold,
|
||||
} = query;
|
||||
|
||||
let id: ExternalDocumentId = id.try_into().map_err(|error| {
|
||||
let msg = format!("Invalid value at `.id`: {error}");
|
||||
ResponseError::from_msg(msg, Code::InvalidSimilarId)
|
||||
})?;
|
||||
|
||||
// using let-else rather than `?` so that the borrow checker identifies we're always returning here,
|
||||
// preventing a use-after-move
|
||||
let Some(internal_id) = index.external_documents_ids().get(&rtxn, &id)? else {
|
||||
|
Reference in New Issue
Block a user