From b66122d91899f342dfb7ade9e412f986482a02e6 Mon Sep 17 00:00:00 2001 From: Dens Sumesh Date: Tue, 3 Sep 2024 11:19:04 -0700 Subject: [PATCH] feature: added option to frontend --- .../search/src/components/ResultsPage.tsx | 2 ++ .../search/src/components/SearchForm.tsx | 21 +++++++++++++++++ frontends/search/src/hooks/useSearch.ts | 6 +++++ server/src/data/models.rs | 2 +- server/src/operators/typo_operator.rs | 23 ++++++++++--------- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/frontends/search/src/components/ResultsPage.tsx b/frontends/search/src/components/ResultsPage.tsx index 73d9bb147e..a5af7a78f8 100644 --- a/frontends/search/src/components/ResultsPage.tsx +++ b/frontends/search/src/components/ResultsPage.tsx @@ -294,6 +294,8 @@ const ResultsPage = (props: ResultsPageProps) => { max: props.search.debounced.twoTypoWordRangeMax, }, disable_on_word: props.search.debounced.disableOnWords, + prioritize_domain_specifc_words: + props.search.debounced.prioritize_domain_specifc_words, }, highlight_options: { highlight_results: props.search.debounced.highlightResults ?? true, diff --git a/frontends/search/src/components/SearchForm.tsx b/frontends/search/src/components/SearchForm.tsx index 78c14b6fb4..b2f6e193d7 100644 --- a/frontends/search/src/components/SearchForm.tsx +++ b/frontends/search/src/components/SearchForm.tsx @@ -1058,6 +1058,7 @@ const SearchForm = (props: { twoTypoWordRangeMax: null, disableOnWords: [], typoTolerance: false, + prioritize_domain_specifc_words: true, highlightResults: true, highlightDelimiters: ["?", ".", "!"], highlightMaxLength: 8, @@ -1219,6 +1220,26 @@ const SearchForm = (props: { }} /> +
+ + { + setTempSearchValues((prev) => { + return { + ...prev, + prioritize_domain_specifc_words: + e.target.checked, + }; + }); + }} + /> +
{ oneTypoWordRangeMax: state.oneTypoWordRangeMax?.toString() ?? "8", twoTypoWordRangeMin: state.twoTypoWordRangeMin.toString(), twoTypoWordRangeMax: state.twoTypoWordRangeMax?.toString() ?? "", + prioritize_domain_specifc_words: + state.prioritize_domain_specifc_words?.toString() ?? "", disableOnWords: state.disableOnWords.join(","), highlightStrategy: state.highlightStrategy, highlightResults: state.highlightResults.toString(), @@ -166,6 +170,8 @@ const fromParamsToState = ( oneTypoWordRangeMax: parseIntOrNull(params.oneTypoWordRangeMax), twoTypoWordRangeMin: parseInt(params.oneTypoWordRangeMin ?? "8"), twoTypoWordRangeMax: parseIntOrNull(params.twoTypoWordRangeMax), + prioritize_domain_specifc_words: + (params.prioritize_domain_specifc_words ?? "true") === "true", disableOnWords: params.disableOnWords?.split(",") ?? [], highlightResults: (params.highlightResults ?? "true") === "true", highlightStrategy: isHighlightStrategy(params.highlightStrategy) diff --git a/server/src/data/models.rs b/server/src/data/models.rs index c194b911a2..ad364d07bb 100644 --- a/server/src/data/models.rs +++ b/server/src/data/models.rs @@ -5297,7 +5297,7 @@ pub struct TypoOptions { /// Words that should not be corrected. If not specified, this defaults to an empty list. pub disable_on_word: Option>, /// Auto-require non-english words present in the dataset to exist in each results chunk_html text. If not specified, this defaults to true. - pub auto_require_non_english_words: Option, + pub prioritize_domain_specifc_words: Option, } #[derive(Serialize, Deserialize, Debug, Clone, ToSchema, Default)] diff --git a/server/src/operators/typo_operator.rs b/server/src/operators/typo_operator.rs index 9e859501ce..1034f3a5c8 100644 --- a/server/src/operators/typo_operator.rs +++ b/server/src/operators/typo_operator.rs @@ -610,17 +610,18 @@ fn correct_query_helper( continue; } - if options.auto_require_non_english_words.unwrap_or(true) - && !tree.find(word.to_string(), 0).is_empty() - { - new_quote_words.push(word); - query.quote_words = match query.quote_words { - Some(mut existing_words) => { - existing_words.push(word.to_string()); - Some(existing_words) - } - None => Some(vec![word.to_string()]), - }; + if !tree.find(word.to_string(), 0).is_empty() { + if options.prioritize_domain_specifc_words.unwrap_or(true) { + println!("Prioritizing domain specific word: {}", word); + new_quote_words.push(word); + query.quote_words = match query.quote_words { + Some(mut existing_words) => { + existing_words.push(word.to_string()); + Some(existing_words) + } + None => Some(vec![word.to_string()]), + }; + } continue; }