• Oleg (10/7/2008)


    Hi Mike,

    very useful article, especially code - thank you.

    I tested code and found one problem.

    If I entered phrase:

    president -aluminium

    it wokrs fine.

    If phrase is:

    -aluminium president

    it generates syntax error, phrase cannot start from negation. I checked goole it understand correctly this kind of phrases.

    How can I edit grammar to avoid this kind of errors?

    Thank you again.

    Regards,

    Oleg.

    Hi Oleg

    I fought with this issue myself and decided to "keep it simple" by defining a rule that the first token can't be preceded by a minus sign. The issue is that, owing to the simple nature of the recursive AST walker, the grammar maps fairly closely to the iFTS grammar. In IFTS grammar you have to use the AND NOT operator (there's no NOT without AND). Starting an iFTS query string with AND NOT ("AND NOT aluminum AND president" is not allowed in iFTS). You could use a more complex algorithm to rearrange the nodes of the AST to deal with this issue in a more user-friendly way, but I really wanted to keep the sample code simple for the article. I also considered using a more advanced algorithm like applying the visitor pattern to the AST, but again to keep it simple I decided to stick with the simple recursive tree walker.

    Thanks

    Mike C