A Google-like Full Text Search

  • According to Ivan this line is causing the issue:

    Term.Priority = Terminal.LowestPriority;

    If you remove this he says it should fix the problem. He says there's a deeper issue that he needs to address concerning this operation, but this simple fix should resolve the issue for this simple grammar.

    Thanks

    Mike C

  • That seems to work. All the same tests work after making that change and removing my workaround.

  • Thanks, this is a great article.

    Converted the SearchGrammer.cs to VB and works like a charm!

    Project was already a VB .NET web project, no choice.

    Great Job!

  • Just wondering if you had the code to make the OR operator take precedence over the AND operator in queries? I've tried modifying the SearchGrammar constructor code but cannot seem to get it to work.

    Thanks!

  • rherubin (11/3/2008)


    Just wondering if you had the code to make the OR operator take precedence over the AND operator in queries? I've tried modifying the SearchGrammar constructor code but cannot seem to get it to work.

    Thanks!

    You have to flip-flop the AndExpression and the OrExpression. Right now the AndExpression is a subcomponent of the OrExpression, so the AndExpression takes precedence. You would have to rewrite it so that the OrExpression would be a subcomponent of the AndExpression to give the OR operator precedence. This might be a little tricky since having no operator in between two expressions is equivalent to having an AND operator between them.

  • Thanks for the reply....here's the code that I wrote to switch between the "and" specific and "or" specific expressions (expressionType variable is of type enum as you can see in each case statements):

    switch (expressionType)

    {

    case ExpressionType.And:

    {

    Root = OrExpression;

    OrExpression.Rule = AndExpression | OrExpression + OrOperator + AndExpression;

    OrOperator.Rule = Symbol("or") | "|";

    AndExpression.Rule = PrimaryExpression | AndExpression + AndOperator + PrimaryExpression;

    AndOperator.Rule = Empty | "and" | "&" | ExcludeOperator;

    break;

    }

    case ExpressionType.Or:

    {

    Root = AndExpression;

    //AndExpression.Rule = PrimaryExpression | AndExpression + AndOperator + PrimaryExpression;

    AndExpression.Rule = OrExpression | AndExpression + AndOperator + OrExpression;

    AndOperator.Rule = ExcludeOperator | "and" | "&";

    //OrExpression.Rule = AndExpression | OrExpression + OrOperator + AndExpression;

    OrExpression.Rule = PrimaryExpression | OrExpression + OrOperator + PrimaryExpression;

    OrOperator.Rule = Empty | Symbol("or") | "|";

    break;

    }

    }

    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 = " ";

    MakePlusRule(ProximityList, Term);

    RegisterPunctuation(" ", "(", ")");

  • Hi!

    Thank you for your article. It was great reading.

    Just one question. Irony.dll has problem with non-english characters?

    I enter greek characters and the error is:

    Errors: Invalid character: '{greek for you :)}'

    Do you know if this error is fixed with a newer version of Irony. Unfortunately I cannot find the latest dll

  • Hi panteluke,

    I think you need to modify the grammar to handle international characters. Right now I use a pretty narrow definition for terminals: basically letters A-Z, a-z, numbers, and a few punctuation symbols. Try modifying the grammar to include additional Greek characters in the definition for terminals.

    If that doesn't work I would recommend checking with Roman to make sure this version of Irony is handling international/Unicode characters properly. My guess is that Irony can handle Unicode/international characters, but check the CodePlex site to verify that; I just didn't include them as part of the definition of a terminal in this example. The Irony website is at http://www.codeplex.com/irony. The full source and binaries for the most recent version of Irony is available there.

    Thanks

    Mike C

  • Thank you Mike.

    You were right about the extra chars in the grammar.

    Now, the dll that you have attached is fine.

  • I think there is a slight bug in the ExcludeOperator since if I search for e-learning it's doing all "e" that does not have learning.

    I think we should add a space before the exclude operator meaning it should behave like that if it was "e -learning" and not "e-learning".

    Does anyone ran accross this problem?

    Thanks,

    Flavio

  • Try changing the definition for a Terminal to add a hyphen:

    var Term = new IdentifierTerminal("Term", "!@#$%^*_'.?", "-!@#$%^*_'.?0123456789");

  • Great post!

    Seams like there is a problem with special characters. When i search for a word like "hår" (danish word for "hair"), the Language Compiler will return: Invalid character: 'å'. Anyone know how to fix this problem with special characters ?

    Thanks in advance =)

    Best regards,

    Carsten Petersen, Denmark

  • Hi Carsten,

    Add the characters to the definition of the Terminals (see my previous post above). To keep the definition simple I only used the standard 26-character Latin alphabet.

    Here's an example:

    var Term = new IdentifierTerminal("Term", "å!@#$%^*_'.?", "å-!@#$%^*_'.?0123456789");

    Note that the second parameter to IdentifierTerminal consists of the characters that can appear at the beginning of an identifier, the third parameter consists of the characters that can appear anywhere else in the identifer. By default the letters A-Z and a few punctuation symbols are automatically included in every IdentifierTerminal.

    Thanks

    Mike

  • Is there any possibility to use this using .NET 2.0? Because our project is under 2.0 and developed using VS 2005. We can't push the whole project to 3.5 to use this.

    How can I apply this GREAT thing under .NET 2.0??

    Please help! =P

    btw, great work, that's what exactly I was looking for... shame I cannot make it work under .net 2.0 =(

  • emzero (12/15/2008)


    Is there any possibility to use this using .NET 2.0? Because our project is under 2.0 and developed using VS 2005. We can't push the whole project to 3.5 to use this.

    How can I apply this GREAT thing under .NET 2.0??

    Please help! =P

    btw, great work, that's what exactly I was looking for... shame I cannot make it work under .net 2.0 =(

    Hi emzero, glad you found it useful. The source code for this and for Irony.NET are both available (the source for this is available here, for Irony.NET it's available on the Codeplex site). You should be able to download and compile to target your platform. I'm not sure if Irony uses any 3.5-specific features or if it will compile for .NET 2.0 -- you might check over on the Irony site to see if that's an option.

    Thanks

    Mike C

Viewing 15 posts - 31 through 45 (of 166 total)

You must be logged in to reply to this topic. Login to reply