Arch Stanton
06-09-2004, 03:48 PM
I'm doing an advanced search for an events database and my resulting SQL look like this:
SELECT events.event_id , events.name , events.description
FROM `events` , `event_city` , `event_dates`
WHERE 1 AND (
(
events.name REGEXP '[[:<:]]Art Gallery[[:>:]]'
OR events.description REGEXP '[[:<:]]Art Gallery[[:>:]]'
OR events.locationname REGEXP '[[:<:]]Art Gallery[[:>:]]'
OR events.contactname REGEXP '[[:<:]]Art Gallery[[:>:]]'
) OR (
events.name REGEXP '[[:<:]]Art[[:>:]]'
OR events.description REGEXP '[[:<:]]Art[[:>:]]'
OR events.locationname REGEXP '[[:<:]]Art[[:>:]]'
OR events.contactname REGEXP '[[:<:]]Art[[:>:]]'
) OR (
events.name REGEXP '[[:<:]]Gallery[[:>:]]'
OR events.description REGEXP '[[:<:]]Gallery[[:>:]]'
OR events.locationname REGEXP '[[:<:]]Gallery[[:>:]]'
OR events.contactname REGEXP '[[:<:]]Gallery[[:>:]]'
)
) AND (
events.price1 >= '0.00'
OR events.price2 >= '0.00'
OR events.price3 >= '0.00'
OR events.price4 >= '0.00'
) AND (
events.price1 <= '99.99'
OR events.price2 <= '99.99'
OR events.price3 <= '99.99'
OR events.price4 <= '99.99'
)
AND events.ages = '1'
AND events.category = '8'
AND event_city.region = '1'
AND event_dates.startdate >= '2002-01-1'
AND event_dates.enddate <= '2005-12-31'
AND event_dates.event_id = events.event_id
AND events.locationcity = event_city.city_id
AND events.active = '1';
There are 2 things I'm concerned with.
1) does it make sense to do the first set of regexp with both keywords? I was doing this in hopes that exact matches would be listed first, but it doesn't seem to be working that way.
2) is there a better way of doing this? the server this is on tends to be sluggish, and so does this query, is there any suggestions you might have to optimize this a bit. This is the longest query possible for the results page, if someone doesn't fill out a field in the advanced search, it's not included in the query.
http://dev.thompsonokanagan.com/trellis/events_advanced
SELECT events.event_id , events.name , events.description
FROM `events` , `event_city` , `event_dates`
WHERE 1 AND (
(
events.name REGEXP '[[:<:]]Art Gallery[[:>:]]'
OR events.description REGEXP '[[:<:]]Art Gallery[[:>:]]'
OR events.locationname REGEXP '[[:<:]]Art Gallery[[:>:]]'
OR events.contactname REGEXP '[[:<:]]Art Gallery[[:>:]]'
) OR (
events.name REGEXP '[[:<:]]Art[[:>:]]'
OR events.description REGEXP '[[:<:]]Art[[:>:]]'
OR events.locationname REGEXP '[[:<:]]Art[[:>:]]'
OR events.contactname REGEXP '[[:<:]]Art[[:>:]]'
) OR (
events.name REGEXP '[[:<:]]Gallery[[:>:]]'
OR events.description REGEXP '[[:<:]]Gallery[[:>:]]'
OR events.locationname REGEXP '[[:<:]]Gallery[[:>:]]'
OR events.contactname REGEXP '[[:<:]]Gallery[[:>:]]'
)
) AND (
events.price1 >= '0.00'
OR events.price2 >= '0.00'
OR events.price3 >= '0.00'
OR events.price4 >= '0.00'
) AND (
events.price1 <= '99.99'
OR events.price2 <= '99.99'
OR events.price3 <= '99.99'
OR events.price4 <= '99.99'
)
AND events.ages = '1'
AND events.category = '8'
AND event_city.region = '1'
AND event_dates.startdate >= '2002-01-1'
AND event_dates.enddate <= '2005-12-31'
AND event_dates.event_id = events.event_id
AND events.locationcity = event_city.city_id
AND events.active = '1';
There are 2 things I'm concerned with.
1) does it make sense to do the first set of regexp with both keywords? I was doing this in hopes that exact matches would be listed first, but it doesn't seem to be working that way.
2) is there a better way of doing this? the server this is on tends to be sluggish, and so does this query, is there any suggestions you might have to optimize this a bit. This is the longest query possible for the results page, if someone doesn't fill out a field in the advanced search, it's not included in the query.
http://dev.thompsonokanagan.com/trellis/events_advanced