sql server - Is there a way to parse a Google search string to a table variable in T-SQL? -


Is there a way to parse Google search string in a table variable in T-SQL?

By Google search string I mean, plus sign (requirement), zero mark (excluded), and exact phrase (double quote) operators.

For example, the following search string:

 one-two + three "four five" - ​​"six seven" + "eight nine" "ten eleven twelve" 

will be parsed in the table variable which I can use to generate T-SQL volume:

 operator STRING one - two + three four five - six seven + eight nine ten eleven twelve < / Pre> 

Thanks!

Parser is well written in any language by using the state machine. Nothing like getting the lube of your sins in order to put a small pacer in the morning:

  Declare it (maximum); Announce @t table (operator four (1) blank, token varchar (max)); Set @s = 'one-two + three' four five '- "six seven" + "eight nine" "ten eleven twelve"'; declared declared @state varchar (100); declared @operator char (1); declared @ token Varchar (max); declare @ c char (1); @ declite; set @state = 'start'; set @i = -1; while (1 = 1) set @i = @i + 1; if ( @ E & gt; lane (@ s) break; set @ c = substring (@s, @i, 1); if (@state = 'start') starts, then in @c ('-', ' + ') @ Operator = @c; set @ token =' '; set @state =' operator '; continue; and if' A 'and' Z '(' A 'and' C 'in' C ' With 'A' and 'Z'), '0' and '9' between @ C T @operator = null; set @token = @c; set @state = 'token'; Continue; Continue at the end; - Ignore the end of the noise if @state = token starts ('C' and Between 'C' and '0' and '9') set @ set = @ token + c; release; end; operator; token) value (@ operator, @ token) set @state = 'Start'; Continue; End & End if set @state = 'quote' if (@c! = '' ') Start set @taken = @ token + @; continue;; @t (operator) , Tokens) Enter the values ​​(@operator, @token); Set @state = 'start'; to continue; If the 'operator' 'operator' starts between 'A' and 'Z' for Android then set end and end then set @token = ''; Set @state = 'quote'; ) Or set ('0' and '9' between @ C @ token = @c; Set @state = 'token'; Continue; End and Start - Consider raising the error here, after the operator invalid characters +/- set @state = 'token' @t (operator, token) values ​​(@ obsolete state% s, 16,2, @ State); End = operator, @token) Finally if @state! = 'Start' starts raiserror ('incorrectly formatted string, state should not end in% s,', 16, 1, @state); Choose from the end * @;  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -