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:
Sizes To Exclude:
<input type="checkbox" name="sizes" value="x-small">X-Small
<input type="checkbox" name="sizes" value="small">Small
<input type="checkbox" name="sizes" value="large">Large
<input type="checkbox" name="sizes" value="x-large">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