diff --git a/src/libs/SearchParser/searchParser.js b/src/libs/SearchParser/searchParser.js index 53d0ac82bec0..64d5334aa265 100644 --- a/src/libs/SearchParser/searchParser.js +++ b/src/libs/SearchParser/searchParser.js @@ -203,7 +203,7 @@ function peg$parse(input, options) { var peg$r0 = /^[:=]/; var peg$r1 = /^[^"\r\n]/; - var peg$r2 = /^[A-Za-z0-9_@.\/#&+\-\\',]/; + var peg$r2 = /^[A-Za-z0-9_@.\/#&+\-\\',;]/; var peg$r3 = /^[ \t\r\n]/; var peg$e0 = peg$classExpectation([":", "="], false, false); @@ -233,7 +233,7 @@ function peg$parse(input, options) { var peg$e24 = peg$literalExpectation("sortOrder", false); var peg$e25 = peg$literalExpectation("\"", false); var peg$e26 = peg$classExpectation(["\"", "\r", "\n"], true, false); - var peg$e27 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "@", ".", "/", "#", "&", "+", "-", "\\", "'", ","], false, false); + var peg$e27 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "@", ".", "/", "#", "&", "+", "-", "\\", "'", ",", ";"], false, false); var peg$e28 = peg$otherExpectation("whitespace"); var peg$e29 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); @@ -243,6 +243,18 @@ function peg$parse(input, options) { if (!allFilters.length) { return null; } + const keywords = allFilters.filter((filter) => filter.left === "keyword" || filter.right?.left === "keyword") + const nonKeywords = allFilters.filter((filter) => filter.left !== "keyword" && filter.right?.left !== "keyword") + if(!nonKeywords.length){ + return keywords.reduce((result, filter) => buildFilter("or", result, filter)) + } + if(!keywords.length){ + return nonKeywords.reduce((result, filter) => buildFilter("and", result, filter)) + } + + return buildFilter("and", keywords.reduce((result, filter) => buildFilter("or", result, filter)), nonKeywords.reduce((result, filter) => buildFilter("and", result, filter))) + + return allFilters.reduce((result, filter) => buildFilter("and", result, filter)); }; var peg$f2 = function(field, op, value) { diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index 310e942bbb80..d9ede101f7f8 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -3,8 +3,7 @@ // // Here's a general grammar structure: // -// start: entry point for the parser. It calls the query rule and return its value. -// query: rule to process the values returned by the filterList rule. Takes filters as an argument and returns the final AST output. +// query: entry point for the parser and rule to process the values returned by the filterList rule. Takes filters as an argument and returns the final AST output. // filterList: rule to process the array of filters returned by the filter rule. It takes head and tail as arguments, filters it for null values and builds the AST. // filter: rule to build the filter object. It takes field, operator and value as input and returns {operator, left: field, right: value} or null if the left value is a defaultValues // operator: rule to match pre-defined search syntax operators, e.g. !=, >, etc @@ -52,6 +51,18 @@ filterList if (!allFilters.length) { return null; } + const keywords = allFilters.filter((filter) => filter.left === "keyword" || filter.right?.left === "keyword") + const nonKeywords = allFilters.filter((filter) => filter.left !== "keyword" && filter.right?.left !== "keyword") + if(!nonKeywords.length){ + return keywords.reduce((result, filter) => buildFilter("or", result, filter)) + } + if(!keywords.length){ + return nonKeywords.reduce((result, filter) => buildFilter("and", result, filter)) + } + + return buildFilter("and", keywords.reduce((result, filter) => buildFilter("or", result, filter)), nonKeywords.reduce((result, filter) => buildFilter("and", result, filter))) + + return allFilters.reduce((result, filter) => buildFilter("and", result, filter)); } @@ -108,13 +119,10 @@ quotedString = '"' chars:[^"\r\n]* '"' { return chars.join(''); } alphanumeric - = chars:[A-Za-z0-9_@./#&+\-\\',]+ { return chars.join(''); } + = chars:[A-Za-z0-9_@./#&+\-\\',;]+ { return chars.join(''); } logicalAnd = _ { return "and"; } _ "whitespace" = [ \t\r\n]* - -start - = query