Skip to content

Commit

Permalink
feature: added option to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
densumesh authored and skeptrunedev committed Sep 3, 2024
1 parent 897a46d commit 3dc1cef
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
2 changes: 2 additions & 0 deletions frontends/search/src/components/ResultsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions frontends/search/src/components/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ const SearchForm = (props: {
twoTypoWordRangeMax: null,
disableOnWords: [],
typoTolerance: false,
prioritize_domain_specifc_words: true,
highlightResults: true,
highlightDelimiters: ["?", ".", "!"],
highlightMaxLength: 8,
Expand Down Expand Up @@ -1219,6 +1220,26 @@ const SearchForm = (props: {
}}
/>
</div>
<div class="flex items-center justify-between space-x-2 p-1">
<label>Prioritize Domain Specific Words</label>
<input
class="h-4 w-4"
type="checkbox"
checked={
tempSearchValues()
.prioritize_domain_specifc_words ?? false
}
onChange={(e) => {
setTempSearchValues((prev) => {
return {
...prev,
prioritize_domain_specifc_words:
e.target.checked,
};
});
}}
/>
</div>
<div class="items flex justify-between space-x-2 p-1">
<label>One typo min word length:</label>
<input
Expand Down
6 changes: 6 additions & 0 deletions frontends/search/src/hooks/useSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface SearchOptions {
oneTypoWordRangeMax: number | null;
twoTypoWordRangeMin: number;
twoTypoWordRangeMax: number | null;
prioritize_domain_specifc_words: boolean | null;
disableOnWords: string[];
sort_by: SortByField | SortBySearchType;
pageSize: number;
Expand Down Expand Up @@ -86,6 +87,7 @@ const initalState: SearchOptions = {
oneTypoWordRangeMax: 8,
twoTypoWordRangeMin: 8,
twoTypoWordRangeMax: null,
prioritize_domain_specifc_words: true,
disableOnWords: [],
highlightResults: true,
highlightStrategy: "exactmatch",
Expand Down Expand Up @@ -123,6 +125,8 @@ const fromStateToParams = (state: SearchOptions): Params => {
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(),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/src/data/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
/// 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<bool>,
pub prioritize_domain_specifc_words: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug, Clone, ToSchema, Default)]
Expand Down
22 changes: 11 additions & 11 deletions server/src/operators/typo_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3dc1cef

Please sign in to comment.