use std::collections::HashSet;
use std::sync::OnceLock;
use crate::format::catalog::StopwordsPolicy;
const ENGLISH_LUCENE: &[&str] = &[
"a", "an", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it",
"no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these",
"they", "this", "to", "was", "will", "with",
];
pub(crate) fn resolve(policy: StopwordsPolicy) -> Option<&'static HashSet<&'static [u8]>> {
match policy {
StopwordsPolicy::None => None,
StopwordsPolicy::EnglishLucene => Some(english_lucene_set()),
}
}
fn english_lucene_set() -> &'static HashSet<&'static [u8]> {
static SET: OnceLock<HashSet<&'static [u8]>> = OnceLock::new();
SET.get_or_init(|| ENGLISH_LUCENE.iter().map(|s| s.as_bytes()).collect())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn english_lucene_has_33_entries() {
let s = english_lucene_set();
assert_eq!(s.len(), 33);
}
#[test]
fn english_lucene_contains_canonical_members() {
let s = english_lucene_set();
for word in ["the", "and", "of", "into", "with"] {
assert!(s.contains(word.as_bytes()), "missing {word}");
}
}
#[test]
fn english_lucene_does_not_contain_non_stopwords() {
let s = english_lucene_set();
for word in ["python", "covid", "diabetes", "statin"] {
assert!(!s.contains(word.as_bytes()), "unexpected stopword {word}");
}
}
#[test]
fn resolve_none_returns_none() {
assert!(resolve(StopwordsPolicy::None).is_none());
}
}