Setting database to exact phrase as default

Discussion in 'Databases' started by carl gale, Nov 29, 2009.

  1. #1
    Could anyone point me in the right direction here please, also excuse the lack of technical terms in the description as I am not a database expert by far.

    I have installed a script on my website to work as a price comparison type script; ie you enter a product and it matches all the items with that in the title. This is working fine but I am having a problem with the search searching on ALL the words not the phrase. So, for example, I enter 'black dress' into the search and the first few results will be black dresses but then it will be everything else with either black or dress in the title which will be a lot of irrelevant items!

    If I search for "black dress" it returns the results perfectly ie just black dresses but I do not want my users to have to enter the " signs as they are non IT people.

    Is there a way, therefore I can convert the database from the current search to exact phrase searching?

    The bit of the script which is about the search is posted below

    search
    case "search":
    if ($_GET['ps'] == NULL) { header("Location: ".$installDir['value']); }
    // get keywords
    $pieces = explode(" ", strip_tags($_GET['ps']));
    $kp = count($pieces);
    // reset pieces
    $pluspieces = '';
    for ($pi=0;$pi<$kp;$pi++) {
    $pluspieces .= $pieces[$pi].' ';
    }
    $pluspieces = rtrim($pluspieces, " ");
    // output search results
    $extracondition = '';
    if (isset($_GET['pscat'])){
    $extracondition .= " AND prodCategory = ".quote_smart($_GET['pscat'])."";
    }
    if (isset($_GET['pslow'])){
    $extracondition .= " AND (prodPrice BETWEEN ".quote_smart($_GET['pslow'])." AND ".quote_smart($_GET['pshigh']).")";
    }
    if ($indcount == 0) {
    $query_product = "SELECT *, ( (1.3 * (MATCH(prodName) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) + (0.6 * (MATCH(prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) ) AS relevance FROM affiliSt_products1 WHERE ( MATCH(prodName,prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE) ) $extracondition HAVING relevance > 0 $sortby";
    } else {
    $query_product = "SELECT *, MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") AS relevance FROM affiliSt_products1 WHERE MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") $extracondition HAVING relevance > 0 $sortby";
    }
    break;


    Many thanks for any advice offered.

    Carl.
     
    carl gale, Nov 29, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Use Phrase match..

    A sample is below, please take note of (") around 'black dress' :)

    
    SELECT * FROM affiliSt_products1 WHERE MATCH(prodName) against('"black dress"')
    
    Code (markup):
     
    mastermunj, Nov 30, 2009 IP