Page 4 of 4 FirstFirst ... 234
Results 31 to 32 of 32
  1. #31
    Join Date
    Apr 2019
    Posts
    297
    Plugin Contributions
    0

    Default Re: Improving search results

    Quote Originally Posted by madmouse View Post
    Ok, I finally sussed this. I now have relevant ranked results using the built in ZenCart search. It's a bit of a hack (modifying a core file) but I don't know how to do it properly using the notifers, etc. But it is a very simple hack. It uses the full text searching capabilities built in to mySQL to rank each result and then it sorts the results by that rank. I've done lots of test searches on my site and it really does work well.

    Step one: enable full text indexing
    Using phpMyAdmin, go to the structure of products_description. On the row for products_name, look at the end of the row and press the T icon (if you hover the tooltip is Fulltext). Now do the same for products_description.

    Step two: edit the code in includes/modules/pages/advanced_search_result/header_php.php

    Around line 219, add the code in red. The commented out line above is nothing to do with me, it was already commented out.

    Code:
    // Notifier Point
    $zco_notifier->notify('NOTIFY_SEARCH_SELECT_STRING');
    
    
    //  $from_str = "from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c";
    
    // FullText Ranking code by Rob - www.funkyraw.com
    $from_str = ",  MATCH(pd.products_name) AGAINST(:keywords) AS rank1, MATCH(pd.products_description) AGAINST(:keywords) AS rank2 ";
    $from_str = $db->bindVars($from_str, ':keywords', stripslashes($_GET['keyword']), 'string');
    //end FullText ranking code
    
    $from_str = "FROM (" . TABLE_PRODUCTS . " p
                 LEFT JOIN " . TABLE_MANUFACTURERS . " m
                 USING(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c )
                 LEFT JOIN " . TABLE_META_TAGS_PRODUCTS_DESCRIPTION . " mtpd
                 ON mtpd.products_id= p2c.products_id
                 AND mtpd.language_id = :languagesID";
    and change the line immediately below what you have added to:
    Code:
    $from_str .= "FROM (" . TABLE_PRODUCTS . " p
    (just added a . before the = sign)



    Now find this line at around line 415
    Code:
    $order_str .= " order by p.products_sort_order, pd.products_name";
    and change it to:
    Code:
    $order_str .= " order by rank1 DESC, rank2 DESC, p.products_sort_order, pd.products_name";
    And you're done. Make sure you test before going live. It will fail with errors if you haven't first enabled the full text indexing. Hope it helps someone. And if anyone wants to use the code to create a proper module then please go ahead.

    Rob
    I just tried to use the following tool to update my database to utf8mb4.

    https://www.zen-cart.com/downloads.php?do=file&id=2367

    I haven't encountered much issues during the upgrade process. However, after I upgraded my live site, I started to receive warnings in the back end when users tried the search function. Luckily I have a recent database backup to recover so I don't lose much data...

    Error looks like the following:

    PHP Fatal error: 1191:Can't find FULLTEXT index matching the column list :: SELECT DISTINCT p.products_image, p.products_model, p.products_quantity , p.products_sort_order, m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_price_sorter, p.products_qty_box_status, p.master_categories_id, p.product_is_call

    Anyway, I did some research later and I found out my database mod used in this thread has been erased or reset during this database upgrade process. After I changed the database again according to this thread (for FULLTEXT), this issue was resolved. No files are changed.

  2. #32
    Join Date
    Apr 2019
    Posts
    297
    Plugin Contributions
    0

    Default Re: Improving search results

    The trick above still works on zc210! But the file has been changed. The following file needs to be changed in the same way.

    \includes\classes\class.search.php

    Instant Search plug-in has not been updated for zc210 yet.

 

 
Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. v154 Improving search box results on main page
    By cahoca in forum General Questions
    Replies: 2
    Last Post: 24 Jan 2016, 04:26 PM
  2. Improving Search Speed
    By jmcdougal in forum General Questions
    Replies: 0
    Last Post: 28 Jan 2011, 06:27 PM
  3. Improving Site Search
    By mutualadvantage in forum General Questions
    Replies: 1
    Last Post: 18 Feb 2008, 10:47 PM
  4. Replies: 8
    Last Post: 5 Dec 2006, 10:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR