Page 1 of 1

changing query syntax

Posted: Mon Mar 30, 2009 10:11 am
by basement_addict
Hi,

We have a client that would like to change the way they query to something like what monster does:

http://help.monster.com/js20/index.asp? ... t#location


examples:

php AND mysql AND apache

(php OR vortex) AND (oracle OR sqlite) AND linux


I was thinking I'd have to build a string parser to map the syntax to a texis query but I thought of checking with you guys first so I don't reinvent the wheel.

Thanks

changing query syntax

Posted: Mon Mar 30, 2009 10:47 am
by jason112
Actually, this is something we've just integrated in Webinator, these are the relevant bits:

<sandr "\space+>>OR=\space+" "," $sqlq>
<sandr "\space+>>AND=\space+NOT=\space+" ") -(" $ret>
<sandr "\space+>>NOT=\space+" ") -(" $ret>
<sandr "\space+>>AND=\space+" ") (" $ret>
<sandr ">>=\space+" "" $ret>
<sandr "\space+>>=" "" $ret>
<strfmt "(%s)" $ret>
<sandr ">>(=[^,)]+)=" '"\2"' $ret>

This supports AND, OR, NOT, and AND NOT. Note that it doesn't take parenthesis, but it will do what your second example wants with

php OR vortex AND oracle OR sqlite AND linux

Edit: fixed some repetition operators to properly match multiple spaces.