mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-12-13 16:07:00 +00:00
Compare commits
8 Commits
proper-def
...
yoeight/sk
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
328718ee90 | ||
|
|
a2878efafe | ||
|
|
f392e0a0f8 | ||
|
|
e359325dbd | ||
|
|
d5f66c195d | ||
|
|
9f64b0de66 | ||
|
|
26e368b116 | ||
|
|
ba95ac0915 |
12
.github/workflows/sdks-tests.yml
vendored
12
.github/workflows/sdks-tests.yml
vendored
@@ -25,14 +25,18 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
- name: Define the Docker image we need to use
|
||||
id: define-image
|
||||
env:
|
||||
EVENT_NAME: ${{ github.event_name }}
|
||||
DOCKER_IMAGE_INPUT: ${{ github.event.inputs.docker_image }}
|
||||
run: |
|
||||
event=${{ github.event_name }}
|
||||
echo "docker-image=nightly" >> $GITHUB_OUTPUT
|
||||
if [[ $event == 'workflow_dispatch' ]]; then
|
||||
echo "docker-image=${{ github.event.inputs.docker_image }}" >> $GITHUB_OUTPUT
|
||||
if [[ "$EVENT_NAME" == 'workflow_dispatch' ]]; then
|
||||
echo "docker-image=$DOCKER_IMAGE_INPUT" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- name: Docker image is ${{ steps.define-image.outputs.docker-image }}
|
||||
run: echo "Docker image is ${{ steps.define-image.outputs.docker-image }}"
|
||||
env:
|
||||
DOCKER_IMAGE: ${{ steps.define-image.outputs.docker-image }}
|
||||
run: echo "Docker image is $DOCKER_IMAGE"
|
||||
|
||||
##########
|
||||
## SDKs ##
|
||||
|
||||
@@ -113,9 +113,9 @@ fn main() {
|
||||
|
||||
for op in &operations {
|
||||
match op {
|
||||
Either::Left(documents) => {
|
||||
indexer.replace_documents(documents).unwrap()
|
||||
}
|
||||
Either::Left(documents) => indexer
|
||||
.replace_documents(documents, Default::default())
|
||||
.unwrap(),
|
||||
Either::Right(ids) => indexer.delete_documents(ids),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +164,7 @@ impl<'a> Dump<'a> {
|
||||
content_file: content_uuid.ok_or(Error::CorruptedDump)?,
|
||||
documents_count,
|
||||
allow_index_creation,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
KindDump::DocumentDeletion { documents_ids } => KindWithContent::DocumentDeletion {
|
||||
documents_ids,
|
||||
|
||||
@@ -502,11 +502,13 @@ impl Queue {
|
||||
*before_finished_at,
|
||||
)?;
|
||||
|
||||
batches = if query.reverse.unwrap_or_default() {
|
||||
batches.into_iter().take(*limit).collect()
|
||||
} else {
|
||||
batches.into_iter().rev().take(*limit).collect()
|
||||
};
|
||||
if let Some(limit) = limit {
|
||||
batches = if query.reverse.unwrap_or_default() {
|
||||
batches.into_iter().take(*limit as usize).collect()
|
||||
} else {
|
||||
batches.into_iter().rev().take(*limit as usize).collect()
|
||||
};
|
||||
}
|
||||
|
||||
Ok(batches)
|
||||
}
|
||||
@@ -600,8 +602,11 @@ impl Queue {
|
||||
Box::new(batches.into_iter().rev()) as Box<dyn Iterator<Item = u32>>
|
||||
};
|
||||
|
||||
let batches =
|
||||
self.batches.get_existing_batches(rtxn, batches.take(query.limit), processing)?;
|
||||
let batches = self.batches.get_existing_batches(
|
||||
rtxn,
|
||||
batches.take(query.limit.unwrap_or(u32::MAX) as usize),
|
||||
processing,
|
||||
)?;
|
||||
|
||||
Ok((batches, total))
|
||||
}
|
||||
|
||||
@@ -28,21 +28,21 @@ fn query_batches_from_and_limit() {
|
||||
|
||||
let proc = index_scheduler.processing_tasks.read().unwrap().clone();
|
||||
let rtxn = index_scheduler.env.read_txn().unwrap();
|
||||
let query = Query { limit: 0, ..Default::default() };
|
||||
let query = Query { limit: Some(0), ..Default::default() };
|
||||
let (batches, _) = index_scheduler
|
||||
.queue
|
||||
.get_batch_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &proc)
|
||||
.unwrap();
|
||||
snapshot!(snapshot_bitmap(&batches), @"[]");
|
||||
|
||||
let query = Query { limit: 1, ..Default::default() };
|
||||
let query = Query { limit: Some(1), ..Default::default() };
|
||||
let (batches, _) = index_scheduler
|
||||
.queue
|
||||
.get_batch_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &proc)
|
||||
.unwrap();
|
||||
snapshot!(snapshot_bitmap(&batches), @"[2,]");
|
||||
|
||||
let query = Query { limit: 2, ..Default::default() };
|
||||
let query = Query { limit: Some(2), ..Default::default() };
|
||||
let (batches, _) = index_scheduler
|
||||
.queue
|
||||
.get_batch_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &proc)
|
||||
@@ -63,14 +63,14 @@ fn query_batches_from_and_limit() {
|
||||
.unwrap();
|
||||
snapshot!(snapshot_bitmap(&batches), @"[0,1,2,]");
|
||||
|
||||
let query = Query { from: Some(1), limit: 1, ..Default::default() };
|
||||
let query = Query { from: Some(1), limit: Some(1), ..Default::default() };
|
||||
let (batches, _) = index_scheduler
|
||||
.queue
|
||||
.get_batch_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &proc)
|
||||
.unwrap();
|
||||
snapshot!(snapshot_bitmap(&batches), @"[1,]");
|
||||
|
||||
let query = Query { from: Some(1), limit: 2, ..Default::default() };
|
||||
let query = Query { from: Some(1), limit: Some(2), ..Default::default() };
|
||||
let (batches, _) = index_scheduler
|
||||
.queue
|
||||
.get_batch_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &proc)
|
||||
|
||||
@@ -31,9 +31,6 @@ use crate::{Error, IndexSchedulerOptions, Result, TaskId};
|
||||
|
||||
/// The number of database used by queue itself
|
||||
const NUMBER_OF_DATABASES: u32 = 1;
|
||||
/// The default limit for pagination
|
||||
const DEFAULT_LIMIT: usize = 20;
|
||||
|
||||
/// Database const names for the `IndexScheduler`.
|
||||
mod db_name {
|
||||
pub const BATCH_TO_TASKS_MAPPING: &str = "batch-to-tasks-mapping";
|
||||
@@ -43,11 +40,11 @@ mod db_name {
|
||||
///
|
||||
/// An empty/default query (where each field is set to `None`) matches all tasks.
|
||||
/// Each non-null field restricts the set of tasks further.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Query {
|
||||
/// The maximum number of tasks to be matched. Defaults to 20.
|
||||
pub limit: usize,
|
||||
/// The minimum [task id](`meilisearch_types::tasks::Task::uid`) to be matched. Defaults to 0.
|
||||
/// The maximum number of tasks to be matched
|
||||
pub limit: Option<u32>,
|
||||
/// The minimum [task id](`meilisearch_types::tasks::Task::uid`) to be matched
|
||||
pub from: Option<u32>,
|
||||
/// The order used to return the tasks. By default the newest tasks are returned first and the boolean is `false`.
|
||||
pub reverse: Option<bool>,
|
||||
@@ -86,29 +83,32 @@ pub struct Query {
|
||||
pub after_finished_at: Option<OffsetDateTime>,
|
||||
}
|
||||
|
||||
impl Default for Query {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
limit: DEFAULT_LIMIT,
|
||||
from: Default::default(),
|
||||
reverse: Default::default(),
|
||||
uids: Default::default(),
|
||||
batch_uids: Default::default(),
|
||||
statuses: Default::default(),
|
||||
types: Default::default(),
|
||||
index_uids: Default::default(),
|
||||
canceled_by: Default::default(),
|
||||
before_enqueued_at: Default::default(),
|
||||
after_enqueued_at: Default::default(),
|
||||
before_started_at: Default::default(),
|
||||
after_started_at: Default::default(),
|
||||
before_finished_at: Default::default(),
|
||||
after_finished_at: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Query {
|
||||
/// Return `true` if every field of the query is set to `None`, such that the query
|
||||
/// matches all tasks.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Query {
|
||||
limit: None,
|
||||
from: None,
|
||||
reverse: None,
|
||||
uids: None,
|
||||
batch_uids: None,
|
||||
statuses: None,
|
||||
types: None,
|
||||
index_uids: None,
|
||||
canceled_by: None,
|
||||
before_enqueued_at: None,
|
||||
after_enqueued_at: None,
|
||||
before_started_at: None,
|
||||
after_started_at: None,
|
||||
before_finished_at: None,
|
||||
after_finished_at: None,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/// Add an [index id](meilisearch_types::tasks::Task::index_uid) to the list of permitted indexes.
|
||||
pub fn with_index(self, index_uid: String) -> Self {
|
||||
let mut index_vec = self.index_uids.unwrap_or_default();
|
||||
@@ -119,7 +119,7 @@ impl Query {
|
||||
// Removes the `from` and `limit` restrictions from the query.
|
||||
// Useful to get the total number of tasks matching a filter.
|
||||
pub fn without_limits(self) -> Self {
|
||||
Query { limit: usize::MAX, from: None, ..self }
|
||||
Query { limit: None, from: None, ..self }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -465,11 +465,13 @@ impl Queue {
|
||||
*before_finished_at,
|
||||
)?;
|
||||
|
||||
tasks = if query.reverse.unwrap_or_default() {
|
||||
tasks.into_iter().take(*limit).collect()
|
||||
} else {
|
||||
tasks.into_iter().rev().take(*limit).collect()
|
||||
};
|
||||
if let Some(limit) = limit {
|
||||
tasks = if query.reverse.unwrap_or_default() {
|
||||
tasks.into_iter().take(*limit as usize).collect()
|
||||
} else {
|
||||
tasks.into_iter().rev().take(*limit as usize).collect()
|
||||
};
|
||||
}
|
||||
|
||||
Ok(tasks)
|
||||
}
|
||||
@@ -527,7 +529,9 @@ impl Queue {
|
||||
} else {
|
||||
Box::new(tasks.into_iter().rev()) as Box<dyn Iterator<Item = u32>>
|
||||
};
|
||||
let tasks = self.tasks.get_existing_tasks(rtxn, tasks.take(query.limit))?;
|
||||
let tasks = self
|
||||
.tasks
|
||||
.get_existing_tasks(rtxn, tasks.take(query.limit.unwrap_or(u32::MAX) as usize))?;
|
||||
|
||||
let ProcessingTasks { batch, processing, progress: _ } = processing_tasks;
|
||||
|
||||
|
||||
@@ -28,21 +28,21 @@ fn query_tasks_from_and_limit() {
|
||||
|
||||
let rtxn = index_scheduler.env.read_txn().unwrap();
|
||||
let processing = index_scheduler.processing_tasks.read().unwrap();
|
||||
let query = Query { limit: 0, ..Default::default() };
|
||||
let query = Query { limit: Some(0), ..Default::default() };
|
||||
let (tasks, _) = index_scheduler
|
||||
.queue
|
||||
.get_task_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &processing)
|
||||
.unwrap();
|
||||
snapshot!(snapshot_bitmap(&tasks), @"[]");
|
||||
|
||||
let query = Query { limit: 1, ..Default::default() };
|
||||
let query = Query { limit: Some(1), ..Default::default() };
|
||||
let (tasks, _) = index_scheduler
|
||||
.queue
|
||||
.get_task_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &processing)
|
||||
.unwrap();
|
||||
snapshot!(snapshot_bitmap(&tasks), @"[2,]");
|
||||
|
||||
let query = Query { limit: 2, ..Default::default() };
|
||||
let query = Query { limit: Some(2), ..Default::default() };
|
||||
let (tasks, _) = index_scheduler
|
||||
.queue
|
||||
.get_task_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &processing)
|
||||
@@ -63,14 +63,14 @@ fn query_tasks_from_and_limit() {
|
||||
.unwrap();
|
||||
snapshot!(snapshot_bitmap(&tasks), @"[0,1,2,]");
|
||||
|
||||
let query = Query { from: Some(1), limit: 1, ..Default::default() };
|
||||
let query = Query { from: Some(1), limit: Some(1), ..Default::default() };
|
||||
let (tasks, _) = index_scheduler
|
||||
.queue
|
||||
.get_task_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &processing)
|
||||
.unwrap();
|
||||
snapshot!(snapshot_bitmap(&tasks), @"[1,]");
|
||||
|
||||
let query = Query { from: Some(1), limit: 2, ..Default::default() };
|
||||
let query = Query { from: Some(1), limit: Some(2), ..Default::default() };
|
||||
let (tasks, _) = index_scheduler
|
||||
.queue
|
||||
.get_task_ids_from_authorized_indexes(&rtxn, &query, &AuthFilter::default(), &processing)
|
||||
|
||||
@@ -40,6 +40,7 @@ fn doc_imp(
|
||||
content_file: Uuid::new_v4(),
|
||||
documents_count: 0,
|
||||
allow_index_creation,
|
||||
on_missing_document: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::fmt;
|
||||
use std::io::ErrorKind;
|
||||
|
||||
use meilisearch_types::heed::RoTxn;
|
||||
use meilisearch_types::milli::update::IndexDocumentsMethod;
|
||||
use meilisearch_types::milli::update::{IndexDocumentsMethod, MissingDocumentPolicy};
|
||||
use meilisearch_types::settings::{Settings, Unchecked};
|
||||
use meilisearch_types::tasks::{BatchStopReason, Kind, KindWithContent, Status, Task};
|
||||
use roaring::RoaringBitmap;
|
||||
@@ -63,8 +63,8 @@ pub(crate) enum Batch {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum DocumentOperation {
|
||||
Replace(Uuid),
|
||||
Update(Uuid),
|
||||
Replace { content_file: Uuid, on_missing_document: MissingDocumentPolicy },
|
||||
Update { content_file: Uuid, on_missing_document: MissingDocumentPolicy },
|
||||
Delete(Vec<String>),
|
||||
}
|
||||
|
||||
@@ -293,13 +293,22 @@ impl IndexScheduler {
|
||||
for task in tasks.iter() {
|
||||
match task.kind {
|
||||
KindWithContent::DocumentAdditionOrUpdate {
|
||||
content_file, method, ..
|
||||
content_file,
|
||||
method,
|
||||
on_missing_document,
|
||||
..
|
||||
} => match method {
|
||||
IndexDocumentsMethod::ReplaceDocuments => {
|
||||
operations.push(DocumentOperation::Replace(content_file))
|
||||
operations.push(DocumentOperation::Replace {
|
||||
content_file,
|
||||
on_missing_document,
|
||||
})
|
||||
}
|
||||
IndexDocumentsMethod::UpdateDocuments => {
|
||||
operations.push(DocumentOperation::Update(content_file))
|
||||
operations.push(DocumentOperation::Update {
|
||||
content_file,
|
||||
on_missing_document,
|
||||
})
|
||||
}
|
||||
_ => unreachable!("Unknown document merging method"),
|
||||
},
|
||||
|
||||
@@ -77,8 +77,8 @@ impl IndexScheduler {
|
||||
let mut content_files = Vec::new();
|
||||
for operation in &operations {
|
||||
match operation {
|
||||
DocumentOperation::Replace(content_uuid)
|
||||
| DocumentOperation::Update(content_uuid) => {
|
||||
DocumentOperation::Replace { content_file: content_uuid, .. }
|
||||
| DocumentOperation::Update { content_file: content_uuid, .. } => {
|
||||
let content_file = self.queue.file_store.get_update(*content_uuid)?;
|
||||
let mmap = unsafe { memmap2::Mmap::map(&content_file)? };
|
||||
content_files.push(mmap);
|
||||
@@ -100,16 +100,16 @@ impl IndexScheduler {
|
||||
let embedders = self.embedders(index_uid.clone(), embedders)?;
|
||||
for operation in operations {
|
||||
match operation {
|
||||
DocumentOperation::Replace(_content_uuid) => {
|
||||
DocumentOperation::Replace { content_file: _, on_missing_document } => {
|
||||
let mmap = content_files_iter.next().unwrap();
|
||||
indexer
|
||||
.replace_documents(mmap)
|
||||
.replace_documents(mmap, on_missing_document)
|
||||
.map_err(|e| Error::from_milli(e, Some(index_uid.clone())))?;
|
||||
}
|
||||
DocumentOperation::Update(_content_uuid) => {
|
||||
DocumentOperation::Update { content_file: _, on_missing_document } => {
|
||||
let mmap = content_files_iter.next().unwrap();
|
||||
indexer
|
||||
.update_documents(mmap)
|
||||
.update_documents(mmap, on_missing_document)
|
||||
.map_err(|e| Error::from_milli(e, Some(index_uid.clone())))?;
|
||||
}
|
||||
DocumentOperation::Delete(document_ids) => {
|
||||
|
||||
@@ -294,6 +294,7 @@ fn document_addition_and_index_deletion() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -482,6 +483,7 @@ fn document_addition_and_index_deletion_on_unexisting_index() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
|
||||
@@ -31,6 +31,7 @@ fn document_addition() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -67,6 +68,7 @@ fn document_addition_and_document_deletion() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -133,6 +135,7 @@ fn document_deletion_and_document_addition() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -185,6 +188,7 @@ fn test_document_replace() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -236,6 +240,7 @@ fn test_document_update() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -289,6 +294,7 @@ fn test_mixed_document_addition() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -340,6 +346,7 @@ fn test_document_replace_without_autobatching() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -395,6 +402,7 @@ fn test_document_update_without_autobatching() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -454,6 +462,7 @@ fn test_document_addition_cant_create_index_without_index() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: false,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -506,6 +515,7 @@ fn test_document_addition_cant_create_index_without_index_without_autobatching()
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: false,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -568,6 +578,7 @@ fn test_document_addition_cant_create_index_with_index() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: false,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -635,6 +646,7 @@ fn test_document_addition_cant_create_index_with_index_without_autobatching() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: false,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -707,6 +719,7 @@ fn test_document_addition_mixed_rights_with_index() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -764,6 +777,7 @@ fn test_document_addition_mixed_right_without_index_starts_with_cant_create() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -820,6 +834,7 @@ fn test_document_addition_with_multiple_primary_key() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -883,6 +898,7 @@ fn test_document_addition_with_multiple_primary_key_batch_wrong_key() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -943,6 +959,7 @@ fn test_document_addition_with_bad_primary_key() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -1029,6 +1046,7 @@ fn test_document_addition_with_set_and_null_primary_key() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -1104,6 +1122,7 @@ fn test_document_addition_with_set_and_null_primary_key_inference_works() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
|
||||
@@ -173,6 +173,7 @@ fn import_vectors() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -263,6 +264,7 @@ fn import_vectors() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -399,6 +401,7 @@ fn import_vectors_first_and_embedder_later() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -539,6 +542,7 @@ fn import_vectors_first_and_embedder_later() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -640,6 +644,7 @@ fn delete_document_containing_vector() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: false,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -818,6 +823,7 @@ fn delete_embedder_with_user_provided_vectors() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: false,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
|
||||
@@ -52,6 +52,7 @@ fn fail_in_process_batch_for_document_addition() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -94,6 +95,7 @@ fn fail_in_update_task_after_process_batch_success_for_document_addition() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
@@ -160,6 +162,7 @@ fn fail_in_process_batch_for_document_deletion() {
|
||||
content_file: uuid,
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
},
|
||||
None,
|
||||
false,
|
||||
|
||||
@@ -197,6 +197,7 @@ pub(crate) fn replace_document_import_task(
|
||||
content_file: Uuid::from_u128(content_file_uuid),
|
||||
documents_count,
|
||||
allow_index_creation: true,
|
||||
on_missing_document: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -255,6 +255,7 @@ InvalidIndexLimit , InvalidRequest , BAD_REQU
|
||||
InvalidIndexOffset , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidIndexPrimaryKey , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidIndexCustomMetadata , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidSkipCreation , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidIndexUid , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidMultiSearchFacets , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidMultiSearchFacetsByIndex , InvalidRequest , BAD_REQUEST ;
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::str::FromStr;
|
||||
|
||||
use byte_unit::Byte;
|
||||
use enum_iterator::Sequence;
|
||||
use milli::update::IndexDocumentsMethod;
|
||||
use milli::update::{IndexDocumentsMethod, MissingDocumentPolicy};
|
||||
use milli::Object;
|
||||
use roaring::RoaringBitmap;
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
@@ -114,6 +114,7 @@ pub enum KindWithContent {
|
||||
content_file: Uuid,
|
||||
documents_count: u64,
|
||||
allow_index_creation: bool,
|
||||
on_missing_document: MissingDocumentPolicy,
|
||||
},
|
||||
DocumentDeletion {
|
||||
index_uid: String,
|
||||
|
||||
@@ -629,7 +629,7 @@ fn import_dump(
|
||||
|
||||
let mmap = unsafe { memmap2::Mmap::map(index_reader.documents_file())? };
|
||||
|
||||
indexer.replace_documents(&mmap)?;
|
||||
indexer.replace_documents(&mmap, Default::default())?;
|
||||
|
||||
let indexer_config = index_scheduler.indexer_config();
|
||||
let pool = &indexer_config.thread_pool;
|
||||
|
||||
@@ -20,7 +20,7 @@ use meilisearch_types::heed::RoTxn;
|
||||
use meilisearch_types::index_uid::IndexUid;
|
||||
use meilisearch_types::milli::documents::sort::recursive_sort;
|
||||
use meilisearch_types::milli::index::EmbeddingsWithMetadata;
|
||||
use meilisearch_types::milli::update::IndexDocumentsMethod;
|
||||
use meilisearch_types::milli::update::{IndexDocumentsMethod, MissingDocumentPolicy};
|
||||
use meilisearch_types::milli::vector::parsed_vectors::ExplicitVectors;
|
||||
use meilisearch_types::milli::{AscDesc, DocumentId};
|
||||
use meilisearch_types::serde_cs::vec::CS;
|
||||
@@ -687,6 +687,11 @@ pub struct UpdateDocumentsQuery {
|
||||
#[param(example = "custom")]
|
||||
#[deserr(default, error = DeserrQueryParamError<InvalidIndexCustomMetadata>)]
|
||||
pub custom_metadata: Option<String>,
|
||||
|
||||
#[param(example = "true")]
|
||||
#[deserr(default, try_from(&String) = from_string_skip_creation -> DeserrQueryParamError<InvalidSkipCreation>, error = DeserrQueryParamError<InvalidSkipCreation>)]
|
||||
/// Only update documents if they already exist.
|
||||
pub skip_creation: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Deserr, IntoParams)]
|
||||
@@ -711,6 +716,23 @@ fn from_char_csv_delimiter(
|
||||
}
|
||||
}
|
||||
|
||||
fn from_string_skip_creation(
|
||||
s: &String,
|
||||
) -> Result<Option<bool>, DeserrQueryParamError<InvalidSkipCreation>> {
|
||||
if s.eq_ignore_ascii_case("true") {
|
||||
return Ok(Some(true));
|
||||
}
|
||||
|
||||
if s.eq_ignore_ascii_case("false") {
|
||||
return Ok(Some(false));
|
||||
}
|
||||
|
||||
Err(DeserrQueryParamError::new(
|
||||
format!("skipCreation must be either `true` or `false`. Found: `{}`", s),
|
||||
Code::InvalidSkipCreation,
|
||||
))
|
||||
}
|
||||
|
||||
aggregate_methods!(
|
||||
Replaced => "Documents Added",
|
||||
Updated => "Documents Updated",
|
||||
@@ -840,6 +862,7 @@ pub async fn replace_documents(
|
||||
params.custom_metadata,
|
||||
dry_run,
|
||||
allow_index_creation,
|
||||
params.skip_creation,
|
||||
&req,
|
||||
)
|
||||
.await?;
|
||||
@@ -943,6 +966,7 @@ pub async fn update_documents(
|
||||
params.custom_metadata,
|
||||
dry_run,
|
||||
allow_index_creation,
|
||||
params.skip_creation,
|
||||
&req,
|
||||
)
|
||||
.await?;
|
||||
@@ -963,6 +987,7 @@ async fn document_addition(
|
||||
custom_metadata: Option<String>,
|
||||
dry_run: bool,
|
||||
allow_index_creation: bool,
|
||||
skip_creation: Option<bool>,
|
||||
req: &HttpRequest,
|
||||
) -> Result<SummarizedTaskView, MeilisearchHttpError> {
|
||||
let mime_type = extract_mime_type(req)?;
|
||||
@@ -1083,6 +1108,11 @@ async fn document_addition(
|
||||
primary_key,
|
||||
allow_index_creation,
|
||||
index_uid: index_uid.to_string(),
|
||||
on_missing_document: if matches!(skip_creation, Some(true)) {
|
||||
MissingDocumentPolicy::Skip
|
||||
} else {
|
||||
MissingDocumentPolicy::Create
|
||||
},
|
||||
};
|
||||
|
||||
let scheduler = index_scheduler.clone();
|
||||
|
||||
@@ -185,7 +185,7 @@ pub async fn get_metrics(
|
||||
// Fetch the finished batches...
|
||||
&Query {
|
||||
statuses: Some(vec![Status::Succeeded, Status::Failed]),
|
||||
limit: 1,
|
||||
limit: Some(1),
|
||||
..Query::default()
|
||||
},
|
||||
auth_filters,
|
||||
@@ -214,7 +214,7 @@ pub async fn get_metrics(
|
||||
let task_queue_latency_seconds = index_scheduler
|
||||
.get_tasks_from_authorized_indexes(
|
||||
&Query {
|
||||
limit: 1,
|
||||
limit: Some(1),
|
||||
reverse: Some(true),
|
||||
statuses: Some(vec![Status::Enqueued, Status::Processing]),
|
||||
..Query::default()
|
||||
|
||||
@@ -126,7 +126,7 @@ pub struct TasksFilterQuery {
|
||||
impl TasksFilterQuery {
|
||||
pub(crate) fn into_query(self) -> Query {
|
||||
Query {
|
||||
limit: self.limit.0 as usize,
|
||||
limit: Some(self.limit.0),
|
||||
from: self.from.as_deref().copied(),
|
||||
reverse: self.reverse.as_deref().copied(),
|
||||
batch_uids: self.batch_uids.merge_star_and_none(),
|
||||
@@ -225,8 +225,7 @@ pub struct TaskDeletionOrCancelationQuery {
|
||||
impl TaskDeletionOrCancelationQuery {
|
||||
fn into_query(self) -> Query {
|
||||
Query {
|
||||
// We want to delete all tasks that match the given filters
|
||||
limit: usize::MAX,
|
||||
limit: None,
|
||||
from: None,
|
||||
reverse: None,
|
||||
batch_uids: self.batch_uids.merge_star_and_none(),
|
||||
|
||||
@@ -64,7 +64,7 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index {
|
||||
let payload = unsafe { memmap2::Mmap::map(&file).unwrap() };
|
||||
|
||||
// index documents
|
||||
indexer.replace_documents(&payload).unwrap();
|
||||
indexer.replace_documents(&payload, Default::default()).unwrap();
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
let (document_changes, operation_stats, primary_key) = indexer
|
||||
|
||||
@@ -70,9 +70,11 @@ impl TempIndex {
|
||||
let mut indexer = indexer::DocumentOperation::new();
|
||||
match self.index_documents_config.update_method {
|
||||
IndexDocumentsMethod::ReplaceDocuments => {
|
||||
indexer.replace_documents(&documents).unwrap()
|
||||
indexer.replace_documents(&documents, Default::default()).unwrap()
|
||||
}
|
||||
IndexDocumentsMethod::UpdateDocuments => {
|
||||
indexer.update_documents(&documents, Default::default()).unwrap()
|
||||
}
|
||||
IndexDocumentsMethod::UpdateDocuments => indexer.update_documents(&documents).unwrap(),
|
||||
}
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
@@ -232,7 +234,7 @@ fn aborting_indexation() {
|
||||
{ "id": 2, "name": "bob", "age": 20 },
|
||||
{ "id": 2, "name": "bob", "age": 20 },
|
||||
]);
|
||||
indexer.replace_documents(&payload).unwrap();
|
||||
indexer.replace_documents(&payload, Default::default()).unwrap();
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
|
||||
@@ -67,6 +67,21 @@ pub enum IndexDocumentsMethod {
|
||||
UpdateDocuments,
|
||||
}
|
||||
|
||||
/// Controls whether new documents should be created when they don't already exist.
|
||||
///
|
||||
/// This policy is checked when processing a document whose ID is not found in the index.
|
||||
/// It applies to both update and replace operations.
|
||||
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum MissingDocumentPolicy {
|
||||
/// Create the document if it doesn't exist. This is the default behavior.
|
||||
#[default]
|
||||
Create,
|
||||
|
||||
/// Skip the document silently if it doesn't exist. No error is returned, the document is simply
|
||||
/// not indexed.
|
||||
Skip,
|
||||
}
|
||||
|
||||
pub struct IndexDocuments<'t, 'i, 'a, FP, FA> {
|
||||
wtxn: &'t mut heed::RwTxn<'i>,
|
||||
index: &'i Index,
|
||||
@@ -1971,10 +1986,10 @@ mod tests {
|
||||
let mut new_fields_ids_map = db_fields_ids_map.clone();
|
||||
|
||||
let mut indexer = indexer::DocumentOperation::new();
|
||||
indexer.replace_documents(&doc1).unwrap();
|
||||
indexer.replace_documents(&doc2).unwrap();
|
||||
indexer.replace_documents(&doc3).unwrap();
|
||||
indexer.replace_documents(&doc4).unwrap();
|
||||
indexer.replace_documents(&doc1, Default::default()).unwrap();
|
||||
indexer.replace_documents(&doc2, Default::default()).unwrap();
|
||||
indexer.replace_documents(&doc3, Default::default()).unwrap();
|
||||
indexer.replace_documents(&doc4, Default::default()).unwrap();
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
let (_document_changes, operation_stats, _primary_key) = indexer
|
||||
@@ -2024,10 +2039,10 @@ mod tests {
|
||||
let mut new_fields_ids_map = db_fields_ids_map.clone();
|
||||
|
||||
let mut indexer = indexer::DocumentOperation::new();
|
||||
indexer.replace_documents(&doc1).unwrap();
|
||||
indexer.update_documents(&doc2).unwrap();
|
||||
indexer.update_documents(&doc3).unwrap();
|
||||
indexer.update_documents(&doc4).unwrap();
|
||||
indexer.replace_documents(&doc1, Default::default()).unwrap();
|
||||
indexer.update_documents(&doc2, Default::default()).unwrap();
|
||||
indexer.update_documents(&doc3, Default::default()).unwrap();
|
||||
indexer.update_documents(&doc4, Default::default()).unwrap();
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
let (document_changes, operation_stats, primary_key) = indexer
|
||||
@@ -2112,11 +2127,11 @@ mod tests {
|
||||
let mut new_fields_ids_map = db_fields_ids_map.clone();
|
||||
|
||||
let mut indexer = indexer::DocumentOperation::new();
|
||||
indexer.replace_documents(&doc1).unwrap();
|
||||
indexer.update_documents(&doc2).unwrap();
|
||||
indexer.update_documents(&doc3).unwrap();
|
||||
indexer.replace_documents(&doc4).unwrap();
|
||||
indexer.update_documents(&doc5).unwrap();
|
||||
indexer.replace_documents(&doc1, Default::default()).unwrap();
|
||||
indexer.update_documents(&doc2, Default::default()).unwrap();
|
||||
indexer.update_documents(&doc3, Default::default()).unwrap();
|
||||
indexer.replace_documents(&doc4, Default::default()).unwrap();
|
||||
indexer.update_documents(&doc5, Default::default()).unwrap();
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
let (document_changes, operation_stats, primary_key) = indexer
|
||||
@@ -2307,7 +2322,7 @@ mod tests {
|
||||
let indexer_alloc = Bump::new();
|
||||
let embedders = RuntimeEmbedders::default();
|
||||
let mut indexer = indexer::DocumentOperation::new();
|
||||
indexer.replace_documents(&documents).unwrap();
|
||||
indexer.replace_documents(&documents, Default::default()).unwrap();
|
||||
indexer.delete_documents(&["2"]);
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
.into_changes(
|
||||
@@ -2362,13 +2377,13 @@ mod tests {
|
||||
{ "id": 3, "name": "jean", "age": 25 },
|
||||
]);
|
||||
let mut indexer = indexer::DocumentOperation::new();
|
||||
indexer.update_documents(&documents).unwrap();
|
||||
indexer.update_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
let documents = documents!([
|
||||
{ "id": 2, "catto": "jorts" },
|
||||
{ "id": 3, "legs": 4 },
|
||||
]);
|
||||
indexer.update_documents(&documents).unwrap();
|
||||
indexer.update_documents(&documents, Default::default()).unwrap();
|
||||
indexer.delete_documents(&["1", "2"]);
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
@@ -2426,7 +2441,7 @@ mod tests {
|
||||
let indexer_alloc = Bump::new();
|
||||
let embedders = RuntimeEmbedders::default();
|
||||
let mut indexer = indexer::DocumentOperation::new();
|
||||
indexer.update_documents(&documents).unwrap();
|
||||
indexer.update_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
.into_changes(
|
||||
@@ -2479,7 +2494,7 @@ mod tests {
|
||||
let indexer_alloc = Bump::new();
|
||||
let embedders = RuntimeEmbedders::default();
|
||||
let mut indexer = indexer::DocumentOperation::new();
|
||||
indexer.update_documents(&documents).unwrap();
|
||||
indexer.update_documents(&documents, Default::default()).unwrap();
|
||||
indexer.delete_documents(&["1", "2"]);
|
||||
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
@@ -2536,7 +2551,7 @@ mod tests {
|
||||
{ "id": 2, "doggo": { "name": "jean", "age": 20 } },
|
||||
{ "id": 3, "name": "bob", "age": 25 },
|
||||
]);
|
||||
indexer.update_documents(&documents).unwrap();
|
||||
indexer.update_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
.into_changes(
|
||||
@@ -2595,7 +2610,7 @@ mod tests {
|
||||
{ "id": 2, "doggo": { "name": "jean", "age": 20 } },
|
||||
{ "id": 3, "name": "bob", "age": 25 },
|
||||
]);
|
||||
indexer.update_documents(&documents).unwrap();
|
||||
indexer.update_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
indexer.delete_documents(&["1", "2", "1", "2"]);
|
||||
|
||||
@@ -2651,7 +2666,7 @@ mod tests {
|
||||
let documents = documents!([
|
||||
{ "id": 1, "doggo": "kevin" },
|
||||
]);
|
||||
indexer.update_documents(&documents).unwrap();
|
||||
indexer.update_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
.into_changes(
|
||||
@@ -2705,7 +2720,7 @@ mod tests {
|
||||
{ "id": 1, "catto": "jorts" },
|
||||
]);
|
||||
|
||||
indexer.replace_documents(&documents).unwrap();
|
||||
indexer.replace_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
.into_changes(
|
||||
@@ -2916,7 +2931,7 @@ mod tests {
|
||||
let documents = documents!([
|
||||
{ "id": 1, "doggo": "bernese" },
|
||||
]);
|
||||
indexer.replace_documents(&documents).unwrap();
|
||||
indexer.replace_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
// FINISHING
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
@@ -2978,7 +2993,7 @@ mod tests {
|
||||
let documents = documents!([
|
||||
{ "id": 0, "catto": "jorts" },
|
||||
]);
|
||||
indexer.replace_documents(&documents).unwrap();
|
||||
indexer.replace_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
.into_changes(
|
||||
@@ -3036,7 +3051,7 @@ mod tests {
|
||||
let documents = documents!([
|
||||
{ "id": 1, "catto": "jorts" },
|
||||
]);
|
||||
indexer.replace_documents(&documents).unwrap();
|
||||
indexer.replace_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
.into_changes(
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::update::new::indexer::current_edition::sharding::Shards;
|
||||
use crate::update::new::steps::IndexingStep;
|
||||
use crate::update::new::thread_local::MostlySend;
|
||||
use crate::update::new::{DocumentIdentifiers, Insertion, Update};
|
||||
use crate::update::{AvailableIds, IndexDocumentsMethod};
|
||||
use crate::update::{AvailableIds, IndexDocumentsMethod, MissingDocumentPolicy};
|
||||
use crate::{DocumentId, Error, FieldsIdsMap, Index, InternalError, Result, UserError};
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -37,20 +37,28 @@ impl<'pl> DocumentOperation<'pl> {
|
||||
/// Append a replacement of documents.
|
||||
///
|
||||
/// The payload is expected to be in the NDJSON format
|
||||
pub fn replace_documents(&mut self, payload: &'pl Mmap) -> Result<()> {
|
||||
pub fn replace_documents(
|
||||
&mut self,
|
||||
payload: &'pl Mmap,
|
||||
on_missing_document: MissingDocumentPolicy,
|
||||
) -> Result<()> {
|
||||
#[cfg(unix)]
|
||||
payload.advise(memmap2::Advice::Sequential)?;
|
||||
self.operations.push(Payload::Replace(&payload[..]));
|
||||
self.operations.push(Payload::Replace { payload: &payload[..], on_missing_document });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Append an update of documents.
|
||||
///
|
||||
/// The payload is expected to be in the NDJSON format
|
||||
pub fn update_documents(&mut self, payload: &'pl Mmap) -> Result<()> {
|
||||
pub fn update_documents(
|
||||
&mut self,
|
||||
payload: &'pl Mmap,
|
||||
on_missing_document: MissingDocumentPolicy,
|
||||
) -> Result<()> {
|
||||
#[cfg(unix)]
|
||||
payload.advise(memmap2::Advice::Sequential)?;
|
||||
self.operations.push(Payload::Update(&payload[..]));
|
||||
self.operations.push(Payload::Update { payload: &payload[..], on_missing_document });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -98,34 +106,40 @@ impl<'pl> DocumentOperation<'pl> {
|
||||
|
||||
let mut bytes = 0;
|
||||
let result = match operation {
|
||||
Payload::Replace(payload) => extract_addition_payload_changes(
|
||||
indexer,
|
||||
index,
|
||||
rtxn,
|
||||
primary_key_from_op,
|
||||
&mut primary_key,
|
||||
new_fields_ids_map,
|
||||
&mut available_docids,
|
||||
&mut bytes,
|
||||
&docids_version_offsets,
|
||||
IndexDocumentsMethod::ReplaceDocuments,
|
||||
shards,
|
||||
payload,
|
||||
),
|
||||
Payload::Update(payload) => extract_addition_payload_changes(
|
||||
indexer,
|
||||
index,
|
||||
rtxn,
|
||||
primary_key_from_op,
|
||||
&mut primary_key,
|
||||
new_fields_ids_map,
|
||||
&mut available_docids,
|
||||
&mut bytes,
|
||||
&docids_version_offsets,
|
||||
IndexDocumentsMethod::UpdateDocuments,
|
||||
shards,
|
||||
payload,
|
||||
),
|
||||
Payload::Replace { payload, on_missing_document } => {
|
||||
extract_addition_payload_changes(
|
||||
indexer,
|
||||
index,
|
||||
rtxn,
|
||||
primary_key_from_op,
|
||||
&mut primary_key,
|
||||
new_fields_ids_map,
|
||||
&mut available_docids,
|
||||
&mut bytes,
|
||||
&docids_version_offsets,
|
||||
IndexDocumentsMethod::ReplaceDocuments,
|
||||
shards,
|
||||
payload,
|
||||
on_missing_document,
|
||||
)
|
||||
}
|
||||
Payload::Update { payload, on_missing_document } => {
|
||||
extract_addition_payload_changes(
|
||||
indexer,
|
||||
index,
|
||||
rtxn,
|
||||
primary_key_from_op,
|
||||
&mut primary_key,
|
||||
new_fields_ids_map,
|
||||
&mut available_docids,
|
||||
&mut bytes,
|
||||
&docids_version_offsets,
|
||||
IndexDocumentsMethod::UpdateDocuments,
|
||||
shards,
|
||||
payload,
|
||||
on_missing_document,
|
||||
)
|
||||
}
|
||||
Payload::Deletion(to_delete) => extract_deletion_payload_changes(
|
||||
index,
|
||||
rtxn,
|
||||
@@ -180,6 +194,7 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
|
||||
method: IndexDocumentsMethod,
|
||||
shards: Option<&Shards>,
|
||||
payload: &'pl [u8],
|
||||
on_missing_document: MissingDocumentPolicy,
|
||||
) -> Result<hashbrown::HashMap<&'pl str, PayloadOperations<'pl>>> {
|
||||
use IndexDocumentsMethod::{ReplaceDocuments, UpdateDocuments};
|
||||
|
||||
@@ -271,6 +286,10 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
|
||||
|
||||
match method {
|
||||
ReplaceDocuments => {
|
||||
if matches!(on_missing_document, MissingDocumentPolicy::Skip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entry.insert(PayloadOperations::new_replacement(
|
||||
docid,
|
||||
true, // is new
|
||||
@@ -278,6 +297,10 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
|
||||
));
|
||||
}
|
||||
UpdateDocuments => {
|
||||
if matches!(on_missing_document, MissingDocumentPolicy::Skip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entry.insert(PayloadOperations::new_update(
|
||||
docid,
|
||||
true, // is new
|
||||
@@ -297,6 +320,12 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
|
||||
},
|
||||
Entry::Vacant(entry) => match method {
|
||||
ReplaceDocuments => {
|
||||
if payload_operations.is_new
|
||||
&& matches!(on_missing_document, MissingDocumentPolicy::Skip)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
entry.insert(PayloadOperations::new_replacement(
|
||||
payload_operations.docid,
|
||||
payload_operations.is_new,
|
||||
@@ -304,6 +333,12 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
|
||||
));
|
||||
}
|
||||
UpdateDocuments => {
|
||||
if payload_operations.is_new
|
||||
&& matches!(on_missing_document, MissingDocumentPolicy::Skip)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
entry.insert(PayloadOperations::new_update(
|
||||
payload_operations.docid,
|
||||
payload_operations.is_new,
|
||||
@@ -448,8 +483,8 @@ pub struct DocumentOperationChanges<'pl> {
|
||||
}
|
||||
|
||||
pub enum Payload<'pl> {
|
||||
Replace(&'pl [u8]),
|
||||
Update(&'pl [u8]),
|
||||
Replace { payload: &'pl [u8], on_missing_document: MissingDocumentPolicy },
|
||||
Update { payload: &'pl [u8], on_missing_document: MissingDocumentPolicy },
|
||||
Deletion(&'pl [&'pl str]),
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ fn test_facet_distribution_with_no_facet_values() {
|
||||
let documents = mmap_from_objects(vec![doc1, doc2]);
|
||||
|
||||
// index documents
|
||||
indexer.replace_documents(&documents).unwrap();
|
||||
indexer.replace_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
|
||||
@@ -85,7 +85,7 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index {
|
||||
let payload = unsafe { memmap2::Mmap::map(&file).unwrap() };
|
||||
|
||||
// index documents
|
||||
indexer.replace_documents(&payload).unwrap();
|
||||
indexer.replace_documents(&payload, Default::default()).unwrap();
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
let (document_changes, operation_stats, primary_key) = indexer
|
||||
|
||||
@@ -319,7 +319,7 @@ fn criteria_ascdesc() {
|
||||
file.sync_all().unwrap();
|
||||
|
||||
let payload = unsafe { memmap2::Mmap::map(&file).unwrap() };
|
||||
indexer.replace_documents(&payload).unwrap();
|
||||
indexer.replace_documents(&payload, Default::default()).unwrap();
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
.into_changes(
|
||||
&indexer_alloc,
|
||||
|
||||
@@ -126,7 +126,7 @@ fn test_typo_disabled_on_word() {
|
||||
let embedders = RuntimeEmbedders::default();
|
||||
let mut indexer = indexer::DocumentOperation::new();
|
||||
|
||||
indexer.replace_documents(&documents).unwrap();
|
||||
indexer.replace_documents(&documents, Default::default()).unwrap();
|
||||
|
||||
let indexer_alloc = Bump::new();
|
||||
let (document_changes, _operation_stats, primary_key) = indexer
|
||||
|
||||
Reference in New Issue
Block a user