Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How can i parse google-like search strings?

by pernod (Chaplain)
on Jul 01, 2005 at 09:04 UTC ( #471599=perlquestion: print w/replies, xml ) Need Help??

pernod has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks,

I've searched cpan, super searched and googled, and I'm sure I've overlooked something. Therefore this little question.

My $firm has a web application, where we would like to take google-like search strings and process these for insertion into sql-statements. Example:

PersonId < 3 and OrganisationId = 4

This search string will then be translated into some data-structure that can be transmitted to our sql-generation functions. There are probably a million ways to solve this with regular expressions, Parse::RecDescent and whatnot. Safety-issues (sql-insertion, for example) makes this a delicate issue, though.

Does anyone know of a module that implements this? I am almost certain that this is a wheel that does not need to be reinvented, I'm just unable to find it at the moment. Thank you for listening.

pernod
--
Mischief. Mayhem. Soap.

Replies are listed 'Best First'.
Re: How can i parse google-like search strings?
by bart (Canon) on Jul 01, 2005 at 09:28 UTC
    There's a module Text::Query on CPAN, which is, if I understood it correctly, designed for this kind of parsing. However, it is old and no longer maintained, probably due to lack of interest from the public. It might still work well, though.

      Thank you!

      This looks very interesting, I'll take a closer look to see if this is the wheel I'm looking for.

      pernod
      --
      Mischief. Mayhem. Soap.

Re: How can i parse google-like search strings?
by Joost (Canon) on Jul 01, 2005 at 09:25 UTC

      I realize that my question was poorly phrased. SQL::Statement would be useful in this context, but it takes care of the second part of the problem. Namely generating the SQL.

      As bart helpfully pointed out, the thing I'm searching for is a widget that translates the value of $cgi->param("search_field") into a data structure that can be fed to something like SQL::Statement.

      Thank you for your suggestion, though :)

      pernod
      --
      Mischief. Mayhem. Soap.

Re: How can i parse google-like search strings?
by Anonymous Monk on Jul 01, 2005 at 09:27 UTC
    CGI or CGI::Simple parse query strings into a data structure and provide accessors to said structure.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://471599]
Approved by muntfish
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2019-08-21 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?