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
https://forums.phpfreaks.com/topic/216396-parse-query-for-year-and-price-ranges/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.