@@ -14,6 +14,7 @@ import "./global-filters"
1414import { Condition , CqpQuery } from "@/cqp_parser/cqp.types"
1515import { StoreService } from "@/services/store"
1616import { savedSearches } from "@/search/saved-searches"
17+ import { buildSimpleLemgramCqp , buildSimpleWordCqp } from "@/search/simple-search"
1718
1819type SimpleSearchController = IController & {
1920 input : string
@@ -185,29 +186,12 @@ angular.module("korpApp").component("simpleSearch", {
185186 }
186187
187188 ctrl . getCQP = function ( ) {
188- const query : CqpQuery = [ ]
189+ let query : CqpQuery = [ ]
189190 const currentText = ( ctrl . currentText || "" ) . trim ( )
190191
191- if ( currentText ) {
192- currentText . split ( / \s + / ) . forEach ( ( word ) => {
193- let value = regescape ( word )
194- if ( $scope . prefix ) value = `${ value } .*`
195- if ( $scope . suffix ) value = `.*${ value } `
196- const condition = createCondition ( value )
197- if ( ctrl . isCaseInsensitive ) condition . flags = { c : true }
198- query . push ( { and_block : [ [ condition ] ] } )
199- } )
200- } else if ( ctrl . lemgram ) {
201- const conditions : Condition [ ] = [ { type : "lex" , op : "contains" , val : ctrl . lemgram } ]
202- // The complemgram attribute is a set of strings like: <part1>+<part2>+<...>:<probability>
203- if ( $scope . prefix ) {
204- conditions . push ( { type : "complemgram" , op : "contains" , val : `${ ctrl . lemgram } \\+.*` } )
205- }
206- if ( $scope . suffix ) {
207- conditions . push ( { type : "complemgram" , op : "contains" , val : `.*\\+${ ctrl . lemgram } :.*` } )
208- }
209- query . push ( { and_block : [ conditions ] } )
210- }
192+ if ( currentText )
193+ query = buildSimpleWordCqp ( currentText , $scope . prefix , $scope . suffix , ctrl . isCaseInsensitive )
194+ else if ( ctrl . lemgram ) query = buildSimpleLemgramCqp ( ctrl . lemgram , $scope . prefix , $scope . suffix )
211195
212196 if ( store . globalFilter ) mergeCqpExprs ( query , store . globalFilter )
213197 return stringify ( query )
0 commit comments