mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-06-09 05:35:41 +00:00
Merge pull request #5623 from martin-g/faster-search-geo-it-tests
tests: Faster search::geo IT tests
This commit is contained in:
commit
e416bbc1de
@ -453,3 +453,57 @@ pub async fn shared_index_with_test_set() -> &'static Index<'static, Shared> {
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub static GEO_DOCUMENTS: Lazy<Value> = Lazy::new(|| {
|
||||||
|
json!([
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Taco Truck",
|
||||||
|
"address": "444 Salsa Street, Burritoville",
|
||||||
|
"type": "Mexican",
|
||||||
|
"rating": 9,
|
||||||
|
"_geo": {
|
||||||
|
"lat": 34.0522,
|
||||||
|
"lng": -118.2437
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "La Bella Italia",
|
||||||
|
"address": "456 Elm Street, Townsville",
|
||||||
|
"type": "Italian",
|
||||||
|
"rating": 9,
|
||||||
|
"_geo": {
|
||||||
|
"lat": "45.4777599",
|
||||||
|
"lng": "9.1967508"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "Crêpe Truck",
|
||||||
|
"address": "2 Billig Avenue, Rouenville",
|
||||||
|
"type": "French",
|
||||||
|
"rating": 10
|
||||||
|
}
|
||||||
|
])
|
||||||
|
});
|
||||||
|
|
||||||
|
pub async fn shared_index_with_geo_documents() -> &'static Index<'static, Shared> {
|
||||||
|
static INDEX: OnceCell<Index<'static, Shared>> = OnceCell::const_new();
|
||||||
|
INDEX
|
||||||
|
.get_or_init(|| async {
|
||||||
|
let server = Server::new_shared();
|
||||||
|
let index = server._index("SHARED_GEO_DOCUMENTS").to_shared();
|
||||||
|
let (response, _code) = index._add_documents(GEO_DOCUMENTS.clone(), None).await;
|
||||||
|
index.wait_task(response.uid()).await.succeeded();
|
||||||
|
|
||||||
|
let (response, _code) = index
|
||||||
|
._update_settings(
|
||||||
|
json!({"filterableAttributes": ["_geo"], "sortableAttributes": ["_geo"]}),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
index.wait_task(response.uid()).await.succeeded();
|
||||||
|
index
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
@ -1,56 +1,14 @@
|
|||||||
use meili_snap::{json_string, snapshot};
|
use meili_snap::{json_string, snapshot};
|
||||||
use meilisearch_types::milli::constants::RESERVED_GEO_FIELD_NAME;
|
use meilisearch_types::milli::constants::RESERVED_GEO_FIELD_NAME;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
use crate::common::{Server, Value};
|
use crate::common::shared_index_with_geo_documents;
|
||||||
use crate::json;
|
use crate::json;
|
||||||
|
|
||||||
use super::test_settings_documents_indexing_swapping_and_search;
|
use super::test_settings_documents_indexing_swapping_and_search;
|
||||||
|
|
||||||
static DOCUMENTS: Lazy<Value> = Lazy::new(|| {
|
|
||||||
json!([
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"name": "Taco Truck",
|
|
||||||
"address": "444 Salsa Street, Burritoville",
|
|
||||||
"type": "Mexican",
|
|
||||||
"rating": 9,
|
|
||||||
"_geo": {
|
|
||||||
"lat": 34.0522,
|
|
||||||
"lng": -118.2437
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"name": "La Bella Italia",
|
|
||||||
"address": "456 Elm Street, Townsville",
|
|
||||||
"type": "Italian",
|
|
||||||
"rating": 9,
|
|
||||||
"_geo": {
|
|
||||||
"lat": "45.4777599",
|
|
||||||
"lng": "9.1967508"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"name": "Crêpe Truck",
|
|
||||||
"address": "2 Billig Avenue, Rouenville",
|
|
||||||
"type": "French",
|
|
||||||
"rating": 10
|
|
||||||
}
|
|
||||||
])
|
|
||||||
});
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn geo_sort_with_geo_strings() {
|
async fn geo_sort_with_geo_strings() {
|
||||||
let server = Server::new().await;
|
let index = shared_index_with_geo_documents().await;
|
||||||
let index = server.index("test");
|
|
||||||
|
|
||||||
let documents = DOCUMENTS.clone();
|
|
||||||
index.update_settings_filterable_attributes(json!(["_geo"])).await;
|
|
||||||
index.update_settings_sortable_attributes(json!(["_geo"])).await;
|
|
||||||
let (task, _status_code) = index.add_documents(documents, None).await;
|
|
||||||
index.wait_task(task.uid()).await.succeeded();
|
|
||||||
|
|
||||||
index
|
index
|
||||||
.search(
|
.search(
|
||||||
@ -59,7 +17,7 @@ async fn geo_sort_with_geo_strings() {
|
|||||||
"sort": ["_geoPoint(0.0, 0.0):asc"]
|
"sort": ["_geoPoint(0.0, 0.0):asc"]
|
||||||
}),
|
}),
|
||||||
|response, code| {
|
|response, code| {
|
||||||
assert_eq!(code, 200, "{}", response);
|
assert_eq!(code, 200, "{response}");
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@ -67,14 +25,7 @@ async fn geo_sort_with_geo_strings() {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn geo_bounding_box_with_string_and_number() {
|
async fn geo_bounding_box_with_string_and_number() {
|
||||||
let server = Server::new().await;
|
let index = shared_index_with_geo_documents().await;
|
||||||
let index = server.index("test");
|
|
||||||
|
|
||||||
let documents = DOCUMENTS.clone();
|
|
||||||
index.update_settings_filterable_attributes(json!(["_geo"])).await;
|
|
||||||
index.update_settings_sortable_attributes(json!(["_geo"])).await;
|
|
||||||
let (ret, _code) = index.add_documents(documents, None).await;
|
|
||||||
index.wait_task(ret.uid()).await.succeeded();
|
|
||||||
|
|
||||||
index
|
index
|
||||||
.search(
|
.search(
|
||||||
@ -82,7 +33,7 @@ async fn geo_bounding_box_with_string_and_number() {
|
|||||||
"filter": "_geoBoundingBox([89, 179], [-89, -179])",
|
"filter": "_geoBoundingBox([89, 179], [-89, -179])",
|
||||||
}),
|
}),
|
||||||
|response, code| {
|
|response, code| {
|
||||||
assert_eq!(code, 200, "{}", response);
|
assert_eq!(code, 200, "{response}");
|
||||||
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
||||||
{
|
{
|
||||||
"hits": [
|
"hits": [
|
||||||
@ -124,14 +75,7 @@ async fn geo_bounding_box_with_string_and_number() {
|
|||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn bug_4640() {
|
async fn bug_4640() {
|
||||||
// https://github.com/meilisearch/meilisearch/issues/4640
|
// https://github.com/meilisearch/meilisearch/issues/4640
|
||||||
let server = Server::new().await;
|
let index = shared_index_with_geo_documents().await;
|
||||||
let index = server.index("test");
|
|
||||||
|
|
||||||
let documents = DOCUMENTS.clone();
|
|
||||||
index.add_documents(documents, None).await;
|
|
||||||
index.update_settings_filterable_attributes(json!(["_geo"])).await;
|
|
||||||
let (ret, _code) = index.update_settings_sortable_attributes(json!(["_geo"])).await;
|
|
||||||
index.wait_task(ret.uid()).await.succeeded();
|
|
||||||
|
|
||||||
// Sort the document with the second one first
|
// Sort the document with the second one first
|
||||||
index
|
index
|
||||||
@ -140,7 +84,7 @@ async fn bug_4640() {
|
|||||||
"sort": ["_geoPoint(45.4777599, 9.1967508):asc"],
|
"sort": ["_geoPoint(45.4777599, 9.1967508):asc"],
|
||||||
}),
|
}),
|
||||||
|response, code| {
|
|response, code| {
|
||||||
assert_eq!(code, 200, "{}", response);
|
assert_eq!(code, 200, "{response}");
|
||||||
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
||||||
{
|
{
|
||||||
"hits": [
|
"hits": [
|
||||||
@ -203,7 +147,7 @@ async fn geo_asc_with_words() {
|
|||||||
&json!({"searchableAttributes": ["id", "doggo"], "rankingRules": ["words", "geo:asc"]}),
|
&json!({"searchableAttributes": ["id", "doggo"], "rankingRules": ["words", "geo:asc"]}),
|
||||||
&json!({"q": "jean"}),
|
&json!({"q": "jean"}),
|
||||||
|response, code| {
|
|response, code| {
|
||||||
assert_eq!(code, 200, "{}", response);
|
assert_eq!(code, 200, "{response}");
|
||||||
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
||||||
{
|
{
|
||||||
"hits": [
|
"hits": [
|
||||||
@ -248,7 +192,7 @@ async fn geo_asc_with_words() {
|
|||||||
&json!({"searchableAttributes": ["id", "doggo"], "rankingRules": ["words", "geo:asc"]}),
|
&json!({"searchableAttributes": ["id", "doggo"], "rankingRules": ["words", "geo:asc"]}),
|
||||||
&json!({"q": "bob"}),
|
&json!({"q": "bob"}),
|
||||||
|response, code| {
|
|response, code| {
|
||||||
assert_eq!(code, 200, "{}", response);
|
assert_eq!(code, 200, "{response}");
|
||||||
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
||||||
{
|
{
|
||||||
"hits": [
|
"hits": [
|
||||||
@ -285,7 +229,7 @@ async fn geo_asc_with_words() {
|
|||||||
&json!({"searchableAttributes": ["id", "doggo"], "rankingRules": ["words", "geo:asc"]}),
|
&json!({"searchableAttributes": ["id", "doggo"], "rankingRules": ["words", "geo:asc"]}),
|
||||||
&json!({"q": "intel"}),
|
&json!({"q": "intel"}),
|
||||||
|response, code| {
|
|response, code| {
|
||||||
assert_eq!(code, 200, "{}", response);
|
assert_eq!(code, 200, "{response}");
|
||||||
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
||||||
{
|
{
|
||||||
"hits": [
|
"hits": [
|
||||||
@ -325,7 +269,7 @@ async fn geo_sort_with_words() {
|
|||||||
&json!({"searchableAttributes": ["id", "doggo"], "rankingRules": ["words", "sort"], "sortableAttributes": [RESERVED_GEO_FIELD_NAME]}),
|
&json!({"searchableAttributes": ["id", "doggo"], "rankingRules": ["words", "sort"], "sortableAttributes": [RESERVED_GEO_FIELD_NAME]}),
|
||||||
&json!({"q": "jean", "sort": ["_geoPoint(0.0, 0.0):asc"]}),
|
&json!({"q": "jean", "sort": ["_geoPoint(0.0, 0.0):asc"]}),
|
||||||
|response, code| {
|
|response, code| {
|
||||||
assert_eq!(code, 200, "{}", response);
|
assert_eq!(code, 200, "{response}");
|
||||||
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###"
|
||||||
{
|
{
|
||||||
"hits": [
|
"hits": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user