@@ -178,7 +178,22 @@ fn convert_user_input_ast_to_query_ast(
178178 Ok ( term_set_query. into ( ) )
179179 }
180180 UserInputLeaf :: Exists { field } => Ok ( FieldPresenceQuery { field } . into ( ) ) ,
181- UserInputLeaf :: Regex { .. } => bail ! ( "regex query is not supported" ) ,
181+ UserInputLeaf :: Regex { field, pattern } => {
182+ let field = if let Some ( field) = field {
183+ field
184+ } else if default_search_fields. len ( ) == 1 {
185+ default_search_fields[ 0 ] . clone ( )
186+ } else if default_search_fields. is_empty ( ) {
187+ bail ! ( "regex query without field is not supported" ) ;
188+ } else {
189+ bail ! ( "regex query with multiple fields is not supported" ) ;
190+ } ;
191+ let regex_query = query_ast:: RegexQuery {
192+ field,
193+ regex : pattern,
194+ } ;
195+ Ok ( regex_query. into ( ) )
196+ }
182197 } ,
183198 UserInputAst :: Boost ( underlying, boost) => {
184199 let query_ast = convert_user_input_ast_to_query_ast (
@@ -536,4 +551,21 @@ mod tests {
536551 ) ;
537552 }
538553 }
554+
555+ #[ test]
556+ fn test_user_input_query_regex ( ) {
557+ let ast = UserInputQuery {
558+ user_text : "field: /.*/" . to_string ( ) ,
559+ default_fields : None ,
560+ default_operator : BooleanOperand :: And ,
561+ lenient : false ,
562+ }
563+ . parse_user_query ( & [ ] )
564+ . unwrap ( ) ;
565+ let QueryAst :: Regex ( regex_query) = ast else {
566+ panic ! ( )
567+ } ;
568+ assert_eq ! ( & regex_query. field, "field" ) ;
569+ assert_eq ! ( & regex_query. regex, ".*" ) ;
570+ }
539571}
0 commit comments