Skip to content

Commit 00acb01

Browse files
meili-bors[bot]Vedmak
and
Vedmak
authored
Merge #478
478: Fix json serialization error if meilisearch response contains facet_stats r=bidoubiwa a=Vedmak # Pull Request ## Related issue Fixes #474 ## What does this PR do? - change field types of FacetStats struct from u32 to f64 - add test for facet_stats ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Vedmak <[email protected]>
2 parents 1181462 + 49c18fa commit 00acb01

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

src/search.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ pub struct SearchResult<T> {
5050
#[derive(Deserialize, Debug, Clone)]
5151
#[serde(rename_all = "camelCase")]
5252
pub struct FacetStats {
53-
pub min: u32,
54-
pub max: u32,
53+
pub min: f64,
54+
pub max: f64,
5555
}
5656
#[derive(Deserialize, Debug, Clone)]
5757
#[serde(rename_all = "camelCase")]
@@ -557,6 +557,7 @@ mod tests {
557557
id: usize,
558558
value: String,
559559
kind: String,
560+
number: i32,
560561
nested: Nested,
561562
}
562563

@@ -570,18 +571,20 @@ mod tests {
570571

571572
async fn setup_test_index(client: &Client, index: &Index) -> Result<(), Error> {
572573
let t0 = index.add_documents(&[
573-
Document { id: 0, kind: "text".into(), value: S("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."), nested: Nested { child: S("first") } },
574-
Document { id: 1, kind: "text".into(), value: S("dolor sit amet, consectetur adipiscing elit"), nested: Nested { child: S("second") } },
575-
Document { id: 2, kind: "title".into(), value: S("The Social Network"), nested: Nested { child: S("third") } },
576-
Document { id: 3, kind: "title".into(), value: S("Harry Potter and the Sorcerer's Stone"), nested: Nested { child: S("fourth") } },
577-
Document { id: 4, kind: "title".into(), value: S("Harry Potter and the Chamber of Secrets"), nested: Nested { child: S("fift") } },
578-
Document { id: 5, kind: "title".into(), value: S("Harry Potter and the Prisoner of Azkaban"), nested: Nested { child: S("sixth") } },
579-
Document { id: 6, kind: "title".into(), value: S("Harry Potter and the Goblet of Fire"), nested: Nested { child: S("seventh") } },
580-
Document { id: 7, kind: "title".into(), value: S("Harry Potter and the Order of the Phoenix"), nested: Nested { child: S("eighth") } },
581-
Document { id: 8, kind: "title".into(), value: S("Harry Potter and the Half-Blood Prince"), nested: Nested { child: S("ninth") } },
582-
Document { id: 9, kind: "title".into(), value: S("Harry Potter and the Deathly Hallows"), nested: Nested { child: S("tenth") } },
574+
Document { id: 0, kind: "text".into(), number: 0, value: S("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."), nested: Nested { child: S("first") } },
575+
Document { id: 1, kind: "text".into(), number: 10, value: S("dolor sit amet, consectetur adipiscing elit"), nested: Nested { child: S("second") } },
576+
Document { id: 2, kind: "title".into(), number: 20, value: S("The Social Network"), nested: Nested { child: S("third") } },
577+
Document { id: 3, kind: "title".into(), number: 30, value: S("Harry Potter and the Sorcerer's Stone"), nested: Nested { child: S("fourth") } },
578+
Document { id: 4, kind: "title".into(), number: 40, value: S("Harry Potter and the Chamber of Secrets"), nested: Nested { child: S("fift") } },
579+
Document { id: 5, kind: "title".into(), number: 50, value: S("Harry Potter and the Prisoner of Azkaban"), nested: Nested { child: S("sixth") } },
580+
Document { id: 6, kind: "title".into(), number: 60, value: S("Harry Potter and the Goblet of Fire"), nested: Nested { child: S("seventh") } },
581+
Document { id: 7, kind: "title".into(), number: 70, value: S("Harry Potter and the Order of the Phoenix"), nested: Nested { child: S("eighth") } },
582+
Document { id: 8, kind: "title".into(), number: 80, value: S("Harry Potter and the Half-Blood Prince"), nested: Nested { child: S("ninth") } },
583+
Document { id: 9, kind: "title".into(), number: 90, value: S("Harry Potter and the Deathly Hallows"), nested: Nested { child: S("tenth") } },
583584
], None).await?;
584-
let t1 = index.set_filterable_attributes(["kind", "value"]).await?;
585+
let t1 = index
586+
.set_filterable_attributes(["kind", "value", "number"])
587+
.await?;
585588
let t2 = index.set_sortable_attributes(["title"]).await?;
586589

587590
t2.wait_for_completion(client, None, None).await?;
@@ -664,6 +667,7 @@ mod tests {
664667
id: 1,
665668
value: S("dolor sit amet, consectetur adipiscing elit"),
666669
kind: S("text"),
670+
number: 10,
667671
nested: Nested { child: S("second") }
668672
},
669673
&results.hits[0].result
@@ -793,6 +797,22 @@ mod tests {
793797
Ok(())
794798
}
795799

800+
#[meilisearch_test]
801+
async fn test_query_facet_stats(client: Client, index: Index) -> Result<(), Error> {
802+
setup_test_index(&client, &index).await?;
803+
804+
let mut query = SearchQuery::new(&index);
805+
query.with_facets(Selectors::All);
806+
let results: SearchResults<Document> = index.execute_query(&query).await?;
807+
let facet_stats = results.facet_stats.unwrap();
808+
809+
assert_eq!(facet_stats.get("number").unwrap().min, 0.0);
810+
811+
assert_eq!(facet_stats.get("number").unwrap().max, 90.0);
812+
813+
Ok(())
814+
}
815+
796816
#[meilisearch_test]
797817
async fn test_query_attributes_to_retrieve(client: Client, index: Index) -> Result<(), Error> {
798818
setup_test_index(&client, &index).await?;
@@ -835,6 +855,7 @@ mod tests {
835855
id: 0,
836856
value: S("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do…"),
837857
kind: S("text"),
858+
number: 0,
838859
nested: Nested { child: S("first") }
839860
},
840861
results.hits[0].formatted_result.as_ref().unwrap()
@@ -849,6 +870,7 @@ mod tests {
849870
id: 0,
850871
value: S("Lorem ipsum dolor sit amet…"),
851872
kind: S("text"),
873+
number: 0,
852874
nested: Nested { child: S("first") }
853875
},
854876
results.hits[0].formatted_result.as_ref().unwrap()
@@ -869,6 +891,7 @@ mod tests {
869891
id: 0,
870892
value: S("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
871893
kind: S("text"),
894+
number: 0,
872895
nested: Nested { child: S("first") }
873896
},
874897
results.hits[0].formatted_result.as_ref().unwrap());
@@ -883,6 +906,7 @@ mod tests {
883906
id: 0,
884907
value: S("Lorem ipsum dolor sit amet…"),
885908
kind: S("text"),
909+
number: 0,
886910
nested: Nested { child: S("first") }
887911
},
888912
results.hits[0].formatted_result.as_ref().unwrap()
@@ -907,6 +931,7 @@ mod tests {
907931
id: 0,
908932
value: S("(ꈍᴗꈍ) sed do eiusmod tempor incididunt ut(ꈍᴗꈍ)"),
909933
kind: S("text"),
934+
number: 0,
910935
nested: Nested { child: S("first") }
911936
},
912937
results.hits[0].formatted_result.as_ref().unwrap()
@@ -933,6 +958,7 @@ mod tests {
933958
id: 2,
934959
value: S("The (⊃。•́‿•̀。)⊃ Social ⊂(´• ω •`⊂) Network"),
935960
kind: S("title"),
961+
number: 20,
936962
nested: Nested { child: S("third") }
937963
},
938964
results.hits[0].formatted_result.as_ref().unwrap()
@@ -954,6 +980,7 @@ mod tests {
954980
id: 1,
955981
value: S("<em>dolor</em> sit amet, consectetur adipiscing elit"),
956982
kind: S("<em>text</em>"),
983+
number: 10,
957984
nested: Nested { child: S("first") }
958985
},
959986
results.hits[0].formatted_result.as_ref().unwrap(),
@@ -968,6 +995,7 @@ mod tests {
968995
id: 1,
969996
value: S("<em>dolor</em> sit amet, consectetur adipiscing elit"),
970997
kind: S("text"),
998+
number: 10,
971999
nested: Nested { child: S("first") }
9721000
},
9731001
results.hits[0].formatted_result.as_ref().unwrap()

0 commit comments

Comments
 (0)