mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 08:41:00 +00:00
Remove insertFields parameter
This commit is contained in:
@ -423,7 +423,6 @@ InvalidRenderTemplateId , InvalidRequest , BAD_REQU
|
|||||||
InvalidRenderTemplateInline , InvalidRequest , BAD_REQUEST ;
|
InvalidRenderTemplateInline , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidRenderInput , InvalidRequest , BAD_REQUEST ;
|
InvalidRenderInput , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidRenderInputDocumentId , InvalidRequest , BAD_REQUEST ;
|
InvalidRenderInputDocumentId , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidRenderInputFields , InvalidRequest , BAD_REQUEST ;
|
|
||||||
InvalidRenderInputInline , InvalidRequest , BAD_REQUEST ;
|
InvalidRenderInputInline , InvalidRequest , BAD_REQUEST ;
|
||||||
RenderDocumentNotFound , InvalidRequest , NOT_FOUND ;
|
RenderDocumentNotFound , InvalidRequest , NOT_FOUND ;
|
||||||
TemplateParsingError , InvalidRequest , BAD_REQUEST ;
|
TemplateParsingError , InvalidRequest , BAD_REQUEST ;
|
||||||
|
@ -8,9 +8,8 @@ use index_scheduler::IndexScheduler;
|
|||||||
use liquid::ValueView;
|
use liquid::ValueView;
|
||||||
use meilisearch_types::deserr::DeserrJsonError;
|
use meilisearch_types::deserr::DeserrJsonError;
|
||||||
use meilisearch_types::error::deserr_codes::{
|
use meilisearch_types::error::deserr_codes::{
|
||||||
InvalidRenderInput, InvalidRenderInputDocumentId, InvalidRenderInputFields,
|
InvalidRenderInput, InvalidRenderInputDocumentId, InvalidRenderInputInline,
|
||||||
InvalidRenderInputInline, InvalidRenderTemplate, InvalidRenderTemplateId,
|
InvalidRenderTemplate, InvalidRenderTemplateId, InvalidRenderTemplateInline,
|
||||||
InvalidRenderTemplateInline,
|
|
||||||
};
|
};
|
||||||
use meilisearch_types::error::Code;
|
use meilisearch_types::error::Code;
|
||||||
use meilisearch_types::error::ResponseError;
|
use meilisearch_types::error::ResponseError;
|
||||||
@ -180,11 +179,6 @@ enum RenderError {
|
|||||||
BothInlineDocAndDocId,
|
BothInlineDocAndDocId,
|
||||||
TemplateParsing(json_template::Error),
|
TemplateParsing(json_template::Error),
|
||||||
TemplateRendering(json_template::Error),
|
TemplateRendering(json_template::Error),
|
||||||
|
|
||||||
FieldsUnavailable,
|
|
||||||
FieldsAlreadyPresent,
|
|
||||||
FieldsWithoutDocument,
|
|
||||||
|
|
||||||
CouldNotHandleInput,
|
CouldNotHandleInput,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,18 +318,6 @@ impl From<RenderError> for ResponseError {
|
|||||||
format!("Error rendering template: {}", err.rendering_error("input")),
|
format!("Error rendering template: {}", err.rendering_error("input")),
|
||||||
Code::TemplateRenderingError,
|
Code::TemplateRenderingError,
|
||||||
),
|
),
|
||||||
FieldsUnavailable => ResponseError::from_msg(
|
|
||||||
String::from("Fields are not available on fragments.\n Hint: Remove the `insertFields` parameter or set it to `false`."),
|
|
||||||
Code::InvalidRenderInputFields,
|
|
||||||
),
|
|
||||||
FieldsAlreadyPresent => ResponseError::from_msg(
|
|
||||||
String::from("Fields were provided in the inline input but `insertFields` is set to `true`.\n Hint: Remove the `insertFields` parameter or set it to `false`."),
|
|
||||||
Code::InvalidRenderInputFields,
|
|
||||||
),
|
|
||||||
FieldsWithoutDocument => ResponseError::from_msg(
|
|
||||||
String::from("Fields were requested but no document was provided.\n Hint: Provide a document ID or inline document."),
|
|
||||||
Code::InvalidRenderInputFields,
|
|
||||||
),
|
|
||||||
CouldNotHandleInput => ResponseError::from_msg(
|
CouldNotHandleInput => ResponseError::from_msg(
|
||||||
String::from("Could not handle the input provided."),
|
String::from("Could not handle the input provided."),
|
||||||
Code::InvalidRenderInput,
|
Code::InvalidRenderInput,
|
||||||
@ -478,7 +460,6 @@ async fn render(index: Index, query: RenderQuery) -> Result<RenderResult, Render
|
|||||||
(None, None) => return Err(MissingTemplate),
|
(None, None) => return Err(MissingTemplate),
|
||||||
};
|
};
|
||||||
|
|
||||||
let fields_required = query.input.as_ref().and_then(|i| i.insert_fields);
|
|
||||||
let fields_already_present = query
|
let fields_already_present = query
|
||||||
.input
|
.input
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@ -490,19 +471,8 @@ async fn render(index: Index, query: RenderQuery) -> Result<RenderResult, Render
|
|||||||
.is_some_and(|i| i.inline.as_ref().is_some_and(|i| i.get("doc").is_some()));
|
.is_some_and(|i| i.inline.as_ref().is_some_and(|i| i.get("doc").is_some()));
|
||||||
let has_document_id = query.input.as_ref().is_some_and(|i| i.document_id.is_some());
|
let has_document_id = query.input.as_ref().is_some_and(|i| i.document_id.is_some());
|
||||||
let has_doc = has_inline_doc || has_document_id;
|
let has_doc = has_inline_doc || has_document_id;
|
||||||
let insert_fields = match fields_required {
|
let insert_fields =
|
||||||
Some(insert_fields) => insert_fields,
|
fields_available && has_doc && fields_probably_used && !fields_already_present;
|
||||||
None => fields_available && has_doc && fields_probably_used && !fields_already_present,
|
|
||||||
};
|
|
||||||
if insert_fields && !fields_available {
|
|
||||||
return Err(FieldsUnavailable);
|
|
||||||
}
|
|
||||||
if insert_fields && fields_already_present {
|
|
||||||
return Err(FieldsAlreadyPresent);
|
|
||||||
}
|
|
||||||
if insert_fields && !has_doc {
|
|
||||||
return Err(FieldsWithoutDocument);
|
|
||||||
}
|
|
||||||
if has_inline_doc && has_document_id {
|
if has_inline_doc && has_document_id {
|
||||||
return Err(BothInlineDocAndDocId);
|
return Err(BothInlineDocAndDocId);
|
||||||
}
|
}
|
||||||
@ -561,8 +531,6 @@ pub struct RenderQueryTemplate {
|
|||||||
pub struct RenderQueryInput {
|
pub struct RenderQueryInput {
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidRenderInputDocumentId>)]
|
#[deserr(default, error = DeserrJsonError<InvalidRenderInputDocumentId>)]
|
||||||
pub document_id: Option<String>,
|
pub document_id: Option<String>,
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidRenderInputFields>)]
|
|
||||||
pub insert_fields: Option<bool>,
|
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidRenderInputInline>)]
|
#[deserr(default, error = DeserrJsonError<InvalidRenderInputInline>)]
|
||||||
pub inline: Option<BTreeMap<String, serde_json::Value>>,
|
pub inline: Option<BTreeMap<String, serde_json::Value>>,
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,6 @@ pub struct RenderAggregator {
|
|||||||
input_inline: bool,
|
input_inline: bool,
|
||||||
input_id: bool,
|
input_id: bool,
|
||||||
input_omitted: bool,
|
input_omitted: bool,
|
||||||
fields_forced: bool,
|
|
||||||
fields_disabled: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderAggregator {
|
impl RenderAggregator {
|
||||||
@ -33,8 +31,6 @@ impl RenderAggregator {
|
|||||||
ret.input_inline = input.as_ref().is_some_and(|i| i.inline.is_some());
|
ret.input_inline = input.as_ref().is_some_and(|i| i.inline.is_some());
|
||||||
ret.input_id = input.as_ref().is_some_and(|i| i.document_id.is_some());
|
ret.input_id = input.as_ref().is_some_and(|i| i.document_id.is_some());
|
||||||
ret.input_omitted = input.as_ref().is_none();
|
ret.input_omitted = input.as_ref().is_none();
|
||||||
ret.fields_forced = input.as_ref().is_some_and(|i| i.insert_fields.is_some());
|
|
||||||
ret.fields_disabled = input.as_ref().is_some_and(|i| i.insert_fields.is_none());
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
@ -58,8 +54,6 @@ impl Aggregate for RenderAggregator {
|
|||||||
self.input_inline |= new.input_inline;
|
self.input_inline |= new.input_inline;
|
||||||
self.input_id |= new.input_id;
|
self.input_id |= new.input_id;
|
||||||
self.input_omitted |= new.input_omitted;
|
self.input_omitted |= new.input_omitted;
|
||||||
self.fields_forced |= new.fields_forced;
|
|
||||||
self.fields_disabled |= new.fields_disabled;
|
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -73,8 +67,6 @@ impl Aggregate for RenderAggregator {
|
|||||||
input_inline,
|
input_inline,
|
||||||
input_id,
|
input_id,
|
||||||
input_omitted,
|
input_omitted,
|
||||||
fields_forced,
|
|
||||||
fields_disabled,
|
|
||||||
} = *self;
|
} = *self;
|
||||||
|
|
||||||
json!({
|
json!({
|
||||||
@ -90,9 +82,7 @@ impl Aggregate for RenderAggregator {
|
|||||||
"input": {
|
"input": {
|
||||||
"inline": input_inline,
|
"inline": input_inline,
|
||||||
"id": input_id,
|
"id": input_id,
|
||||||
"omitted": input_omitted,
|
"omitted": input_omitted
|
||||||
"fields_forced": fields_forced,
|
|
||||||
"fields_disabled": fields_disabled,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -501,59 +501,6 @@ async fn multiple_templates_or_docs() {
|
|||||||
"#);
|
"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn fields() {
|
|
||||||
let index = shared_index_for_fragments().await;
|
|
||||||
|
|
||||||
let (value, code) = index
|
|
||||||
.render(json! {{
|
|
||||||
"template": { "inline": "whatever" },
|
|
||||||
"input": { "insertFields": true }
|
|
||||||
}})
|
|
||||||
.await;
|
|
||||||
snapshot!(code, @"400 Bad Request");
|
|
||||||
snapshot!(value, @r#"
|
|
||||||
{
|
|
||||||
"message": "Fields were requested but no document was provided.\n Hint: Provide a document ID or inline document.",
|
|
||||||
"code": "invalid_render_input_fields",
|
|
||||||
"type": "invalid_request",
|
|
||||||
"link": "https://docs.meilisearch.com/errors#invalid_render_input_fields"
|
|
||||||
}
|
|
||||||
"#);
|
|
||||||
|
|
||||||
let (value, code) = index
|
|
||||||
.render(json! {{
|
|
||||||
"template": { "id": "embedders.rest.indexingFragments.basic" },
|
|
||||||
"input": { "documentId": "0", "insertFields": true }
|
|
||||||
}})
|
|
||||||
.await;
|
|
||||||
snapshot!(code, @"400 Bad Request");
|
|
||||||
snapshot!(value, @r#"
|
|
||||||
{
|
|
||||||
"message": "Fields are not available on fragments.\n Hint: Remove the `insertFields` parameter or set it to `false`.",
|
|
||||||
"code": "invalid_render_input_fields",
|
|
||||||
"type": "invalid_request",
|
|
||||||
"link": "https://docs.meilisearch.com/errors#invalid_render_input_fields"
|
|
||||||
}
|
|
||||||
"#);
|
|
||||||
|
|
||||||
let (value, code) = index
|
|
||||||
.render(json! {{
|
|
||||||
"template": { "inline": "whatever" },
|
|
||||||
"input": { "documentId": "0", "inline": { "fields": {} }, "insertFields": true }
|
|
||||||
}})
|
|
||||||
.await;
|
|
||||||
snapshot!(code, @"400 Bad Request");
|
|
||||||
snapshot!(value, @r#"
|
|
||||||
{
|
|
||||||
"message": "Fields were provided in the inline input but `insertFields` is set to `true`.\n Hint: Remove the `insertFields` parameter or set it to `false`.",
|
|
||||||
"code": "invalid_render_input_fields",
|
|
||||||
"type": "invalid_request",
|
|
||||||
"link": "https://docs.meilisearch.com/errors#invalid_render_input_fields"
|
|
||||||
}
|
|
||||||
"#);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn document_not_found() {
|
async fn document_not_found() {
|
||||||
let index = shared_index_for_fragments().await;
|
let index = shared_index_for_fragments().await;
|
||||||
|
Reference in New Issue
Block a user