mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-20 11:46:25 +00:00
Fix errors, clippy warnings, and add review comments
This commit is contained in:
@ -1,14 +1,9 @@
|
||||
/*!
|
||||
This module tests the `geo_sort` ranking rule:
|
||||
|
||||
1. an error is returned if the sort ranking rule exists but no fields-to-sort were given at search time
|
||||
2. an error is returned if the fields-to-sort are not sortable
|
||||
3. it is possible to add multiple fields-to-sort at search time
|
||||
4. custom sort ranking rules can be added to the settings, they interact with the generic `sort` ranking rule as expected
|
||||
5. numbers appear before strings
|
||||
6. documents with either: (1) no value, (2) null, or (3) an object for the field-to-sort appear at the end of the bucket
|
||||
7. boolean values are translated to strings
|
||||
8. if a field contains an array, it is sorted by the best value in the array according to the sort rule
|
||||
REVIEW COMMENT:
|
||||
- nice tests :)
|
||||
- add anything that seems not obvious about the behaviour of the geosort ranking rule here
|
||||
*/
|
||||
|
||||
use big_s::S;
|
||||
@ -40,21 +35,21 @@ fn execute_iterative_and_rtree_returns_the_same<'a>(
|
||||
) -> Vec<usize> {
|
||||
search.geo_sort_strategy(GeoSortStrategy::AlwaysIterative(2));
|
||||
let SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||
let iterative_ids_bucketed = collect_field_values(&index, rtxn, "id", &documents_ids);
|
||||
let iterative_ids_bucketed = collect_field_values(index, rtxn, "id", &documents_ids);
|
||||
|
||||
search.geo_sort_strategy(GeoSortStrategy::AlwaysIterative(1000));
|
||||
let SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||
let iterative_ids = collect_field_values(&index, rtxn, "id", &documents_ids);
|
||||
let iterative_ids = collect_field_values(index, rtxn, "id", &documents_ids);
|
||||
|
||||
assert_eq!(iterative_ids_bucketed, iterative_ids, "iterative bucket");
|
||||
|
||||
search.geo_sort_strategy(GeoSortStrategy::AlwaysRtree(2));
|
||||
let SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||
let rtree_ids_bucketed = collect_field_values(&index, rtxn, "id", &documents_ids);
|
||||
let rtree_ids_bucketed = collect_field_values(index, rtxn, "id", &documents_ids);
|
||||
|
||||
search.geo_sort_strategy(GeoSortStrategy::AlwaysRtree(1000));
|
||||
let SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||
let rtree_ids = collect_field_values(&index, rtxn, "id", &documents_ids);
|
||||
let rtree_ids = collect_field_values(index, rtxn, "id", &documents_ids);
|
||||
|
||||
assert_eq!(rtree_ids_bucketed, rtree_ids, "rtree bucket");
|
||||
|
||||
@ -67,15 +62,24 @@ fn execute_iterative_and_rtree_returns_the_same<'a>(
|
||||
fn test_geo_sort() {
|
||||
let index = create_index();
|
||||
|
||||
// REVIEW COMMENT:
|
||||
// I prefer to make the external ids correspond to the internal ids so that
|
||||
// we can check whether the ranking rules are actually doing work instead of
|
||||
// returning documents in order of their internal ids.
|
||||
//
|
||||
index
|
||||
.add_documents(documents!([
|
||||
{ "id": 2, "_geo": { "lat": 2, "lng": -1 } },
|
||||
{ "id": 3, "_geo": { "lat": -2, "lng": -2 } },
|
||||
{ "id": 5, "_geo": { "lat": 6, "lng": -5 } },
|
||||
{ "id": 4, "_geo": { "lat": 3, "lng": 5 } },
|
||||
{ "id": 0, "_geo": { "lat": 0, "lng": 0 } },
|
||||
{ "id": 1, "_geo": { "lat": 1, "lng": 1 } },
|
||||
{ "id": 6 }, { "id": 8 }, { "id": 7 }, { "id": 10 }, { "id": 9 },
|
||||
{ "id": 0, "_geo": { "lat": 2, "lng": -1 } },
|
||||
{ "id": 1, "_geo": { "lat": -2, "lng": -2 } },
|
||||
{ "id": 2, "_geo": { "lat": 6, "lng": -5 } },
|
||||
{ "id": 3, "_geo": { "lat": 3, "lng": 5 } },
|
||||
{ "id": 4, "_geo": { "lat": 0, "lng": 0 } },
|
||||
{ "id": 5, "_geo": { "lat": 1, "lng": 1 } },
|
||||
{ "id": 6 },
|
||||
{ "id": 7 },
|
||||
{ "id": 8 },
|
||||
{ "id": 9 },
|
||||
{ "id": 10 },
|
||||
]))
|
||||
.unwrap();
|
||||
|
||||
@ -88,66 +92,54 @@ fn test_geo_sort() {
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::Dynamic(100));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["0", "1", "2", "3", "4", "5", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[4, 5, 0, 1, 3, 2, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::Dynamic(3));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["0", "1", "2", "3", "4", "5", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[4, 5, 0, 1, 3, 2, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::AlwaysIterative(100));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["0", "1", "2", "3", "4", "5", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[4, 5, 0, 1, 3, 2, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::AlwaysIterative(3));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["0", "1", "2", "3", "4", "5", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[4, 5, 0, 1, 3, 2, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::AlwaysRtree(100));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["0", "1", "2", "3", "4", "5", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[4, 5, 0, 1, 3, 2, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::AlwaysRtree(3));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["0", "1", "2", "3", "4", "5", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[4, 5, 0, 1, 3, 2, 6, 7, 8, 9, 10]");
|
||||
|
||||
// --- desc
|
||||
s.sort_criteria(vec![AscDesc::Desc(Member::Geo([0., 0.]))]);
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::Dynamic(100));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["5", "4", "3", "2", "1", "0", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[2, 3, 1, 0, 5, 4, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::Dynamic(3));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["5", "4", "3", "2", "1", "0", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[2, 3, 1, 0, 5, 4, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::AlwaysIterative(100));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["5", "4", "3", "2", "1", "0", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[2, 3, 1, 0, 5, 4, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::AlwaysIterative(3));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["5", "4", "3", "2", "1", "0", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[2, 3, 1, 0, 5, 4, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::AlwaysRtree(100));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["5", "4", "3", "2", "1", "0", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[2, 3, 1, 0, 5, 4, 6, 7, 8, 9, 10]");
|
||||
|
||||
s.geo_sort_strategy(GeoSortStrategy::AlwaysRtree(3));
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
let ids = collect_field_values(&index, &txn, "id", &documents_ids);
|
||||
insta::assert_snapshot!(format!("{ids:?}"), @r###"["5", "4", "3", "2", "1", "0", "6", "8", "7", "10", "9"]"###);
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[2, 3, 1, 0, 5, 4, 6, 7, 8, 9, 10]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user