Skip to content

Commit

Permalink
feat: Save searches from extended mode
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Jan 16, 2025
1 parent 3bbdf0b commit 9ea9d66
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Sidebar: Collapse and expand attribute sections [#199](https://github.com/spraakbanken/korp-frontend/issues/199)
- Error messages from backend show up in the GUI [#97](https://github.com/spraakbanken/korp-frontend/issues/97)
- Catch unhandled errors and show in dialog [#419](https://github.com/spraakbanken/korp-frontend/issues/419)
- Save searches from extended mode [#118](https://github.com/spraakbanken/korp-frontend/issues/118)

### Changed

Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/search-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const createSearchOption = (params: SearchParams): SearchOption => ({

const getLabel = (params: SearchParams): string => {
if (!params.search) return "–"
if (params.search == "cqp") return params.cqp || "–"
const [type, value] = splitFirst("|", params.search)
return type === "lemgram" ? unregescape(value) : value
}
Expand Down
13 changes: 7 additions & 6 deletions app/scripts/services/searches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,19 @@ angular.module("korpApp").factory("searches", [
// The value is a string like <type>|<expr>
const [type, ...valueSplit] = searchExpr.split("|")
let value = valueSplit.join("|")

// Store new query in search history
// For Extended search, `value` is empty (then the CQP is instead in the `cqp` URL param)
if (value) {
searchHistory.addItem($location.search())
}
$q.all([searches.langDef.promise, $rootScope.globalFilterDef.promise]).then(function () {
// For Extended search, the CQP is instead in the `cqp` URL param
if (type === "cqp") {
if (!value) {
value = $location.search().cqp || ""
}
}

// Store new query in search history
if (value) {
searchHistory.addItem($location.search())
}

// Update stored search query
if (["cqp", "word", "lemgram"].includes(type)) {
$rootScope.activeSearch = { type, val: value }
Expand Down
8 changes: 6 additions & 2 deletions app/scripts/urlparams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,31 @@ export type SortMethod = "" | "keyword" | "left" | "right" | "random"

export type SearchParams = Pick<HashParams, SearchParamNames>

/** Parameters that define a search result set */
export type SearchParamNames =
export type SearchParamNames = Extract<
keyof HashParams,
| "corpus"
| "cqp"
| "global_filter"
| "in_order"
| "parallel_corpora"
| "search"
| "search_tab"
| "within"
| "prefix"
| "mid_comp"
| "suffix"
| "isCaseInsensitive"
>

/** Parameters that define a search result set */
export const getSearchParamNames = (): SearchParamNames[] => [
"corpus",
"cqp",
"global_filter",
"in_order",
"parallel_corpora",
"search",
"search_tab",
"within",
"prefix",
"mid_comp",
Expand Down

0 comments on commit 9ea9d66

Please sign in to comment.