mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-25 06:00:08 +01:00
Make sure that we register the field when setting criteria
This commit is contained in:
parent
8e2c41e7f7
commit
82df524e09
@ -30,6 +30,16 @@ pub enum Criterion {
|
|||||||
Desc(String),
|
Desc(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Criterion {
|
||||||
|
/// Returns the field name parameter of this criterion.
|
||||||
|
pub fn field_name(&self) -> Option<&str> {
|
||||||
|
match self {
|
||||||
|
Criterion::Asc(name) | Criterion::Desc(name) => Some(name),
|
||||||
|
_otherwise => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for Criterion {
|
impl FromStr for Criterion {
|
||||||
type Err = anyhow::Error;
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
|
@ -8,9 +8,10 @@ use meilisearch_tokenizer::{Analyzer, AnalyzerConfig};
|
|||||||
use rayon::ThreadPool;
|
use rayon::ThreadPool;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
use crate::{FieldsIdsMap, Index};
|
use crate::criterion::Criterion;
|
||||||
use crate::update::{ClearDocuments, IndexDocuments, UpdateIndexingStep};
|
|
||||||
use crate::update::index_documents::{IndexDocumentsMethod, Transform};
|
use crate::update::index_documents::{IndexDocumentsMethod, Transform};
|
||||||
|
use crate::update::{ClearDocuments, IndexDocuments, UpdateIndexingStep};
|
||||||
|
use crate::{FieldsIdsMap, Index};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Setting<T> {
|
pub enum Setting<T> {
|
||||||
@ -403,12 +404,17 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
|||||||
fn update_criteria(&mut self) -> anyhow::Result<()> {
|
fn update_criteria(&mut self) -> anyhow::Result<()> {
|
||||||
match self.criteria {
|
match self.criteria {
|
||||||
Setting::Set(ref fields) => {
|
Setting::Set(ref fields) => {
|
||||||
|
let mut fields_ids_map = self.index.fields_ids_map(self.wtxn)?;
|
||||||
let mut new_criteria = Vec::new();
|
let mut new_criteria = Vec::new();
|
||||||
for name in fields {
|
for name in fields {
|
||||||
let criterion = name.parse()?;
|
let criterion: Criterion = name.parse()?;
|
||||||
|
if let Some(name) = criterion.field_name() {
|
||||||
|
fields_ids_map.insert(name).context("field id limit exceeded")?;
|
||||||
|
}
|
||||||
new_criteria.push(criterion);
|
new_criteria.push(criterion);
|
||||||
}
|
}
|
||||||
self.index.put_criteria(self.wtxn, &new_criteria)?;
|
self.index.put_criteria(self.wtxn, &new_criteria)?;
|
||||||
|
self.index.put_fields_ids_map(self.wtxn, &fields_ids_map)?;
|
||||||
}
|
}
|
||||||
Setting::Reset => { self.index.delete_criteria(self.wtxn)?; }
|
Setting::Reset => { self.index.delete_criteria(self.wtxn)?; }
|
||||||
Setting::NotSet => (),
|
Setting::NotSet => (),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user