Results 1 to 2 of 2

Thread: Search By Relevance

  1. #1
    Join Date
    Apr 2009

    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:

    HTML Code:
    Select Year:
    <select name="year">
        <option value="1995">1995</option>
        <option value="1996">1996</option>
        <option value="1997">1997</option>
    Select Color:
    <select name="color">
        <option value="blue">Blue</option>
        <option value="red">Red</option>
        <option value="yellow">Yellow</option>
    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
    Once the form is submitted, the exclusions are inserted into a PHP variable $exclusions and separated with commas like this:
    PHP Code:
    $exclusions "x-small, 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

    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?

  2. #2
    Join Date
    Oct 2009
    Would it be better if you put the sizes as a separate mapping table?
    Good Luck

    Santos Systems

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center