Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
Iv rewritten the showroom search on vagweb so it now search on image tags. These are seperated in the DB by commas or spaces.
This works fine using the LIKE % $query % statement. So for example if my image has the tags silver, skoda, fabia, vrs then searching for silver skoda, or fabia vrs brings it up fine. But if i search for two tags that arent next to each other in line, ie silver vrs, then it doesnt find it.
Is there any query i can use that brings up any instances of the words anywhere in the line?
|
James
Member
Registered: 1st Jun 02
Location: Surrey
User status: Offline
|
A dirty way of doing it would be to split the search string at code level and then pass in say 6 different parameters to the query, you would have to guess how many words the longest search would be though.
|
AndyKent
Member
Registered: 3rd Sep 05
User status: Offline
|
You can count the number of words entered (received by the search page) and build the query around the number of arguments, not sure how accurate the search results would be though....
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
hmmz
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
Nothing wrong with splitting the queries and a load of OR WHERE, apart from perhaps a bit of speed.
FULLTEXT is also an option.
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
quote: Originally posted by Ian
Nothing wrong with splitting the queries and a load of OR WHERE, apart from perhaps a bit of speed.
FULLTEXT is also an option.
Replaces spaces in the searchphrase with %'s?
FULLTEXT is a bit fiddley is it not? Especially when he'd have to change the INI settings to get past the min 4chars rule. Definately a slicker option though
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
Replacing space with % wouldn't fix the ordering issue of each of the search queries.
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
came up with this
code:
$words = split(" ", $s);
$count = count(explode(" ", $s));
$c='0';
while ($c < $count)
{
$or = $or . "OR " . $where . " LIKE '%" . $words[$c] . "%' ";
$c++;
}
$sql = "SELECT p.pic_id, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_username, p.pic_time, p.pic_cat_id, p.pic_approval, p.pic_file_name, p.pic_thumbnail, c.cat_id, c.cat_title, c.cat_user_id
FROM " . ALBUM_TABLE . ' AS p,' . ALBUM_CAT_TABLE . " AS c
WHERE p.pic_approval = 1
AND " . $where . " LIKE '%" . $s . "%'
$or
AND p.pic_cat_id = c.cat_id
AND c.cat_view_level <> '3'
ORDER BY p.pic_time DESC";
it works, but can anyone see anything thats likely to cause things to grind to a halt there with a large query?
|
James
Member
Registered: 1st Jun 02
Location: Surrey
User status: Offline
|
That's pretty much what I was getting at.
How big is the query that's breaking it?
Also, what is $where?
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
$where is just something that changes when you select the search query type, at the moment the options are, Username, Image Title, and Image Tags
|
James
Member
Registered: 1st Jun 02
Location: Surrey
User status: Offline
|
Is there a limit on the length of a PHP string? I'm not hot on PHP. C# FTW
Can you trace out the SQL thats crashing and then run it directly in MySQL to see if its a DB or Code issue?
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
quote: Originally posted by James
Is there a limit on the length of a PHP string? I'm not hot on PHP. C# FTW
Can you trace out the SQL thats crashing and then run it directly in MySQL to see if its a DB or Code issue?
its not crashing, it works fine i just wondered if any eagle eyed bodies could forsee that becoming slow with more requests
|
James
Member
Registered: 1st Jun 02
Location: Surrey
User status: Offline
|
Not as long as your as DB is designed well. Realistically no-one is going to input a huge string anyway apart from muppetsport
P.s. Thanks for a snippet of your DB structure for SQL injection xxx
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
no worries, shame you dont know my table names
iv got another problem, now i have that list of OR's being created its ignoring my ANDS
any ideas?
|
James
Member
Registered: 1st Jun 02
Location: Surrey
User status: Offline
|
Put all the ORs in brackets and use an AND for the group. Like this:
Criteria1 = 1 AND Criteria2 = 2 AND (Criteria3 = 3 OR Criteria4 = 4)
[Edited on 22-10-2007 by James]
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
yeah just figured that out lolz
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
I would imagine it is slow just simply because of all the ORs. There's no real way around that as you can't index your way out of a substring.
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
nah its not slow at the moment, but iv only tried a few simply queries, just wondering if you could see it being slow in the future?
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
More data and more words in your query, yes.
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
best way to avoid> limit the query length?
|
AndyKent
Member
Registered: 3rd Sep 05
User status: Offline
|
I'd just limit it to, say, 5 words. But don't tell the users that it only searches for 5 words......just drop any extra words from the search.
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
yak theres still issues.
my problem now is if i search for
green seat arosa
it will pull up everything with green | seat | arosa in the tags.
so it pulls up all the ibizas, and leons etc, i want it to only get the green arosas
fuck
[Edited on 23-10-2007 by Steve]
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
i need it to get all the queries in the search string, but that can be anywhere in the string
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
no worries its sorted
|
James
Member
Registered: 1st Jun 02
Location: Surrey
User status: Offline
|
Your ORs needed to be ANDs?
|