Skip to content

Commit dcee0b8

Browse files
committed
fix: restore medial part
1 parent 129ca39 commit dcee0b8

File tree

4 files changed

+73
-49
lines changed

4 files changed

+73
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- Instead of `settings.time_data`, use `import { timeData } from "./timedata"`
1515
- Await `getTimeData()` before using `timeData` or `corpus.time`/`corpus.non_time`. The function is memoized, so repeated calls will not affect performance
1616
- Load Statistics and Word picture result when the tab is selected [#442](https://github.com/spraakbanken/korp-frontend/issues/442)
17-
- Remove redundant "medial part" option [#443](https://github.com/spraakbanken/korp-frontend/issues/443)
17+
- The "medial part" search option is logically linked to initial and final part [#443](https://github.com/spraakbanken/korp-frontend/issues/443)
1818
- The display options (hits per page, sort within corpora, compile based on) were moved into the KWIC and Statistics tab correspondingly
1919
- When these are changed, the search is re-triggered automatically
2020
- The "compile based on" input was relabeled as "group by"

app/scripts/components/simple-search.ts

Lines changed: 68 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ type SimpleSearchController = IController & {
2626
disableLemgramAutocomplete: boolean
2727
freeOrder: boolean
2828
freeOrderEnabled: boolean
29-
prefix: boolean
30-
suffix: boolean
3129
isCaseInsensitive: boolean
3230
currentText?: string
3331
lemgram?: string
@@ -43,6 +41,13 @@ type SimpleSearchController = IController & {
4341
onChange: (value: string, isPlain: boolean) => void
4442
}
4543

44+
type SimpleSearchScope = IScope & {
45+
prefix: boolean
46+
midfix: boolean
47+
suffix: boolean
48+
onMidfixChange: () => void
49+
}
50+
4651
angular.module("korpApp").component("simpleSearch", {
4752
template: html`
4853
<div id="korp-simple" class="flex flex-wrap items-center gap-4">
@@ -65,47 +70,48 @@ angular.module("korpApp").component("simpleSearch", {
6570
</form>
6671
<div class="flex gap-4">
6772
<div class="flex flex-col gap-1">
68-
<div class="flex gap-2">
69-
<input id="prefixChk" type="checkbox" ng-model="$ctrl.prefix" />
70-
<label for="prefixChk">
71-
{{'prefix_chk' | loc:$root.lang}}
72-
<i
73-
class="fa fa-info-circle text-gray-400 table-cell align-middle mb-0.5"
74-
uib-tooltip="{{'prefix_chk_help' | loc:$root.lang}}"
75-
></i>
76-
</label>
77-
</div>
78-
<div class="flex gap-2">
79-
<input id="suffixChk" type="checkbox" ng-model="$ctrl.suffix" />
80-
<label for="suffixChk">
81-
{{'suffix_chk' | loc:$root.lang}}
82-
<i
83-
class="fa fa-info-circle text-gray-400 table-cell align-middle mb-0.5"
84-
uib-tooltip="{{'suffix_chk_help' | loc:$root.lang}}"
85-
></i>
86-
</label>
87-
</div>
73+
<label>
74+
<input type="checkbox" ng-model="prefix" />
75+
{{'prefix_chk' | loc:$root.lang}}
76+
<i
77+
class="fa fa-info-circle text-gray-400 table-cell align-middle mb-0.5"
78+
uib-tooltip="{{'prefix_chk_help' | loc:$root.lang}}"
79+
></i>
80+
</label>
81+
<label>
82+
<input type="checkbox" ng-model="midfix" ng-change="onMidfixChange()" />
83+
{{'midfix_chk' | loc:$root.lang}}
84+
<i
85+
class="fa fa-info-circle text-gray-400 table-cell align-middle mb-0.5"
86+
uib-tooltip="{{'midfix_chk_help' | loc:$root.lang}}"
87+
></i>
88+
</label>
89+
<label>
90+
<input type="checkbox" ng-model="suffix" />
91+
{{'suffix_chk' | loc:$root.lang}}
92+
<i
93+
class="fa fa-info-circle text-gray-400 table-cell align-middle mb-0.5"
94+
uib-tooltip="{{'suffix_chk_help' | loc:$root.lang}}"
95+
></i>
96+
</label>
8897
</div>
8998
<div class="flex flex-col gap-1">
90-
<div class="flex gap-2">
99+
<label>
91100
<input
92-
id="freeOrderChk"
93101
type="checkbox"
94102
ng-model="$ctrl.freeOrder"
95103
ng-disabled="!$ctrl.freeOrderEnabled"
96104
/>
97-
<label for="freeOrderChk">
98-
{{'free_order_chk' | loc:$root.lang}}
99-
<i
100-
class="fa fa-info-circle text-gray-400 table-cell align-middle mb-0.5"
101-
uib-tooltip="{{'free_order_chk_help' | loc:$root.lang}}"
102-
></i>
103-
</label>
104-
</div>
105-
<div class="flex gap-2">
106-
<input id="caseChk" type="checkbox" ng-model="$ctrl.isCaseInsensitive" />
107-
<label for="caseChk"> {{'case_insensitive' | loc:$root.lang}} </label>
108-
</div>
105+
{{'free_order_chk' | loc:$root.lang}}
106+
<i
107+
class="fa fa-info-circle text-gray-400 table-cell align-middle mb-0.5"
108+
uib-tooltip="{{'free_order_chk_help' | loc:$root.lang}}"
109+
></i>
110+
</label>
111+
<label>
112+
<input type="checkbox" ng-model="$ctrl.isCaseInsensitive" />
113+
{{'case_insensitive' | loc:$root.lang}}
114+
</label>
109115
</div>
110116
</div>
111117
</div>
@@ -150,7 +156,7 @@ angular.module("korpApp").component("simpleSearch", {
150156
function (
151157
$location: LocationService,
152158
$rootScope: RootScope,
153-
$scope: IScope,
159+
$scope: SimpleSearchScope,
154160
$timeout: ITimeoutService,
155161
$uibModal: ui.bootstrap.IModalService,
156162
compareSearches: CompareSearches,
@@ -172,31 +178,45 @@ angular.module("korpApp").component("simpleSearch", {
172178
ctrl.freeOrder = false
173179
/** Whether the "free order" option is applicable. */
174180
ctrl.freeOrderEnabled = false
175-
ctrl.prefix = false
176-
ctrl.suffix = false
177181
ctrl.isCaseInsensitive = false
178182

183+
$scope.prefix = false
184+
$scope.midfix = false
185+
$scope.suffix = false
186+
179187
if (settings.input_case_insensitive_default) {
180188
$location.search("isCaseInsensitive", "")
181189
}
182190

191+
$scope.$watch("prefix", () => ($scope.midfix = $scope.prefix && $scope.suffix))
192+
$scope.$watch("suffix", () => ($scope.midfix = $scope.prefix && $scope.suffix))
193+
$scope.onMidfixChange = () => {
194+
$scope.prefix = $scope.midfix
195+
$scope.suffix = $scope.midfix
196+
}
197+
183198
// React to changes in URL params
184199
function watchParam<K extends keyof HashParams>(key: K, callback: (value: HashParams[K]) => void) {
185200
$scope.$watch(() => $location.search()[key], callback)
186201
}
187202

188203
watchParam("in_order", (value) => (ctrl.freeOrder = value != null))
189-
watchParam("prefix", (value) => (ctrl.prefix = value != null))
190-
watchParam("suffix", (value) => (ctrl.suffix = value != null))
204+
watchParam("prefix", (value) => ($scope.prefix = value != null))
205+
watchParam("suffix", (value) => ($scope.suffix = value != null))
191206
watchParam("mid_comp", (value) => {
192-
if (value != null) ctrl.prefix = ctrl.suffix = true
207+
// Deprecated param. Translate to prefix/suffix.
208+
if (value != null) {
209+
$location.search("mid_comp", null)
210+
$location.search("prefix", true)
211+
$location.search("suffix", true)
212+
}
193213
})
194214
watchParam("isCaseInsensitive", (value) => (ctrl.isCaseInsensitive = value != null))
195215

196216
ctrl.updateSearch = function () {
197217
$location.search("in_order", ctrl.freeOrder && ctrl.freeOrderEnabled ? false : null)
198-
$location.search("prefix", ctrl.prefix ? true : null)
199-
$location.search("suffix", ctrl.suffix ? true : null)
218+
$location.search("prefix", $scope.prefix ? true : null)
219+
$location.search("suffix", $scope.suffix ? true : null)
200220
$location.search("isCaseInsensitive", ctrl.isCaseInsensitive ? true : null)
201221
$location.search("within", null)
202222
$location.replace()
@@ -216,8 +236,8 @@ angular.module("korpApp").component("simpleSearch", {
216236
if (currentText) {
217237
currentText.split(/\s+/).forEach((word) => {
218238
let value = regescape(word)
219-
if (ctrl.prefix) value = `${value}.*`
220-
if (ctrl.suffix) value = `.*${value}`
239+
if ($scope.prefix) value = `${value}.*`
240+
if ($scope.suffix) value = `.*${value}`
221241
const condition: Condition = {
222242
type: "word",
223243
op: "=",
@@ -229,10 +249,10 @@ angular.module("korpApp").component("simpleSearch", {
229249
} else if (ctrl.lemgram) {
230250
const conditions: Condition[] = [{ type: "lex", op: "contains", val: ctrl.lemgram }]
231251
// The complemgram attribute is a set of strings like: <part1>+<part2>+<...>:<probability>
232-
if (ctrl.prefix) {
252+
if ($scope.prefix) {
233253
conditions.push({ type: "complemgram", op: "contains", val: `${ctrl.lemgram}\\+.*` })
234254
}
235-
if (ctrl.suffix) {
255+
if ($scope.suffix) {
236256
conditions.push({ type: "complemgram", op: "contains", val: `.*\\+${ctrl.lemgram}:.*` })
237257
}
238258
query.push({ and_block: [conditions] })

app/translations/locale-eng.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@
408408
"free_order_chk_help": "The search words can occur in any order, and not necessarily in sequence.",
409409
"prefix_chk": "initial part",
410410
"prefix_chk_help": "Allow words that begin with the search words.",
411+
"midfix_chk": "medial part",
412+
"midfix_chk_help": "Allow words that begin or end with the search words.",
411413
"suffix_chk": "final part",
412414
"suffix_chk_help": "Allow words that end with the search words.",
413415
"text_tab_header": "Reading mode",

app/translations/locale-swe.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@
407407
"free_order_chk_help": "Sökorden får förekomma i obestämd ordning, och inte nödvändigtvis i följd.",
408408
"prefix_chk": "förled",
409409
"prefix_chk_help": "Tillåt ord som börjar med sökorden.",
410+
"midfix_chk": "mellanled",
411+
"midfix_chk_help": "Tillåt ord som börjar eller slutar med sökorden.",
410412
"suffix_chk": "efterled",
411413
"suffix_chk_help": "Tillåt ord som slutar med sökorden.",
412414
"text_tab_header": "Läsläge",

0 commit comments

Comments
 (0)