Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 8b14090

Browse files
MarinPostmaKerollmops
authored andcommitted
fix min-word-len-for-typo not reset properly
1 parent ea4bb94 commit 8b14090

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

milli/src/update/settings.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::index_documents::{IndexDocumentsConfig, Transform};
1010
use super::IndexerConfig;
1111
use crate::criterion::Criterion;
1212
use crate::error::UserError;
13+
use crate::index::{DEFAULT_MIN_WORD_LEN_ONE_TYPO, DEFAULT_MIN_WORD_LEN_TWO_TYPOS};
1314
use crate::update::index_documents::IndexDocumentsMethod;
1415
use crate::update::{ClearDocuments, IndexDocuments, UpdateIndexingStep};
1516
use crate::{FieldsIdsMap, Index, Result};
@@ -46,6 +47,14 @@ impl<T> Setting<T> {
4647
pub const fn is_not_set(&self) -> bool {
4748
matches!(self, Self::NotSet)
4849
}
50+
51+
/// If `Self` is `Reset`, then map self to `Set` with the provided `val`.
52+
pub fn or_reset(self, val: T) -> Self {
53+
match self {
54+
Self::Reset => Self::Set(val),
55+
otherwise => otherwise,
56+
}
57+
}
4958
}
5059

5160
impl<T: Serialize> Serialize for Setting<T> {
@@ -535,7 +544,9 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
535544
}
536545

537546
fn update_min_typo_word_len(&mut self) -> Result<()> {
538-
match (self.min_word_len_one_typo, self.min_word_len_two_typos) {
547+
let one = self.min_word_len_one_typo.or_reset(DEFAULT_MIN_WORD_LEN_ONE_TYPO);
548+
let two = self.min_word_len_two_typos.or_reset(DEFAULT_MIN_WORD_LEN_TWO_TYPOS);
549+
match (one, two) {
539550
(Setting::Set(one), Setting::Set(two)) => {
540551
if one > two {
541552
return Err(UserError::InvalidMinTypoWordLenSetting(one, two).into());
@@ -1422,6 +1433,20 @@ mod tests {
14221433

14231434
assert_eq!(index.min_word_len_one_typo(&txn).unwrap(), 8);
14241435
assert_eq!(index.min_word_len_two_typos(&txn).unwrap(), 8);
1436+
1437+
let mut txn = index.write_txn().unwrap();
1438+
let mut builder = Settings::new(&mut txn, &index, &config);
1439+
1440+
builder.reset_min_word_len_one_typo();
1441+
builder.reset_min_word_len_two_typos();
1442+
builder.execute(|_| ()).unwrap();
1443+
1444+
txn.commit().unwrap();
1445+
1446+
let txn = index.read_txn().unwrap();
1447+
1448+
assert_eq!(index.min_word_len_one_typo(&txn).unwrap(), DEFAULT_MIN_WORD_LEN_ONE_TYPO);
1449+
assert_eq!(index.min_word_len_two_typos(&txn).unwrap(), DEFAULT_MIN_WORD_LEN_TWO_TYPOS);
14251450
}
14261451

14271452
#[test]

0 commit comments

Comments
 (0)