Skip to content

Commit

Permalink
fix: allow multiple set attributes in filters
Browse files Browse the repository at this point in the history
Fixes #116
  • Loading branch information
arildm committed Oct 31, 2024
1 parent 8f2cfa6 commit ff9a324
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Extracted Karp backend usage into `app/scripts/karp.ts`
- `stringifyFunc(key)` was renamed to `getStringifier(key)`
- `stringify(key, x)` was removed, use `getStringifier(key)(x)` instead
- For `getStructValues()` of `structService`, the `split` option now takes a list of attribute names, not a bool

### Fixed

Expand All @@ -24,6 +25,7 @@
- Barcode (aka hitsPicture) sometimes missing from KWIC tab [#395](https://github.com/spraakbanken/korp-frontend/issues/395)
- Error when loading with restricted corpora selected [#398](https://github.com/spraakbanken/korp-frontend/issues/398)
- Related words lookup must use OR [#401](https://github.com/spraakbanken/korp-frontend/issues/401)
- Add support for annotations of the type 'set' in attribute filters [#116](https://github.com/spraakbanken/korp-frontend/issues/116)

## [9.7.1] - 2024-09-18

Expand Down
5 changes: 3 additions & 2 deletions app/scripts/backend/struct-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export type StructService = {
export type StructServiceOptions = {
count?: boolean
returnByCorpora?: boolean
split?: boolean
/** Attributes that should be split (used for sets) */
split?: string[]
}

/** @see https://ws.spraakbanken.gu.se/docs/korp#tag/Misc/paths/~1attr_values/get */
Expand Down Expand Up @@ -58,7 +59,7 @@ angular.module("korpApp").factory("structService", [
count,
}

if (split) params.split = _.last(attributes)
if (split) params.split = split.join(",")

const conf = httpConfAddMethod({
url: settings["korp_backend_url"] + "/attr_values",
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/components/extended/widgets/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const selectController = (autocomplete: boolean): IController => [
$scope.loading = true
const opts: StructServiceOptions = { count: false, returnByCorpora: false }
if ($scope.type === "set") {
opts.split = true
opts.split = [attribute]
}
structService.getStructValues(corpora, [attribute], opts).then(
function (data: string[]) {
Expand Down
4 changes: 1 addition & 3 deletions app/scripts/global-filter/global-filter-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ angular.module("korpApp").factory("globalFilterService", [
const corpora = getSupportedCorpora()

const opts: StructServiceOptions = {}
if (dataObj.attributes[_.last(dataObj.defaultFilters)!].settings.type === "set") {
opts.split = true
}
opts.split = dataObj.defaultFilters.filter((name) => dataObj.attributes[name].settings.type === "set")

type R = Record<string, RecursiveRecord<Record<string, number>>>
const data = (await structService.getStructValues(corpora, dataObj.defaultFilters, opts)) as R
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/settings/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export type Config = {
}

export type Corpus = {
/** Attributes to use in global filters */
attribute_filters: string[]
context: Labeled[]
description: LangString
hide?: boolean
Expand Down

0 comments on commit ff9a324

Please sign in to comment.