C# Full Text Search Box Criteria Parsing

C# Full Text Search Box Criteria Parsing

Post by Larry Neyl » Wed, 07 Mar 2007 07:06:20


Hi there,

Has anyone written the code to take a user text box containing full text
search criteria and convert it into the string that you can pass to SQL
Server's CONTAINSTEXT command ?

What I think it needs to do is check for multiple words. If there are
multiple words surround with double quotes, unless there are already some
double quotes in there. It also needs to handle whether AND and ORs have
been entered before deciding whether to surround the whole thing with double
quotes.

So I have to convert:

Chairman -> Chairman
Temporary Chairman -> "Temporary Chairman"
Temporary AND Chairman -> Temporary AND Chairman
Temporary AND New Chairman -> Temporary AND "New Chairman"
Temporary AND "New Chairman" -> Temporary AND "New Chairman"
Temporary AND "New Chairman -> Temporary AND "New Chairman" (i.e. cater for
missed or extra quotes)

I'm sure using regular expressions this shouldn't actually be that hard, and
I can't believe I'm the first person to want to do this.

Any assistance much appreciated.

Thanks,
Larry.