SearchGrammar Example - Operator NOT followed by whitespace.

Oct 19, 2010 at 3:33 PM

Hi folks,

I'm using the SearchGrammar.cs from the examples for a FTS application.

I want to change the syntax to only identify the "-" binary operator if its NOT followed by a whitespace.

Example:
1. word1 - word2 

Should generate ((WORD1) AND (WORD2)) , "-" was removed because there is a white space after the operator.

2. word1 -word2 

Should generate ((WORD1) AND NOT (WORD2)) , "-" was removed and replaced by AND NOT.

Thanks!

Coordinator
Oct 20, 2010 at 6:33 PM

You need to set a flag on "-" term that would allow alpha-numeric to follow without space:

var minus = ToTerm(“-”);

minus.AllowAlphaAfterKeyword = true;

 

That would allow it to parse. Later, in conversion phase, you can analyze the positions of minus and following word, and detect if there was a space between or not. 


 

Oct 20, 2010 at 7:03 PM

Hi rivanstov,

Thanks for the answer.

I think i found a different solution

I added another binary operator "- " , that includes a whitespace in it.

So now i have two operators working , one triggers when there is a space and the other when there is no space.

 

public SearchGrammer {
.....
BinaryOp.Rule = ImpliedAnd | "and" | "&" | "-" | "or" | "|" | "- "; 
.....
}

private static string ConvertQuery(ParseTreeNode node, TermType type)
{
....
case "BinaryExpression":
                    string opSym = string.Empty;
                    string op = node.ChildNodes[1].FindTokenAndGetText().ToLower();
                    string sqlOp = "";
                    switch (op)
                    {
                        case "":
                        case "&":
                        case "and":
                            sqlOp = " AND ";
                            type = TermType.Inflectional;
                            break;
                        case "-":
                            sqlOp = " AND NOT ";
                            break;
                        case "|":
                        case "or":
                            sqlOp = " OR ";
                            break;
                        case "- ": 
                            sqlOp = " AND ";
                            break;
                    }//switch
....
}

I'm not sure if i did it in the correct way , but i didn't really understand how to do it in the way you suggested.
It would be great if you could post a bit more detailed explanation or code sample.
thanks!

 

Coordinator
Oct 21, 2010 at 9:38 PM

your solution seem ok, even simpler than mine. So don't worry, you're on the right path

Roman