Jump to content

Parse query for year and price ranges


Pawn

Recommended Posts

The goal is to interpret user search submissions like the following in an intelligent way.

 

"oscar wilde 1903-1910 £4-10"

 

Ideally after pattern matching such a query the script would have variables like $price_min, $price_max, $year_min, $year_max and $query_clean to work with. With these we could construct really useful SQL.

 

All I've got for my efforts over the last couple of hours has been a headache. Can anyone help?

 

Pseudo-code:

 

$q = $_GET['query']
$price_range_expr = some_regex
$year_range_expr = some_more_regex

if $price_range = match all $price_range_expr in $q
    $q = strip $price_range from $q
    $price_min = $price_range[1]
    $price_max = $price_range[2]
endif
if $year_range = match all $year_range_expr in $q
    $q = strip $year_range from $q
    $price_min = $year_range[1]
    $price_max = $year_range[2]
endif

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.