mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
fix bug around nested fields
This commit is contained in:
parent
d7844a6e45
commit
43875e6758
@ -280,23 +280,27 @@ async fn distinct_at_search_time() {
|
|||||||
|
|
||||||
let documents = NESTED_DOCUMENTS.clone();
|
let documents = NESTED_DOCUMENTS.clone();
|
||||||
index.add_documents(documents, Some(DOCUMENT_PRIMARY_KEY)).await;
|
index.add_documents(documents, Some(DOCUMENT_PRIMARY_KEY)).await;
|
||||||
index.update_settings_filterable_attributes(json!(["color"])).await;
|
let (task, _) = index.update_settings_filterable_attributes(json!(["color.main"])).await;
|
||||||
index.wait_task(1).await;
|
let task = index.wait_task(task.uid()).await;
|
||||||
|
snapshot!(task, name: "succeed");
|
||||||
|
|
||||||
fn get_hits(response: &Value) -> Vec<&str> {
|
fn get_hits(response: &Value) -> Vec<String> {
|
||||||
let hits_array = response["hits"]
|
let hits_array = response["hits"]
|
||||||
.as_array()
|
.as_array()
|
||||||
.unwrap_or_else(|| panic!("{}", &serde_json::to_string_pretty(&response).unwrap()));
|
.unwrap_or_else(|| panic!("{}", &serde_json::to_string_pretty(&response).unwrap()));
|
||||||
hits_array.iter().map(|h| h[DOCUMENT_DISTINCT_KEY].as_str().unwrap()).collect::<Vec<_>>()
|
hits_array
|
||||||
|
.iter()
|
||||||
|
.map(|h| h[DOCUMENT_PRIMARY_KEY].as_number().unwrap().to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
let (response, code) =
|
let (response, code) =
|
||||||
index.search_post(json!({"page": 0, "hitsPerPage": 2, "distinct": "color.main"})).await;
|
index.search_post(json!({"page": 1, "hitsPerPage": 3, "distinct": "color.main"})).await;
|
||||||
let hits = get_hits(&response);
|
let hits = get_hits(&response);
|
||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
snapshot!(hits.len(), @"0");
|
snapshot!(hits.len(), @"3");
|
||||||
snapshot!(format!("{:?}", hits), @r#"[]"#);
|
snapshot!(format!("{:?}", hits), @r###"["1", "2", "3"]"###);
|
||||||
snapshot!(response["page"], @"0");
|
snapshot!(response["page"], @"1");
|
||||||
snapshot!(response["totalPages"], @"3");
|
snapshot!(response["totalPages"], @"1");
|
||||||
snapshot!(response["totalHits"], @"6");
|
snapshot!(response["totalHits"], @"3");
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ impl<'a> Search<'a> {
|
|||||||
|
|
||||||
if let Some(distinct) = &self.distinct {
|
if let Some(distinct) = &self.distinct {
|
||||||
let filterable_fields = ctx.index.filterable_fields(ctx.txn)?;
|
let filterable_fields = ctx.index.filterable_fields(ctx.txn)?;
|
||||||
if !filterable_fields.contains(distinct) {
|
if !crate::is_faceted(distinct, &filterable_fields) {
|
||||||
let (valid_fields, hidden_fields) =
|
let (valid_fields, hidden_fields) =
|
||||||
ctx.index.remove_hidden_fields(ctx.txn, filterable_fields)?;
|
ctx.index.remove_hidden_fields(ctx.txn, filterable_fields)?;
|
||||||
return Err(Error::UserError(UserError::InvalidDistinctAttribute {
|
return Err(Error::UserError(UserError::InvalidDistinctAttribute {
|
||||||
|
Loading…
Reference in New Issue
Block a user