mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 03:55:07 +08:00
Merge #2543
2543: fix all the array on the search get route and improve the tests r=curquiza a=irevoire fix #2527 Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
commit
9e261b996f
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -2069,7 +2069,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde-cs",
|
"serde-cs",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_url_params",
|
|
||||||
"sha-1",
|
"sha-1",
|
||||||
"sha2",
|
"sha2",
|
||||||
"siphasher",
|
"siphasher",
|
||||||
@ -2087,6 +2086,7 @@ dependencies = [
|
|||||||
"uuid",
|
"uuid",
|
||||||
"vergen",
|
"vergen",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
|
"yaup",
|
||||||
"zip",
|
"zip",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -3113,16 +3113,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_url_params"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2c43307d0640738af32fe8d01e47119bc0fc8a686be470a44a586caff76dfb34"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
"url",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_urlencoded"
|
name = "serde_urlencoded"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
@ -3994,6 +3984,16 @@ version = "0.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6d12cb7a57bbf2ab670ed9545bae3648048547f9039279a89ce000208e585c1"
|
checksum = "b6d12cb7a57bbf2ab670ed9545bae3648048547f9039279a89ce000208e585c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yaup"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f8e1d3d18db742c8b9ad2f5f3c5bf5b63aa67b9933617c8f8350d39a3c173c6"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
@ -83,8 +83,8 @@ actix-rt = "2.7.0"
|
|||||||
assert-json-diff = "2.0.1"
|
assert-json-diff = "2.0.1"
|
||||||
manifest-dir-macros = "0.1.14"
|
manifest-dir-macros = "0.1.14"
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
serde_url_params = "0.2.1"
|
|
||||||
urlencoding = "2.1.0"
|
urlencoding = "2.1.0"
|
||||||
|
yaup = "0.1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["analytics", "mini-dashboard"]
|
default = ["analytics", "mini-dashboard"]
|
||||||
|
@ -14,7 +14,6 @@ use serde_json::Value;
|
|||||||
use crate::analytics::{Analytics, SearchAggregator};
|
use crate::analytics::{Analytics, SearchAggregator};
|
||||||
use crate::extractors::authentication::{policies::*, GuardedData};
|
use crate::extractors::authentication::{policies::*, GuardedData};
|
||||||
use crate::extractors::sequential_extractor::SeqHandler;
|
use crate::extractors::sequential_extractor::SeqHandler;
|
||||||
use crate::routes::{fold_star_or, StarOr};
|
|
||||||
|
|
||||||
pub fn configure(cfg: &mut web::ServiceConfig) {
|
pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(
|
cfg.service(
|
||||||
@ -30,16 +29,16 @@ pub struct SearchQueryGet {
|
|||||||
q: Option<String>,
|
q: Option<String>,
|
||||||
offset: Option<usize>,
|
offset: Option<usize>,
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
attributes_to_retrieve: Option<CS<StarOr<String>>>,
|
attributes_to_retrieve: Option<CS<String>>,
|
||||||
attributes_to_crop: Option<CS<StarOr<String>>>,
|
attributes_to_crop: Option<CS<String>>,
|
||||||
#[serde(default = "DEFAULT_CROP_LENGTH")]
|
#[serde(default = "DEFAULT_CROP_LENGTH")]
|
||||||
crop_length: usize,
|
crop_length: usize,
|
||||||
attributes_to_highlight: Option<CS<StarOr<String>>>,
|
attributes_to_highlight: Option<CS<String>>,
|
||||||
filter: Option<String>,
|
filter: Option<String>,
|
||||||
sort: Option<String>,
|
sort: Option<String>,
|
||||||
#[serde(default = "Default::default")]
|
#[serde(default = "Default::default")]
|
||||||
show_matches_position: bool,
|
show_matches_position: bool,
|
||||||
facets: Option<CS<StarOr<String>>>,
|
facets: Option<CS<String>>,
|
||||||
#[serde(default = "DEFAULT_HIGHLIGHT_PRE_TAG")]
|
#[serde(default = "DEFAULT_HIGHLIGHT_PRE_TAG")]
|
||||||
highlight_pre_tag: String,
|
highlight_pre_tag: String,
|
||||||
#[serde(default = "DEFAULT_HIGHLIGHT_POST_TAG")]
|
#[serde(default = "DEFAULT_HIGHLIGHT_POST_TAG")]
|
||||||
@ -62,14 +61,18 @@ impl From<SearchQueryGet> for SearchQuery {
|
|||||||
q: other.q,
|
q: other.q,
|
||||||
offset: other.offset,
|
offset: other.offset,
|
||||||
limit: other.limit.unwrap_or_else(DEFAULT_SEARCH_LIMIT),
|
limit: other.limit.unwrap_or_else(DEFAULT_SEARCH_LIMIT),
|
||||||
attributes_to_retrieve: other.attributes_to_retrieve.and_then(fold_star_or),
|
attributes_to_retrieve: other
|
||||||
attributes_to_crop: other.attributes_to_crop.and_then(fold_star_or),
|
.attributes_to_retrieve
|
||||||
|
.map(|o| o.into_iter().collect()),
|
||||||
|
attributes_to_crop: other.attributes_to_crop.map(|o| o.into_iter().collect()),
|
||||||
crop_length: other.crop_length,
|
crop_length: other.crop_length,
|
||||||
attributes_to_highlight: other.attributes_to_highlight.and_then(fold_star_or),
|
attributes_to_highlight: other
|
||||||
|
.attributes_to_highlight
|
||||||
|
.map(|o| o.into_iter().collect()),
|
||||||
filter,
|
filter,
|
||||||
sort: other.sort.map(|attr| fix_sort_query_parameters(&attr)),
|
sort: other.sort.map(|attr| fix_sort_query_parameters(&attr)),
|
||||||
show_matches_position: other.show_matches_position,
|
show_matches_position: other.show_matches_position,
|
||||||
facets: other.facets.and_then(fold_star_or),
|
facets: other.facets.map(|o| o.into_iter().collect()),
|
||||||
highlight_pre_tag: other.highlight_pre_tag,
|
highlight_pre_tag: other.highlight_pre_tag,
|
||||||
highlight_post_tag: other.highlight_post_tag,
|
highlight_post_tag: other.highlight_post_tag,
|
||||||
crop_marker: other.crop_marker,
|
crop_marker: other.crop_marker,
|
||||||
|
@ -221,7 +221,7 @@ impl Index<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn search_get(&self, query: Value) -> (Value, StatusCode) {
|
pub async fn search_get(&self, query: Value) -> (Value, StatusCode) {
|
||||||
let params = serde_url_params::to_string(&query).unwrap();
|
let params = yaup::to_string(&query).unwrap();
|
||||||
let url = format!("/indexes/{}/search?{}", encode(self.uid.as_ref()), params);
|
let url = format!("/indexes/{}/search?{}", encode(self.uid.as_ref()), params);
|
||||||
self.service.get(url).await
|
self.service.get(url).await
|
||||||
}
|
}
|
||||||
|
@ -45,26 +45,18 @@ async fn search_invalid_highlight_and_crop_tags() {
|
|||||||
|
|
||||||
for field in fields {
|
for field in fields {
|
||||||
// object
|
// object
|
||||||
index
|
let (response, code) = index
|
||||||
.search(
|
.search_post(json!({field.to_string(): {"marker": "<crop>"}}))
|
||||||
json!({field.to_string(): {"marker": "<crop>"}}),
|
|
||||||
|response, code| {
|
|
||||||
assert_eq!(code, 400, "field {} passing object: {}", &field, response);
|
|
||||||
assert_eq!(response["code"], "bad_request");
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
|
assert_eq!(code, 400, "field {} passing object: {}", &field, response);
|
||||||
|
assert_eq!(response["code"], "bad_request");
|
||||||
|
|
||||||
// array
|
// array
|
||||||
index
|
let (response, code) = index
|
||||||
.search(
|
.search_post(json!({field.to_string(): ["marker", "<crop>"]}))
|
||||||
json!({field.to_string(): ["marker", "<crop>"]}),
|
|
||||||
|response, code| {
|
|
||||||
assert_eq!(code, 400, "field {} passing array: {}", &field, response);
|
|
||||||
assert_eq!(response["code"], "bad_request");
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
|
assert_eq!(code, 400, "field {} passing array: {}", &field, response);
|
||||||
|
assert_eq!(response["code"], "bad_request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,20 +15,23 @@ async fn formatted_contain_wildcard() {
|
|||||||
index.add_documents(documents, None).await;
|
index.add_documents(documents, None).await;
|
||||||
index.wait_task(1).await;
|
index.wait_task(1).await;
|
||||||
|
|
||||||
let (response, code) = index
|
index.search(json!({ "q": "pesti", "attributesToRetrieve": ["father", "mother"], "attributesToHighlight": ["father", "mother", "*"], "attributesToCrop": ["doggos"], "showMatchesPosition": true }),
|
||||||
.search_post(json!({ "q": "pesti", "attributesToRetrieve": ["father", "mother"], "attributesToHighlight": ["father", "mother", "*"], "attributesToCrop": ["doggos"], "showMatchesPosition": true }))
|
|response, code|
|
||||||
.await;
|
{
|
||||||
assert_eq!(code, 200, "{}", response);
|
assert_eq!(code, 200, "{}", response);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
response["hits"][0],
|
response["hits"][0],
|
||||||
json!({
|
json!({
|
||||||
"_formatted": {
|
"_formatted": {
|
||||||
"id": "852",
|
"id": "852",
|
||||||
"cattos": "<em>pesti</em>",
|
"cattos": "<em>pesti</em>",
|
||||||
},
|
},
|
||||||
"_matchesPosition": {"cattos": [{"start": 0, "length": 5}]},
|
"_matchesPosition": {"cattos": [{"start": 0, "length": 5}]},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
let (response, code) = index
|
let (response, code) = index
|
||||||
.search_post(json!({ "q": "pesti", "attributesToRetrieve": ["*"] }))
|
.search_post(json!({ "q": "pesti", "attributesToRetrieve": ["*"] }))
|
||||||
|
Loading…
Reference in New Issue
Block a user