@@ -26,8 +26,6 @@ type SimpleSearchController = IController & {
26
26
disableLemgramAutocomplete : boolean
27
27
freeOrder : boolean
28
28
freeOrderEnabled : boolean
29
- prefix : boolean
30
- suffix : boolean
31
29
isCaseInsensitive : boolean
32
30
currentText ?: string
33
31
lemgram ?: string
@@ -43,6 +41,13 @@ type SimpleSearchController = IController & {
43
41
onChange : ( value : string , isPlain : boolean ) => void
44
42
}
45
43
44
+ type SimpleSearchScope = IScope & {
45
+ prefix : boolean
46
+ midfix : boolean
47
+ suffix : boolean
48
+ onMidfixChange : ( ) => void
49
+ }
50
+
46
51
angular . module ( "korpApp" ) . component ( "simpleSearch" , {
47
52
template : html `
48
53
< div id ="korp-simple " class ="flex flex-wrap items-center gap-4 ">
@@ -65,47 +70,48 @@ angular.module("korpApp").component("simpleSearch", {
65
70
</ form >
66
71
< div class ="flex gap-4 ">
67
72
< 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 >
88
97
</ div >
89
98
< div class ="flex flex-col gap-1 ">
90
- < div class =" flex gap-2 " >
99
+ < label >
91
100
< input
92
- id ="freeOrderChk "
93
101
type ="checkbox "
94
102
ng-model ="$ctrl.freeOrder "
95
103
ng-disabled ="!$ctrl.freeOrderEnabled "
96
104
/>
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 >
109
115
</ div >
110
116
</ div >
111
117
</ div >
@@ -150,7 +156,7 @@ angular.module("korpApp").component("simpleSearch", {
150
156
function (
151
157
$location : LocationService ,
152
158
$rootScope : RootScope ,
153
- $scope : IScope ,
159
+ $scope : SimpleSearchScope ,
154
160
$timeout : ITimeoutService ,
155
161
$uibModal : ui . bootstrap . IModalService ,
156
162
compareSearches : CompareSearches ,
@@ -172,31 +178,45 @@ angular.module("korpApp").component("simpleSearch", {
172
178
ctrl . freeOrder = false
173
179
/** Whether the "free order" option is applicable. */
174
180
ctrl . freeOrderEnabled = false
175
- ctrl . prefix = false
176
- ctrl . suffix = false
177
181
ctrl . isCaseInsensitive = false
178
182
183
+ $scope . prefix = false
184
+ $scope . midfix = false
185
+ $scope . suffix = false
186
+
179
187
if ( settings . input_case_insensitive_default ) {
180
188
$location . search ( "isCaseInsensitive" , "" )
181
189
}
182
190
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
+
183
198
// React to changes in URL params
184
199
function watchParam < K extends keyof HashParams > ( key : K , callback : ( value : HashParams [ K ] ) => void ) {
185
200
$scope . $watch ( ( ) => $location . search ( ) [ key ] , callback )
186
201
}
187
202
188
203
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 ) )
191
206
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
+ }
193
213
} )
194
214
watchParam ( "isCaseInsensitive" , ( value ) => ( ctrl . isCaseInsensitive = value != null ) )
195
215
196
216
ctrl . updateSearch = function ( ) {
197
217
$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 )
200
220
$location . search ( "isCaseInsensitive" , ctrl . isCaseInsensitive ? true : null )
201
221
$location . search ( "within" , null )
202
222
$location . replace ( )
@@ -216,8 +236,8 @@ angular.module("korpApp").component("simpleSearch", {
216
236
if ( currentText ) {
217
237
currentText . split ( / \s + / ) . forEach ( ( word ) => {
218
238
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 } `
221
241
const condition : Condition = {
222
242
type : "word" ,
223
243
op : "=" ,
@@ -229,10 +249,10 @@ angular.module("korpApp").component("simpleSearch", {
229
249
} else if ( ctrl . lemgram ) {
230
250
const conditions : Condition [ ] = [ { type : "lex" , op : "contains" , val : ctrl . lemgram } ]
231
251
// The complemgram attribute is a set of strings like: <part1>+<part2>+<...>:<probability>
232
- if ( ctrl . prefix ) {
252
+ if ( $scope . prefix ) {
233
253
conditions . push ( { type : "complemgram" , op : "contains" , val : `${ ctrl . lemgram } \\+.*` } )
234
254
}
235
- if ( ctrl . suffix ) {
255
+ if ( $scope . suffix ) {
236
256
conditions . push ( { type : "complemgram" , op : "contains" , val : `.*\\+${ ctrl . lemgram } :.*` } )
237
257
}
238
258
query . push ( { and_block : [ conditions ] } )
0 commit comments