mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-14 08:46:26 +00:00
Merge #523
523: Improve geosearch error messages r=irevoire a=irevoire Improve the geosearch error messages (#488). And try to parse the string as specified in https://github.com/meilisearch/meilisearch/issues/2354 Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
@ -1006,6 +1006,135 @@ mod tests {
|
||||
wtxn.commit().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_all_flavour_of_geo() {
|
||||
let path = tempfile::tempdir().unwrap();
|
||||
let mut options = EnvOpenOptions::new();
|
||||
options.map_size(10 * 1024 * 1024); // 10 MB
|
||||
let index = Index::new(options, &path).unwrap();
|
||||
|
||||
let config = IndexerConfig::default();
|
||||
let mut wtxn = index.write_txn().unwrap();
|
||||
let mut builder = update::Settings::new(&mut wtxn, &index, &config);
|
||||
|
||||
builder.set_filterable_fields(hashset!(S("_geo")));
|
||||
builder.execute(|_| ()).unwrap();
|
||||
wtxn.commit().unwrap();
|
||||
|
||||
let indexing_config = IndexDocumentsConfig {
|
||||
update_method: IndexDocumentsMethod::ReplaceDocuments,
|
||||
..Default::default()
|
||||
};
|
||||
let mut wtxn = index.write_txn().unwrap();
|
||||
|
||||
let documents = documents!([
|
||||
{ "id": 0, "_geo": { "lat": 31, "lng": [42] } },
|
||||
{ "id": 1, "_geo": { "lat": "31" }, "_geo.lng": 42 },
|
||||
{ "id": 2, "_geo": { "lng": "42" }, "_geo.lat": "31" },
|
||||
{ "id": 3, "_geo.lat": 31, "_geo.lng": "42" },
|
||||
]);
|
||||
let mut builder =
|
||||
IndexDocuments::new(&mut wtxn, &index, &config, indexing_config.clone(), |_| ())
|
||||
.unwrap();
|
||||
builder.add_documents(documents).unwrap();
|
||||
builder.execute().unwrap();
|
||||
wtxn.commit().unwrap();
|
||||
|
||||
let rtxn = index.read_txn().unwrap();
|
||||
|
||||
let mut search = crate::Search::new(&rtxn, &index);
|
||||
search.filter(crate::Filter::from_str("_geoRadius(31, 42, 0.000001)").unwrap().unwrap());
|
||||
let crate::SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||
assert_eq!(documents_ids, vec![0, 1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn geo_error() {
|
||||
let path = tempfile::tempdir().unwrap();
|
||||
let mut options = EnvOpenOptions::new();
|
||||
options.map_size(10 * 1024 * 1024); // 10 MB
|
||||
let index = Index::new(options, &path).unwrap();
|
||||
|
||||
let config = IndexerConfig::default();
|
||||
let mut wtxn = index.write_txn().unwrap();
|
||||
let mut builder = update::Settings::new(&mut wtxn, &index, &config);
|
||||
|
||||
builder.set_filterable_fields(hashset!(S("_geo")));
|
||||
builder.execute(|_| ()).unwrap();
|
||||
wtxn.commit().unwrap();
|
||||
|
||||
let indexing_config = IndexDocumentsConfig {
|
||||
update_method: IndexDocumentsMethod::ReplaceDocuments,
|
||||
..Default::default()
|
||||
};
|
||||
let mut wtxn = index.write_txn().unwrap();
|
||||
|
||||
let documents = documents!([
|
||||
{ "id": 0, "_geo": { "lng": 42 } }
|
||||
]);
|
||||
let mut builder =
|
||||
IndexDocuments::new(&mut wtxn, &index, &config, indexing_config.clone(), |_| ())
|
||||
.unwrap();
|
||||
builder.add_documents(documents).unwrap();
|
||||
let error = builder.execute().unwrap_err();
|
||||
assert_eq!(
|
||||
&error.to_string(),
|
||||
r#"Could not find latitude in the document with the id: `0`. Was expecting a `_geo.lat` field."#
|
||||
);
|
||||
|
||||
let documents = documents!([
|
||||
{ "id": 0, "_geo": { "lat": 42 } }
|
||||
]);
|
||||
let mut builder =
|
||||
IndexDocuments::new(&mut wtxn, &index, &config, indexing_config.clone(), |_| ())
|
||||
.unwrap();
|
||||
builder.add_documents(documents).unwrap();
|
||||
let error = builder.execute().unwrap_err();
|
||||
assert_eq!(
|
||||
&error.to_string(),
|
||||
r#"Could not find longitude in the document with the id: `0`. Was expecting a `_geo.lng` field."#
|
||||
);
|
||||
|
||||
let documents = documents!([
|
||||
{ "id": 0, "_geo": { "lat": "lol", "lng": 42 } }
|
||||
]);
|
||||
let mut builder =
|
||||
IndexDocuments::new(&mut wtxn, &index, &config, indexing_config.clone(), |_| ())
|
||||
.unwrap();
|
||||
builder.add_documents(documents).unwrap();
|
||||
let error = builder.execute().unwrap_err();
|
||||
assert_eq!(
|
||||
&error.to_string(),
|
||||
r#"Could not parse latitude in the document with the id: `0`. Was expecting a number but instead got `"lol"`."#
|
||||
);
|
||||
|
||||
let documents = documents!([
|
||||
{ "id": 0, "_geo": { "lat": [12, 13], "lng": 42 } }
|
||||
]);
|
||||
let mut builder =
|
||||
IndexDocuments::new(&mut wtxn, &index, &config, indexing_config.clone(), |_| ())
|
||||
.unwrap();
|
||||
builder.add_documents(documents).unwrap();
|
||||
let error = builder.execute().unwrap_err();
|
||||
assert_eq!(
|
||||
&error.to_string(),
|
||||
r#"Could not parse latitude in the document with the id: `0`. Was expecting a number but instead got `[12,13]`."#
|
||||
);
|
||||
|
||||
let documents = documents!([
|
||||
{ "id": 0, "_geo": { "lat": 12, "lng": "hello" } }
|
||||
]);
|
||||
let mut builder =
|
||||
IndexDocuments::new(&mut wtxn, &index, &config, indexing_config.clone(), |_| ())
|
||||
.unwrap();
|
||||
builder.add_documents(documents).unwrap();
|
||||
let error = builder.execute().unwrap_err();
|
||||
assert_eq!(
|
||||
&error.to_string(),
|
||||
r#"Could not parse longitude in the document with the id: `0`. Was expecting a number but instead got `"hello"`."#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_documents_then_insert() {
|
||||
let path = tempfile::tempdir().unwrap();
|
||||
|
Reference in New Issue
Block a user