mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-12-08 13:45:42 +00:00
Compare commits
6 Commits
v1.5.0-rc.
...
simplify-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a34f70566 | ||
|
|
75d8d4f3a8 | ||
|
|
62ea81bef6 | ||
|
|
f28f09ae2f | ||
|
|
62cc97ba70 | ||
|
|
fed59cc1d5 |
2
.github/workflows/test-suite.yml
vendored
2
.github/workflows/test-suite.yml
vendored
@@ -183,7 +183,7 @@ jobs:
|
|||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
toolchain: nightly
|
toolchain: 1.71.1
|
||||||
override: true
|
override: true
|
||||||
components: rustfmt
|
components: rustfmt
|
||||||
- name: Cache dependencies
|
- name: Cache dependencies
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
unstable_features = true
|
|
||||||
|
|
||||||
use_small_heuristics = "max"
|
use_small_heuristics = "max"
|
||||||
imports_granularity = "Module"
|
imports_granularity = "Module"
|
||||||
group_imports = "StdExternalCrate"
|
group_imports = "StdExternalCrate"
|
||||||
|
|||||||
28
Cargo.lock
generated
28
Cargo.lock
generated
@@ -468,7 +468,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "benchmarks"
|
name = "benchmarks"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -1206,7 +1206,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dump"
|
name = "dump"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"big_s",
|
"big_s",
|
||||||
@@ -1417,7 +1417,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "file-store"
|
name = "file-store"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"faux",
|
"faux",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
@@ -1439,7 +1439,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "filter-parser"
|
name = "filter-parser"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"insta",
|
"insta",
|
||||||
"nom",
|
"nom",
|
||||||
@@ -1459,7 +1459,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flatten-serde-json"
|
name = "flatten-serde-json"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"criterion",
|
"criterion",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -1577,7 +1577,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fuzzers"
|
name = "fuzzers"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arbitrary",
|
"arbitrary",
|
||||||
"clap",
|
"clap",
|
||||||
@@ -1891,7 +1891,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "index-scheduler"
|
name = "index-scheduler"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"big_s",
|
"big_s",
|
||||||
@@ -2088,7 +2088,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "json-depth-checker"
|
name = "json-depth-checker"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"criterion",
|
"criterion",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -2500,7 +2500,7 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "meili-snap"
|
name = "meili-snap"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"insta",
|
"insta",
|
||||||
"md5",
|
"md5",
|
||||||
@@ -2509,7 +2509,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "meilisearch"
|
name = "meilisearch"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-cors",
|
"actix-cors",
|
||||||
"actix-http",
|
"actix-http",
|
||||||
@@ -2599,7 +2599,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "meilisearch-auth"
|
name = "meilisearch-auth"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.21.2",
|
"base64 0.21.2",
|
||||||
"enum-iterator",
|
"enum-iterator",
|
||||||
@@ -2618,7 +2618,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "meilisearch-types"
|
name = "meilisearch-types"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
@@ -2672,7 +2672,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "milli"
|
name = "milli"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"big_s",
|
"big_s",
|
||||||
"bimap",
|
"bimap",
|
||||||
@@ -2994,7 +2994,7 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "permissive-json-pointer"
|
name = "permissive-json-pointer"
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"big_s",
|
"big_s",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "1.4.2"
|
version = "1.4.1"
|
||||||
authors = ["Quentin de Quelen <quentin@dequelen.me>", "Clément Renault <clement@meilisearch.com>"]
|
authors = ["Quentin de Quelen <quentin@dequelen.me>", "Clément Renault <clement@meilisearch.com>"]
|
||||||
description = "Meilisearch HTTP server"
|
description = "Meilisearch HTTP server"
|
||||||
homepage = "https://meilisearch.com"
|
homepage = "https://meilisearch.com"
|
||||||
|
|||||||
@@ -526,12 +526,12 @@ pub(crate) mod test {
|
|||||||
assert!(indexes.is_empty());
|
assert!(indexes.is_empty());
|
||||||
|
|
||||||
// products
|
// products
|
||||||
insta::assert_json_snapshot!(products.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(products.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "products",
|
"uid": "products",
|
||||||
"primaryKey": "sku",
|
"primaryKey": "sku",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2022-10-09T20:27:22.688964637Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2022-10-09T20:27:23.951017769Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -541,12 +541,12 @@ pub(crate) mod test {
|
|||||||
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"548284a84de510f71e88e6cdea495cf5");
|
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"548284a84de510f71e88e6cdea495cf5");
|
||||||
|
|
||||||
// movies
|
// movies
|
||||||
insta::assert_json_snapshot!(movies.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(movies.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "movies",
|
"uid": "movies",
|
||||||
"primaryKey": "id",
|
"primaryKey": "id",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2022-10-09T20:27:22.197788495Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2022-10-09T20:28:01.93111053Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -571,12 +571,12 @@ pub(crate) mod test {
|
|||||||
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"d751713988987e9331980363e24189ce");
|
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"d751713988987e9331980363e24189ce");
|
||||||
|
|
||||||
// spells
|
// spells
|
||||||
insta::assert_json_snapshot!(spells.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(spells.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "dnd_spells",
|
"uid": "dnd_spells",
|
||||||
"primaryKey": "index",
|
"primaryKey": "index",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2022-10-09T20:27:24.242683494Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2022-10-09T20:27:24.312809641Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -617,12 +617,12 @@ pub(crate) mod test {
|
|||||||
assert!(indexes.is_empty());
|
assert!(indexes.is_empty());
|
||||||
|
|
||||||
// products
|
// products
|
||||||
insta::assert_json_snapshot!(products.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(products.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "products",
|
"uid": "products",
|
||||||
"primaryKey": "sku",
|
"primaryKey": "sku",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2023-01-30T16:25:56.595257Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2023-01-30T16:25:58.70348Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -632,12 +632,12 @@ pub(crate) mod test {
|
|||||||
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"548284a84de510f71e88e6cdea495cf5");
|
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"548284a84de510f71e88e6cdea495cf5");
|
||||||
|
|
||||||
// movies
|
// movies
|
||||||
insta::assert_json_snapshot!(movies.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(movies.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "movies",
|
"uid": "movies",
|
||||||
"primaryKey": "id",
|
"primaryKey": "id",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2023-01-30T16:25:56.192178Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2023-01-30T16:25:56.455714Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -647,12 +647,12 @@ pub(crate) mod test {
|
|||||||
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"0227598af846e574139ee0b80e03a720");
|
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"0227598af846e574139ee0b80e03a720");
|
||||||
|
|
||||||
// spells
|
// spells
|
||||||
insta::assert_json_snapshot!(spells.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(spells.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "dnd_spells",
|
"uid": "dnd_spells",
|
||||||
"primaryKey": "index",
|
"primaryKey": "index",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2023-01-30T16:25:58.876405Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2023-01-30T16:25:59.079906Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ pub type Checked = settings::Checked;
|
|||||||
pub type Unchecked = settings::Unchecked;
|
pub type Unchecked = settings::Unchecked;
|
||||||
|
|
||||||
pub type Task = updates::UpdateEntry;
|
pub type Task = updates::UpdateEntry;
|
||||||
|
pub type Kind = updates::UpdateMeta;
|
||||||
|
|
||||||
// everything related to the errors
|
// everything related to the errors
|
||||||
pub type ResponseError = errors::ResponseError;
|
pub type ResponseError = errors::ResponseError;
|
||||||
@@ -107,8 +108,11 @@ impl V2Reader {
|
|||||||
pub fn indexes(&self) -> Result<impl Iterator<Item = Result<V2IndexReader>> + '_> {
|
pub fn indexes(&self) -> Result<impl Iterator<Item = Result<V2IndexReader>> + '_> {
|
||||||
Ok(self.index_uuid.iter().map(|index| -> Result<_> {
|
Ok(self.index_uuid.iter().map(|index| -> Result<_> {
|
||||||
V2IndexReader::new(
|
V2IndexReader::new(
|
||||||
index.uid.clone(),
|
|
||||||
&self.dump.path().join("indexes").join(format!("index-{}", index.uuid)),
|
&self.dump.path().join("indexes").join(format!("index-{}", index.uuid)),
|
||||||
|
index,
|
||||||
|
BufReader::new(
|
||||||
|
File::open(self.dump.path().join("updates").join("data.jsonl")).unwrap(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -143,16 +147,41 @@ pub struct V2IndexReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl V2IndexReader {
|
impl V2IndexReader {
|
||||||
pub fn new(name: String, path: &Path) -> Result<Self> {
|
pub fn new(path: &Path, index_uuid: &IndexUuid, tasks: BufReader<File>) -> Result<Self> {
|
||||||
let meta = File::open(path.join("meta.json"))?;
|
let meta = File::open(path.join("meta.json"))?;
|
||||||
let meta: DumpMeta = serde_json::from_reader(meta)?;
|
let meta: DumpMeta = serde_json::from_reader(meta)?;
|
||||||
|
|
||||||
|
let mut created_at = None;
|
||||||
|
let mut updated_at = None;
|
||||||
|
|
||||||
|
for line in tasks.lines() {
|
||||||
|
let task: Task = serde_json::from_str(&line?)?;
|
||||||
|
if !(task.uuid == index_uuid.uuid && task.is_finished()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let new_created_at = match task.update.meta() {
|
||||||
|
Kind::DocumentsAddition { .. } | Kind::Settings(_) => task.update.finished_at(),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
let new_updated_at = task.update.finished_at();
|
||||||
|
|
||||||
|
if created_at.is_none() || created_at > new_created_at {
|
||||||
|
created_at = new_created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
if updated_at.is_none() || updated_at < new_updated_at {
|
||||||
|
updated_at = new_updated_at;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let current_time = OffsetDateTime::now_utc();
|
||||||
|
|
||||||
let metadata = IndexMetadata {
|
let metadata = IndexMetadata {
|
||||||
uid: name,
|
uid: index_uuid.uid.clone(),
|
||||||
primary_key: meta.primary_key,
|
primary_key: meta.primary_key,
|
||||||
// FIXME: Iterate over the whole task queue to find the creation and last update date.
|
created_at: created_at.unwrap_or(current_time),
|
||||||
created_at: OffsetDateTime::now_utc(),
|
updated_at: updated_at.unwrap_or(current_time),
|
||||||
updated_at: OffsetDateTime::now_utc(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret = V2IndexReader {
|
let ret = V2IndexReader {
|
||||||
@@ -248,12 +277,12 @@ pub(crate) mod test {
|
|||||||
assert!(indexes.is_empty());
|
assert!(indexes.is_empty());
|
||||||
|
|
||||||
// products
|
// products
|
||||||
insta::assert_json_snapshot!(products.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(products.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "products",
|
"uid": "products",
|
||||||
"primaryKey": "sku",
|
"primaryKey": "sku",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2022-10-09T20:27:22.688964637Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2022-10-09T20:27:23.951017769Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -263,12 +292,12 @@ pub(crate) mod test {
|
|||||||
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"548284a84de510f71e88e6cdea495cf5");
|
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"548284a84de510f71e88e6cdea495cf5");
|
||||||
|
|
||||||
// movies
|
// movies
|
||||||
insta::assert_json_snapshot!(movies.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(movies.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "movies",
|
"uid": "movies",
|
||||||
"primaryKey": "id",
|
"primaryKey": "id",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2022-10-09T20:27:22.197788495Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2022-10-09T20:28:01.93111053Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -293,12 +322,12 @@ pub(crate) mod test {
|
|||||||
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"d751713988987e9331980363e24189ce");
|
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"d751713988987e9331980363e24189ce");
|
||||||
|
|
||||||
// spells
|
// spells
|
||||||
insta::assert_json_snapshot!(spells.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(spells.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "dnd_spells",
|
"uid": "dnd_spells",
|
||||||
"primaryKey": "index",
|
"primaryKey": "index",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2022-10-09T20:27:24.242683494Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2022-10-09T20:27:24.312809641Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -340,12 +369,12 @@ pub(crate) mod test {
|
|||||||
assert!(indexes.is_empty());
|
assert!(indexes.is_empty());
|
||||||
|
|
||||||
// products
|
// products
|
||||||
insta::assert_json_snapshot!(products.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(products.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "products",
|
"uid": "products",
|
||||||
"primaryKey": "sku",
|
"primaryKey": "sku",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2023-01-30T16:25:56.595257Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2023-01-30T16:25:58.70348Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -355,12 +384,12 @@ pub(crate) mod test {
|
|||||||
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"548284a84de510f71e88e6cdea495cf5");
|
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"548284a84de510f71e88e6cdea495cf5");
|
||||||
|
|
||||||
// movies
|
// movies
|
||||||
insta::assert_json_snapshot!(movies.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(movies.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "movies",
|
"uid": "movies",
|
||||||
"primaryKey": "id",
|
"primaryKey": "id",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2023-01-30T16:25:56.192178Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2023-01-30T16:25:56.455714Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
@@ -370,12 +399,12 @@ pub(crate) mod test {
|
|||||||
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"0227598af846e574139ee0b80e03a720");
|
meili_snap::snapshot_hash!(format!("{:#?}", documents), @"0227598af846e574139ee0b80e03a720");
|
||||||
|
|
||||||
// spells
|
// spells
|
||||||
insta::assert_json_snapshot!(spells.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
|
insta::assert_json_snapshot!(spells.metadata(), @r###"
|
||||||
{
|
{
|
||||||
"uid": "dnd_spells",
|
"uid": "dnd_spells",
|
||||||
"primaryKey": "index",
|
"primaryKey": "index",
|
||||||
"createdAt": "[now]",
|
"createdAt": "2023-01-30T16:25:58.876405Z",
|
||||||
"updatedAt": "[now]"
|
"updatedAt": "2023-01-30T16:25:59.079906Z"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
|
|||||||
@@ -227,4 +227,14 @@ impl UpdateStatus {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn finished_at(&self) -> Option<OffsetDateTime> {
|
||||||
|
match self {
|
||||||
|
UpdateStatus::Processing(_) => None,
|
||||||
|
UpdateStatus::Enqueued(_) => None,
|
||||||
|
UpdateStatus::Processed(u) => Some(u.processed_at),
|
||||||
|
UpdateStatus::Aborted(_) => None,
|
||||||
|
UpdateStatus::Failed(u) => Some(u.failed_at),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,109 +6,21 @@ use crate::json;
|
|||||||
|
|
||||||
pub(self) static DOCUMENTS: Lazy<Value> = Lazy::new(|| {
|
pub(self) static DOCUMENTS: Lazy<Value> = Lazy::new(|| {
|
||||||
json!([
|
json!([
|
||||||
{
|
{"productId": 1, "shopId": 1},
|
||||||
"id": 1,
|
{"productId": 2, "shopId": 1},
|
||||||
"description": "Leather Jacket",
|
{"productId": 3, "shopId": 2},
|
||||||
"brand": "Lee Jeans",
|
{"productId": 4, "shopId": 2},
|
||||||
"product_id": "123456",
|
{"productId": 5, "shopId": 3},
|
||||||
"color": "Brown"
|
{"productId": 6, "shopId": 3},
|
||||||
},
|
{"productId": 7, "shopId": 4},
|
||||||
{
|
{"productId": 8, "shopId": 4},
|
||||||
"id": 2,
|
{"productId": 9, "shopId": 5},
|
||||||
"description": "Leather Jacket",
|
{"productId": 10, "shopId": 5}
|
||||||
"brand": "Lee Jeans",
|
|
||||||
"product_id": "123456",
|
|
||||||
"color": "Black"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"description": "Leather Jacket",
|
|
||||||
"brand": "Lee Jeans",
|
|
||||||
"product_id": "123456",
|
|
||||||
"color": "Blue"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 4,
|
|
||||||
"description": "T-Shirt",
|
|
||||||
"brand": "Nike",
|
|
||||||
"product_id": "789012",
|
|
||||||
"color": "Red"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 5,
|
|
||||||
"description": "T-Shirt",
|
|
||||||
"brand": "Nike",
|
|
||||||
"product_id": "789012",
|
|
||||||
"color": "Blue"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 6,
|
|
||||||
"description": "Running Shoes",
|
|
||||||
"brand": "Adidas",
|
|
||||||
"product_id": "456789",
|
|
||||||
"color": "Black"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 7,
|
|
||||||
"description": "Running Shoes",
|
|
||||||
"brand": "Adidas",
|
|
||||||
"product_id": "456789",
|
|
||||||
"color": "White"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 8,
|
|
||||||
"description": "Hoodie",
|
|
||||||
"brand": "Puma",
|
|
||||||
"product_id": "987654",
|
|
||||||
"color": "Gray"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 9,
|
|
||||||
"description": "Sweater",
|
|
||||||
"brand": "Gap",
|
|
||||||
"product_id": "234567",
|
|
||||||
"color": "Green"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 10,
|
|
||||||
"description": "Sweater",
|
|
||||||
"brand": "Gap",
|
|
||||||
"product_id": "234567",
|
|
||||||
"color": "Red"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 11,
|
|
||||||
"description": "Sweater",
|
|
||||||
"brand": "Gap",
|
|
||||||
"product_id": "234567",
|
|
||||||
"color": "Blue"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 12,
|
|
||||||
"description": "Jeans",
|
|
||||||
"brand": "Levi's",
|
|
||||||
"product_id": "345678",
|
|
||||||
"color": "Indigo"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 13,
|
|
||||||
"description": "Jeans",
|
|
||||||
"brand": "Levi's",
|
|
||||||
"product_id": "345678",
|
|
||||||
"color": "Black"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 14,
|
|
||||||
"description": "Jeans",
|
|
||||||
"brand": "Levi's",
|
|
||||||
"product_id": "345678",
|
|
||||||
"color": "Stone Wash"
|
|
||||||
}
|
|
||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
||||||
pub(self) static DOCUMENT_PRIMARY_KEY: &str = "id";
|
pub(self) static DOCUMENT_PRIMARY_KEY: &str = "productId";
|
||||||
pub(self) static DOCUMENT_DISTINCT_KEY: &str = "product_id";
|
pub(self) static DOCUMENT_DISTINCT_KEY: &str = "shopId";
|
||||||
|
|
||||||
/// testing: https://github.com/meilisearch/meilisearch/issues/4078
|
/// testing: https://github.com/meilisearch/meilisearch/issues/4078
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
@@ -121,121 +33,31 @@ async fn distinct_search_with_offset_no_ranking() {
|
|||||||
index.update_distinct_attribute(json!(DOCUMENT_DISTINCT_KEY)).await;
|
index.update_distinct_attribute(json!(DOCUMENT_DISTINCT_KEY)).await;
|
||||||
index.wait_task(1).await;
|
index.wait_task(1).await;
|
||||||
|
|
||||||
fn get_hits(response: &Value) -> Vec<&str> {
|
fn get_hits(Value(response): Value) -> Vec<i64> {
|
||||||
let hits_array = response["hits"].as_array().unwrap();
|
let hits_array = response["hits"].as_array().unwrap();
|
||||||
hits_array.iter().map(|h| h[DOCUMENT_DISTINCT_KEY].as_str().unwrap()).collect::<Vec<_>>()
|
hits_array.iter().map(|h| h[DOCUMENT_DISTINCT_KEY].as_i64().unwrap()).collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"offset": 0, "limit": 2})).await;
|
let (response, code) = index.search_post(json!({"limit": 2, "offset": 0})).await;
|
||||||
let hits = get_hits(&response);
|
let hits = get_hits(response);
|
||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
snapshot!(hits.len(), @"2");
|
snapshot!(hits.len(), @"2");
|
||||||
snapshot!(format!("{:?}", hits), @r#"["123456", "789012"]"#);
|
snapshot!(format!("{:?}", hits), @"[1, 2]");
|
||||||
snapshot!(response["estimatedTotalHits"] , @"11");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"offset": 2, "limit": 2})).await;
|
let (response, code) = index.search_post(json!({"limit": 2, "offset": 2})).await;
|
||||||
let hits = get_hits(&response);
|
let hits = get_hits(response);
|
||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
snapshot!(hits.len(), @"2");
|
snapshot!(hits.len(), @"2");
|
||||||
snapshot!(format!("{:?}", hits), @r#"["456789", "987654"]"#);
|
snapshot!(format!("{:?}", hits), @"[3, 4]");
|
||||||
snapshot!(response["estimatedTotalHits"], @"10");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"offset": 4, "limit": 2})).await;
|
let (response, code) = index.search_post(json!({"limit": 10, "offset": 4})).await;
|
||||||
let hits = get_hits(&response);
|
let hits = get_hits(response);
|
||||||
snapshot!(code, @"200 OK");
|
|
||||||
snapshot!(hits.len(), @"2");
|
|
||||||
snapshot!(format!("{:?}", hits), @r#"["234567", "345678"]"#);
|
|
||||||
snapshot!(response["estimatedTotalHits"], @"6");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"offset": 5, "limit": 2})).await;
|
|
||||||
let hits = get_hits(&response);
|
|
||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
snapshot!(hits.len(), @"1");
|
snapshot!(hits.len(), @"1");
|
||||||
snapshot!(format!("{:?}", hits), @r#"["345678"]"#);
|
snapshot!(format!("{:?}", hits), @"[5]");
|
||||||
snapshot!(response["estimatedTotalHits"], @"6");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"offset": 6, "limit": 2})).await;
|
let (response, code) = index.search_post(json!({"limit": 10, "offset": 5})).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(), @"0");
|
||||||
snapshot!(format!("{:?}", hits), @r#"[]"#);
|
|
||||||
snapshot!(response["estimatedTotalHits"], @"6");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"offset": 7, "limit": 2})).await;
|
|
||||||
let hits = get_hits(&response);
|
|
||||||
snapshot!(code, @"200 OK");
|
|
||||||
snapshot!(hits.len(), @"0");
|
|
||||||
snapshot!(format!("{:?}", hits), @r#"[]"#);
|
|
||||||
snapshot!(response["estimatedTotalHits"], @"6");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// testing: https://github.com/meilisearch/meilisearch/issues/4130
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn distinct_search_with_pagination_no_ranking() {
|
|
||||||
let server = Server::new().await;
|
|
||||||
let index = server.index("test");
|
|
||||||
|
|
||||||
let documents = DOCUMENTS.clone();
|
|
||||||
index.add_documents(documents, Some(DOCUMENT_PRIMARY_KEY)).await;
|
|
||||||
index.update_distinct_attribute(json!(DOCUMENT_DISTINCT_KEY)).await;
|
|
||||||
index.wait_task(1).await;
|
|
||||||
|
|
||||||
fn get_hits(response: &Value) -> Vec<&str> {
|
|
||||||
let hits_array = response["hits"].as_array().unwrap();
|
|
||||||
hits_array.iter().map(|h| h[DOCUMENT_DISTINCT_KEY].as_str().unwrap()).collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"page": 0, "hitsPerPage": 2})).await;
|
|
||||||
let hits = get_hits(&response);
|
|
||||||
snapshot!(code, @"200 OK");
|
|
||||||
snapshot!(hits.len(), @"0");
|
|
||||||
snapshot!(format!("{:?}", hits), @r#"[]"#);
|
|
||||||
snapshot!(response["page"], @"0");
|
|
||||||
snapshot!(response["totalPages"], @"3");
|
|
||||||
snapshot!(response["totalHits"], @"6");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"page": 1, "hitsPerPage": 2})).await;
|
|
||||||
let hits = get_hits(&response);
|
|
||||||
snapshot!(code, @"200 OK");
|
|
||||||
snapshot!(hits.len(), @"2");
|
|
||||||
snapshot!(format!("{:?}", hits), @r#"["123456", "789012"]"#);
|
|
||||||
snapshot!(response["page"], @"1");
|
|
||||||
snapshot!(response["totalPages"], @"3");
|
|
||||||
snapshot!(response["totalHits"], @"6");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"page": 2, "hitsPerPage": 2})).await;
|
|
||||||
let hits = get_hits(&response);
|
|
||||||
snapshot!(code, @"200 OK");
|
|
||||||
snapshot!(hits.len(), @"2");
|
|
||||||
snapshot!(format!("{:?}", hits), @r#"["456789", "987654"]"#);
|
|
||||||
snapshot!(response["page"], @"2");
|
|
||||||
snapshot!(response["totalPages"], @"3");
|
|
||||||
snapshot!(response["totalHits"], @"6");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"page": 3, "hitsPerPage": 2})).await;
|
|
||||||
let hits = get_hits(&response);
|
|
||||||
snapshot!(code, @"200 OK");
|
|
||||||
snapshot!(hits.len(), @"2");
|
|
||||||
snapshot!(format!("{:?}", hits), @r#"["234567", "345678"]"#);
|
|
||||||
snapshot!(response["page"], @"3");
|
|
||||||
snapshot!(response["totalPages"], @"3");
|
|
||||||
snapshot!(response["totalHits"], @"6");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"page": 4, "hitsPerPage": 2})).await;
|
|
||||||
let hits = get_hits(&response);
|
|
||||||
snapshot!(code, @"200 OK");
|
|
||||||
snapshot!(hits.len(), @"0");
|
|
||||||
snapshot!(format!("{:?}", hits), @r#"[]"#);
|
|
||||||
snapshot!(response["page"], @"4");
|
|
||||||
snapshot!(response["totalPages"], @"3");
|
|
||||||
snapshot!(response["totalHits"], @"6");
|
|
||||||
|
|
||||||
let (response, code) = index.search_post(json!({"page": 2, "hitsPerPage": 3})).await;
|
|
||||||
let hits = get_hits(&response);
|
|
||||||
snapshot!(code, @"200 OK");
|
|
||||||
snapshot!(hits.len(), @"3");
|
|
||||||
snapshot!(format!("{:?}", hits), @r#"["987654", "234567", "345678"]"#);
|
|
||||||
snapshot!(response["page"], @"2");
|
|
||||||
snapshot!(response["totalPages"], @"2");
|
|
||||||
snapshot!(response["totalHits"], @"6");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,9 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>(
|
|||||||
if let Some(distinct_fid) = distinct_fid {
|
if let Some(distinct_fid) = distinct_fid {
|
||||||
let mut excluded = RoaringBitmap::new();
|
let mut excluded = RoaringBitmap::new();
|
||||||
let mut results = vec![];
|
let mut results = vec![];
|
||||||
|
let mut skip = 0;
|
||||||
for docid in universe.iter() {
|
for docid in universe.iter() {
|
||||||
if results.len() >= from + length {
|
if results.len() >= length {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if excluded.contains(docid) {
|
if excluded.contains(docid) {
|
||||||
@@ -55,19 +56,16 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
distinct_single_docid(ctx.index, ctx.txn, distinct_fid, docid, &mut excluded)?;
|
distinct_single_docid(ctx.index, ctx.txn, distinct_fid, docid, &mut excluded)?;
|
||||||
|
skip += 1;
|
||||||
|
if skip <= from {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
results.push(docid);
|
results.push(docid);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut all_candidates = universe - excluded;
|
let mut all_candidates = universe - excluded;
|
||||||
all_candidates.extend(results.iter().copied());
|
all_candidates.extend(results.iter().copied());
|
||||||
// drain the results of the skipped elements
|
|
||||||
// this **must** be done **after** writing the entire results in `all_candidates` to ensure
|
|
||||||
// e.g. estimatedTotalHits is correct.
|
|
||||||
if results.len() >= from {
|
|
||||||
results.drain(..from);
|
|
||||||
} else {
|
|
||||||
results.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(BucketSortOutput {
|
return Ok(BucketSortOutput {
|
||||||
scores: vec![Default::default(); results.len()],
|
scores: vec![Default::default(); results.len()],
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ test_distinct!(
|
|||||||
EXTERNAL_DOCUMENTS_IDS.len(),
|
EXTERNAL_DOCUMENTS_IDS.len(),
|
||||||
1,
|
1,
|
||||||
vec![],
|
vec![],
|
||||||
3
|
2
|
||||||
);
|
);
|
||||||
test_distinct!(
|
test_distinct!(
|
||||||
// testing: https://github.com/meilisearch/meilisearch/issues/4078
|
// testing: https://github.com/meilisearch/meilisearch/issues/4078
|
||||||
@@ -212,7 +212,7 @@ test_distinct!(
|
|||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
vec![],
|
vec![],
|
||||||
3
|
1
|
||||||
);
|
);
|
||||||
test_distinct!(
|
test_distinct!(
|
||||||
// testing: https://github.com/meilisearch/meilisearch/issues/4078
|
// testing: https://github.com/meilisearch/meilisearch/issues/4078
|
||||||
@@ -222,7 +222,7 @@ test_distinct!(
|
|||||||
EXTERNAL_DOCUMENTS_IDS.len(),
|
EXTERNAL_DOCUMENTS_IDS.len(),
|
||||||
2,
|
2,
|
||||||
vec![],
|
vec![],
|
||||||
7
|
5
|
||||||
);
|
);
|
||||||
test_distinct!(
|
test_distinct!(
|
||||||
// testing: https://github.com/meilisearch/meilisearch/issues/4078
|
// testing: https://github.com/meilisearch/meilisearch/issues/4078
|
||||||
@@ -232,5 +232,5 @@ test_distinct!(
|
|||||||
2,
|
2,
|
||||||
4,
|
4,
|
||||||
vec![],
|
vec![],
|
||||||
7
|
3
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user