mac007 Posted March 22, 2009 Share Posted March 22, 2009 Hello, all: I am trying to setup this "search-box" where I want people to type in specific item descriptions they are looking for, and seems to be working more or less ok, but I have this problem: If people type "red pontiac" , it will only retrieve records matching exactly "red pontiac"... (not other ones that might be entered as "pontiac car red", so in other words, i need it to be more inclusive of words regardless of how they are entered in DB. Kind of like one would expect when doing like a google-search... Here is the code I have... I thought maybe there was a way by using a different type of wildcard? not CONCAT function? <CODE> $wordSearch_worksRS = "-1"; if (isset($_GET['wordSearch'])) { $wordSearch_worksRS = $_GET['wordSearch']; } mysql_select_db($database_artStore, $artStore); $query_worksRS = sprintf("SELECT * FROM works WHERE Description OR Description2 LIKE CONCAT('%%%%', %s, '%%%%') ORDER BY ProductID DESC", GetSQLValueString($wordSearch_worksRS, "text")); $query_limit_worksRS = sprintf("%s LIMIT %d, %d", $query_worksRS, $startRow_worksRS, $maxRows_worksRS); $worksRS = mysql_query($query_limit_worksRS, $artStore) or die(mysql_error()); $row_worksRS = mysql_fetch_assoc($worksRS); </CODE> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/150518-problem-with-search-query-box-not-filtering-words-regardless-of-order/ Share on other sites More sharing options...
npsari Posted March 22, 2009 Share Posted March 22, 2009 I never used CONCAT in my site What i used to do is... I Explode the phrase first, the search for each words separately, then echo all results I ended up with many results which is annoying I then done another complicated story which is about 100 lines of code It works ok, but doesnt feel right Link to comment https://forums.phpfreaks.com/topic/150518-problem-with-search-query-box-not-filtering-words-regardless-of-order/#findComment-790666 Share on other sites More sharing options...
mac007 Posted March 22, 2009 Author Share Posted March 22, 2009 Thanks npsari: I ended up using this this: which kind of works much better... it does a wider inclusion of terms, and even though it might give a bit too wide of a range, it does place in order of importance, which is fien with me... Anyways, this is what I did: $query_worksRS = "SELECT * FROM works WHERE MATCH(Description) AGAINST ('$variable')"; But in this case, you have to make sure any table fields you include in the match field are indexed as FULL TEXT in your DB, otherwise it wont work... but as I said, did enough for my needs.. Link to comment https://forums.phpfreaks.com/topic/150518-problem-with-search-query-box-not-filtering-words-regardless-of-order/#findComment-790694 Share on other sites More sharing options...
npsari Posted March 22, 2009 Share Posted March 22, 2009 wow, can i ask you something about this little code you showed me $mysql_query = "SELECT * FROM works WHERE MATCH(Description) AGAINST ('$variable')"; Lets say a user is searching for: very cheap car And there is a car which has the following keywords good cheap new reliable car very I want the Query to find as much keywords possible, rather than looking for the exact match So, if the row Description has loads of keywords, the query will see the most matching keywords in it Do you know how can this be done, because at the moment i am doing something messed up Link to comment https://forums.phpfreaks.com/topic/150518-problem-with-search-query-box-not-filtering-words-regardless-of-order/#findComment-790820 Share on other sites More sharing options...
redarrow Posted March 22, 2009 Share Posted March 22, 2009 look at WHERE $somthink LIKE '%$somethink%' makes sense you answer your own question Link to comment https://forums.phpfreaks.com/topic/150518-problem-with-search-query-box-not-filtering-words-regardless-of-order/#findComment-790852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.