Jump to content

problem with "search" query box... not filtering words regardless of order


mac007

Recommended Posts

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!

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

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

 

 

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  :o

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.