Search Grammar - HELP

Jul 12, 2012 at 3:50 PM

I'm using the Search grammar from the .sqlservercentral link. I found that when the user uses binary operators at the beginning of the search string the grammar brakes. Also when a parentheses/bracket is not closed or when a special character is included in the string. How can I handle all this cases?

e.g.:

  • nasal -aesthetic --> OK
  • -nasal aesthetic --> brakes (Syntax error, expected: OrExpression AndExpression PrimaryExpression ThesaurusExpression ThesaurusOperator ExactExpression ExactOperator ParenthesizedExpression ProximityExpression OrExpression')
  • nasal (hello -> brakes (Unexpected end of file.)
  • nasal \hello -> brakes (Invalid character: '\')
  • nasal /hello -> brakes (Invalid character: '/')
  • nasal "hello -> brakes (Mal-formed string literal - cannot find termination symbol)

I'm using the version of irony that is compiled with .net 3.5. Can't move to the last version.

Please help!!!

Coordinator
Jul 12, 2012 at 5:47 PM

as for "-" at the beginning, this is intentional - SQL server does not support FTS queries that start with "NOT", so the grammar is built in such a way that initial "-" is detected as error. This is by original design by Michael. 

When parenth or bracket is not closed - it is syntax error, Irony parser gives you an error - what else you'd expect it to do? You can try to handle error by adding the missing character at the end and parsing it again - one way to handle this automatically

Roman

Jul 12, 2012 at 10:16 PM

Thanks for your reply. Very helpful. As for the parentheses and brackets... I wonder how can I escape them and take them as a part of the string to look up.

How can I escape a special character and Irony will support it?

Jul 13, 2012 at 8:00 PM

Anything on this?.. please...

Coordinator
Jul 13, 2012 at 8:12 PM

About parenth and brackets - that would be not trivial, as "(" are ")" are special characters used in grammar expressions for grouping operators. Are you sure you need this? What about enclosing them in quotes, like

  hello "("  

You have to come up with rules for escaping inside identifiers, like "\(" - simplest case.

Next, I looked at IdentifierTerminal (that is used by SearchGrammar for regular words) and looks like it does not support this kind of escapes out of the box. So I suggest creating Custom terminal (inherited from Identifier), and overriding ReadBody method, and adding check for escaped parenthesis (just likeReadUnicodeEscapes call in the original method). 

Jul 19, 2012 at 9:15 PM
Edited Jul 19, 2012 at 9:45 PM

Thanks for the suggestion. I think you are right, I don't think I need the parentheses, I will probably strip them out of the query string. I will come back if I have new questions/cases.