Search By Relevance
I am trying to create a search function that will sort results by relevance based upon not only matches but also exclusions. I've got the matching part down good and have tested it out, but it's the exclusions I'm not sure about.
First of all, here is a very condensed version of a sample search form which includes the items needing for match and the exclusion element:
Once the form is submitted, the exclusions are inserted into a PHP variable $exclusions and separated with commas like this:
"year"> <option value=1995 "1995"> </option>
<option value=1996 "1996"> </option>
<option value=1997 "1997"> </option>
"color"> <option value=Blue "blue"> </option>
<option value=Red "red"> </option>
<option value=Yellow "yellow"> </option>
Sizes To Exclude:
"checkbox" name= "sizes" value= "x-small"> <input type=Small
"checkbox" name= "sizes" value= "small"> <input type=Large
"checkbox" name= "sizes" value= "large"> <input type=X-Large "checkbox" name= "sizes" value= "x-large">
Then the database will have the fields of year, color, sizes. In the sizes field, there will be values in the same format as the $exclusions variable: x-small, large, x-large
$exclusions = "x-small, large" ;
My initial search for matches is as follows:
$query = mysql_query("SELECT id, if(year='$year',1,0) + if(color='$color',1,0) as score FROM company ORDER BY score DESC");
My obvious problem is I don't know how to influence this search with the exclusion values. Anyone have any ideas?
Would it be better if you put the sizes as a separate mapping table?
Users Browsing this Thread
There are currently 1 users browsing this thread.
(0 members and 1 guests)
Tags for this Thread