From a96bd2251e24e18cae43c20941eb9981e1dc707c 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 | 22 +++++++++---------- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/frontends/search/src/components/ResultsPage.tsx b/frontends/search/src/components/ResultsPage.tsx index 370cd69e44..e503a160f5 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 055b20c134..e7b6ee504b 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(), @@ -184,6 +188,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 ff41defd3b..713113c1da 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..db20cc954b 100644 --- a/server/src/operators/typo_operator.rs +++ b/server/src/operators/typo_operator.rs @@ -610,17 +610,17 @@ 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) { + 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; }