This project has moved and is read-only. For the latest updates, please go here.

Cant search anything beginning with "Phrase" in Irony

Jan 20, 2011 at 11:59 AM


        This is my search query which returns null AST root node...what is wrong with this...

"mechanical engineer" and (oil or gas) and mumbai


I am using the following grammar...

public FTSQueryGrammar()
            // Terminals
            var Term = new IdentifierTerminal("Term", "!@#$%^*_'.?", "!@#$%^*_'.?0123456789");
            // The following is not very imporant, but makes scanner recognize "or" and "and" as operators, not Terms
            // The "or" and "and" operator symbols found in grammar get higher priority in scanning and are checked
            // first, before the Term terminal, so Scanner produces operator token, not Term. For our purposes it does
            // not matter, we get around without it.
            Term.Priority = Terminal.LowestPriority;
            var Phrase = new StringLiteral("Phrase","\"",ScanFlags.None);

            // NonTerminals
            var OrExpression = new NonTerminal("OrExpression");
            var OrOperator = new NonTerminal("OrOperator");
            var AndExpression = new NonTerminal("AndExpression");
            var AndOperator = new NonTerminal("AndOperator");
            var ExcludeOperator = new NonTerminal("ExcludeOperator");
            var PrimaryExpression = new NonTerminal("PrimaryExpression");
            var ThesaurusExpression = new NonTerminal("ThesaurusExpression");
            var ThesaurusOperator = new NonTerminal("ThesaurusOperator");
            var ExactOperator = new NonTerminal("ExactOperator");
            var ExactExpression = new NonTerminal("ExactExpression");
            var ParenthesizedExpression = new NonTerminal("ParenthesizedExpression");
            var ProximityExpression = new NonTerminal("ProximityExpression");
            var ProximityList = new NonTerminal("ProximityList");

            this.Root = OrExpression;
            OrExpression.Rule = AndExpression
                              | OrExpression + OrOperator + AndExpression;
            OrOperator.Rule = Symbol(" or ") | "|";
            AndExpression.Rule = PrimaryExpression
                               | AndExpression + AndOperator + PrimaryExpression;
            AndOperator.Rule = Empty
                             | " and "
                             | "&"
                             | ExcludeOperator;
            ExcludeOperator.Rule = Symbol("-");
            PrimaryExpression.Rule = Term
                                   | ThesaurusExpression
                                   | ExactExpression
                                   | ParenthesizedExpression
                                   | Phrase
                                   | ProximityExpression;
            ThesaurusExpression.Rule = ThesaurusOperator + Term;
            ThesaurusOperator.Rule = Symbol("~");
            ExactExpression.Rule = ExactOperator + Term
                                 | ExactOperator + Phrase;
            ExactOperator.Rule = Symbol("+");           
            ParenthesizedExpression.Rule = "(" + OrExpression + ")";
            ProximityExpression.Rule = "<" + ProximityList + ">";

            MakePlusRule(ProximityList, Term);

            RegisterPunctuation("<", ">", "(", ")");



Please any help greatly appreciated.




Jan 20, 2011 at 7:35 PM

Please use the SearchGrammar version in samples included in download on this site. 

The code in Michael's article is outdated. 

The phrase works fine in current version


Jan 22, 2011 at 10:20 AM

Hello Roman,

                   Thanks for you're quick reply.I really appreciate that.

Roman even that grammar was not working for "Phrase" and "ParantesizedExpression" properly,i tested that.But now i found one solution.

There are few bugs in the grammar which i rectified and created one console application project in C#.NET.I want to post that project where can i post that project so that rest users can refer that?or should i post you the modified grammar productions to check it out?


Awaiting you're reply.




Jan 22, 2011 at 5:14 PM

Well, that's strange, nobody complained about this grammar in samples. Just checked it again, everything works. 

What input are you entering, what you see as output and what you would expect as output?


Jan 22, 2011 at 5:17 PM
Edited Jan 22, 2011 at 7:24 PM

When you enter "term", the output is "term" - the same. This is expected, this is in fact a correct FTS Query.

To use it in SQL, you have to put it into Contains operator:


Select * from dbo.Documents

Where Contains(*, "term")