Skip to content

Commit

Permalink
[feat] 0.23.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed May 11, 2024
1 parent 8b06507 commit 815c32f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions summa-core/src/components/query_parser/morphology/english.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Default for EnglishMorphology {
}

impl Morphology for EnglishMorphology {
fn derive_tenses(&self, word: &str) -> Option<String> {
fn derive_tenses(&self, word: &str) -> Option<(String, String)> {
thread_local! {
static NOT_A_NOUN: (RegexSet, HashSet<&'static str>) = (RegexSet::new([
r"\d$",
Expand All @@ -56,9 +56,9 @@ impl Morphology for EnglishMorphology {
let is_singular = pluralize_rs::is_singular(word);
let is_plural = pluralize_rs::is_plural(word);
if is_singular {
Some(pluralize_rs::to_plural(word))
Some((word.to_string(), pluralize_rs::to_plural(word)))
} else if is_plural {
Some(pluralize_rs::to_singular(word))
Some((pluralize_rs::to_singular(word), word.to_string()))
} else {
None
}
Expand Down
24 changes: 15 additions & 9 deletions summa-core/src/components/query_parser/morphology/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashSet;
use summa_proto::proto;
use tantivy::query::{DisjunctionMaxQuery, Query, TermQuery};
use tantivy::schema::{Field, FieldType, IndexRecordOption};
Expand All @@ -11,7 +10,7 @@ pub use manager::MorphologyManager;
use crate::components::query_parser::utils::cast_field_to_term;

pub trait Morphology: MorphologyClone + Send + Sync {
fn derive_tenses(&self, word: &str) -> Option<String>;
fn derive_tenses(&self, word: &str) -> Option<(String, String)>;
fn derive_spelling(&self, word: &str) -> Option<String>;

fn derive_query(&self, config: proto::MorphologyConfig, field: &Field, full_path: &str, field_type: &FieldType, text: &str) -> Box<dyn Query> {
Expand All @@ -21,14 +20,21 @@ pub trait Morphology: MorphologyClone + Send + Sync {
let term = cast_field_to_term(field, full_path, field_type, text, false);
return Box::new(TermQuery::new(term, IndexRecordOption::WithFreqs)) as Box<dyn Query>;
};
let mut terms = HashSet::new();
terms.insert(text.to_string());
if let Some(other_tense_text) = self.derive_tenses(text) {
terms.insert(other_tense_text);
let mut terms = vec![];
if let Some((singular, plural)) = self.derive_tenses(text) {
terms.push(singular);
terms.push(plural);
} else {
terms.push(text.to_string());
}
if let Some(spelling) = self.derive_spelling(&terms[0]) {
if let Some((spelling_tense_singular, spelling_tense_plural)) = self.derive_tenses(&spelling) {
terms.push(spelling_tense_singular);
terms.push(spelling_tense_plural);
} else {
terms.push(spelling);
}
}
terms.extend(terms.iter().filter_map(|t| self.derive_spelling(t)).collect::<Vec<_>>());
terms.extend(terms.iter().filter_map(|t| self.derive_tenses(t)).collect::<Vec<_>>());
let terms = Vec::from_iter(terms.into_iter());
if terms.len() == 1 {
Box::new(TermQuery::new(
cast_field_to_term(field, full_path, field_type, &terms[0], false),
Expand Down
2 changes: 1 addition & 1 deletion summa-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "summa-server"
version = "0.23.7"
version = "0.23.8"
license-file = "LICENSE"
description = "Fast full-text search server"
homepage = "https://github.com/izihawa/summa"
Expand Down

0 comments on commit 815c32f

Please sign in to comment.