diff options
author | Mauro D <mauro@stalw.art> | 2023-04-21 15:40:11 +0000 |
---|---|---|
committer | Mauro D <mauro@stalw.art> | 2023-04-21 15:40:11 +0000 |
commit | 46b5dc04253fe18748cfbdc77c68f0ec3e094efd (patch) | |
tree | 0398ce08c8619ac4947e08f39cc9cdf05284ccc0 /crates/store/src/query | |
parent | 51b14ed79ef5d7a0188af31ead5e634b2c039945 (diff) |
Email query and thread merge tests passing
Diffstat (limited to 'crates/store/src/query')
-rw-r--r-- | crates/store/src/query/filter.rs | 4 | ||||
-rw-r--r-- | crates/store/src/query/mod.rs | 52 | ||||
-rw-r--r-- | crates/store/src/query/sort.rs | 21 |
3 files changed, 52 insertions, 25 deletions
diff --git a/crates/store/src/query/filter.rs b/crates/store/src/query/filter.rs index 5f044423..32803532 100644 --- a/crates/store/src/query/filter.rs +++ b/crates/store/src/query/filter.rs @@ -69,6 +69,10 @@ impl ReadTransaction<'_> { ) .await? } + TextMatch::Raw => { + self.get_bitmap(BitmapKey::hash(&text, account_id, collection, 0, field)) + .await? + } }, Filter::InBitmap { family, field, key } => { self.get_bitmap(BitmapKey { diff --git a/crates/store/src/query/mod.rs b/crates/store/src/query/mod.rs index 2f2cce6f..508d2158 100644 --- a/crates/store/src/query/mod.rs +++ b/crates/store/src/query/mod.rs @@ -49,6 +49,7 @@ pub enum TextMatch { Exact(Language), Stemmed(Language), Tokenized, + Raw, } #[derive(Debug)] @@ -129,27 +130,32 @@ impl Filter { } } - pub fn has_text(field: impl Into<u8>, text: impl Into<String>, mut language: Language) -> Self { + pub fn has_text_detect( + field: impl Into<u8>, + text: impl Into<String>, + default_language: Language, + ) -> Self { let mut text = text.into(); - let op = if !matches!(language, Language::None) { - let match_phrase = (text.starts_with('"') && text.ends_with('"')) - || (text.starts_with('\'') && text.ends_with('\'')); - - if !match_phrase && language == Language::Unknown { - language = if let Some((l, t)) = text - .split_once(':') - .and_then(|(l, t)| (Language::from_iso_639(l)?, t.to_string()).into()) - { - text = t; - l - } else { - LanguageDetector::detect_single(&text) - .and_then(|(l, c)| if c > 0.3 { Some(l) } else { None }) - .unwrap_or(Language::Unknown) - }; - } + let language = if let Some((l, t)) = text + .split_once(':') + .and_then(|(l, t)| (Language::from_iso_639(l)?, t.to_string()).into()) + { + text = t; + l + } else { + LanguageDetector::detect_single(&text) + .and_then(|(l, c)| if c > 0.3 { Some(l) } else { None }) + .unwrap_or(default_language) + }; + Self::has_text(field, text, language) + } - if match_phrase { + pub fn has_text(field: impl Into<u8>, text: impl Into<String>, language: Language) -> Self { + let text = text.into(); + let op = if !matches!(language, Language::None) { + if (text.starts_with('"') && text.ends_with('"')) + || (text.starts_with('\'') && text.ends_with('\'')) + { TextMatch::Exact(language) } else { TextMatch::Stemmed(language) @@ -165,6 +171,14 @@ impl Filter { } } + pub fn has_raw_text(field: impl Into<u8>, text: impl Into<String>) -> Self { + Filter::HasText { + field: field.into(), + text: text.into(), + op: TextMatch::Raw, + } + } + pub fn has_english_text(field: impl Into<u8>, text: impl Into<String>) -> Self { Self::has_text(field, text, Language::English) } diff --git a/crates/store/src/query/sort.rs b/crates/store/src/query/sort.rs index c9cde6fe..70a314cd 100644 --- a/crates/store/src/query/sort.rs +++ b/crates/store/src/query/sort.rs @@ -1,3 +1,5 @@ +use std::cmp::Ordering; + use ahash::{AHashMap, AHashSet}; use crate::{ReadTransaction, Store, ValueKey}; @@ -155,7 +157,10 @@ impl ReadTransaction<'_> { let mut seen_prefixes = AHashSet::new(); let mut sorted_ids = sorted_ids.into_iter().collect::<Vec<_>>(); - sorted_ids.sort_by(|a, b| a.1.cmp(&b.1)); + sorted_ids.sort_by(|a, b| match a.1.cmp(&b.1) { + Ordering::Equal => a.0.cmp(&b.0), + other => other, + }); for (document_id, _) in sorted_ids { // Obtain document prefixId let prefix_id = if let Some(prefix_key) = &paginate.prefix_key { @@ -252,13 +257,17 @@ impl Pagination { // Pagination if !self.has_anchor { - if self.position > 0 { - self.position -= 1; + if self.position >= 0 { + if self.position > 0 { + self.position -= 1; + } else { + self.ids.push(id); + if self.ids.len() == self.limit { + return false; + } + } } else { self.ids.push(id); - if self.ids.len() == self.limit { - return false; - } } } else if self.anchor_offset >= 0 { if !self.anchor_found { |