Jump to content

Pleas help fix SEARCH engine


Tomasz

Recommended Posts

Could anyone help us optimise our shop SEARCH engine please.

Basically typing key word in the SEARCH box brings a lot of irrelevant results,

For example, searching for “audi TT cruise control “ will bring a lot for different products listed for audi, but the one I’m interested in, named “audi tt mk1 cruise control kit “ will be somewhere at the bottom.

We use "AJAX Configurable Search Box"  plug in at the moment, pop up suggestion are a bit more accurate, but once you hit ENTER it displays irrelevant results...

Our shop her http://vag-shop.co.uk/

Link to comment
Share on other sites

Since that old thread is so long, here's my 6.2.0 version of the catalogue.class.php file that uses the code Bsmither provided way back when:

    // ORIGINAL B4 BSMITHER SEARCH CHANGE TO LIKE INSTEAD OF FULLTEXT public function searchCatalogue($search_data = null, $page = 1, $per_page = 10, $search_mode = 'fulltext') {
 public function searchCatalogue($search_data = null, $page = 1, $per_page = 10, $search_mode = 'rlike') {

        $per_page = (!is_numeric($per_page) || $per_page < 1) ? 10 : $per_page;

        $original_search_data = $search_data;

        /*    Allow plugins to add to conditions and joins or change the search_data
            Where conditions may be added to the $where variable and must be self contained (e.g. no AND prefix or suffix) since they will be ANDed together below
            $where[] = "I.price > 100";
            Joins may be added to the $joins variable - keep in mind the need for unique table aliases as appropriate
            $joins[] = "`plugin_myPlugin` as P ON P.`product_id`=I.`product_id` AND P.`my_field`='some_value'";
            The only guaranteed table alias is I for CubeCart_inventory
            G for CubeCart_pricing_group
            CI for CubeCart_category_index
            C for CubeCart_category
        */
        $where = array();
        $joins = array();
        foreach ($GLOBALS['hooks']->load('class.catalogue.pre_search') as $hook) include $hook;

        $sale_mode = $GLOBALS['config']->get('config', 'catalogue_sale_mode');

        if ($sale_mode == 2) {
            $sale_percentage = $GLOBALS['config']->get('config', 'catalogue_sale_percentage');
        }
        $user = (array)$GLOBALS['user']->get();
        $group_id = 'WHERE group_id = 0';
        if (isset($user['customer_id']) && ($memberships = $GLOBALS['db']->select('CubeCart_customer_membership', array('group_id'), array('customer_id' => (int)$user['customer_id']))) !== false) {
            $group_id = 'WHERE ';
            foreach ($memberships as $membership) {
                $group_id .= 'group_id = '.$membership['group_id'].' OR ';
            }
            $group_id = substr($group_id, 0, -4);
        }

        if (strtolower($page) != 'all') {
            $page = (is_numeric($page)) ? $page : 1;
            $limit = sprintf('LIMIT %d OFFSET %d', (int)$per_page, $per_page*($page-1));
        } else {
            $limit = 'LIMIT 100';
        }

        // Presence of a join is similar to presence of a search keyword
        if (!empty($joins) || is_array($search_data)) {
            if (!empty($search_data['priceVary'])) {
                // Allow for a 5% variance in prices
                if (!empty($search_data['priceMin']) && is_numeric($search_data['priceMin'])) {
                    $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMin'])/1.05, 3);
                    if ($sale_mode == 1) {
                        $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price) >= '.$price.', IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price) >= '.$price.')';
                    } else if ($sale_mode == 2) {
                            $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) >= '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) >= '.$price.')';
                        } else {
                        $where[] = 'IF (G.price IS NULL, I.price >= '.$price.', G.price >= '.$price.')';
                    }
                }

                if (!empty($search_data['priceMax']) && is_numeric($search_data['priceMax'])) {
                    $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMax'])*1.05, 3);
                    if ($sale_mode == 1) {
                        $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price) <= '.$price.', IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price) <= '.$price.')';
                    } else if ($sale_mode == 2) {
                            $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) <= '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) <= '.$price.')';
                        } else {
                        $where[] = 'IF (G.price IS NULL, I.price <= '.$price.', G.price <= '.$price.')';
                    }
                }
            } else {
                ## Basic price searching
                if (!empty($search_data['priceMin']) && is_numeric($search_data['priceMin']) &&
                    !empty($search_data['priceMax']) && is_numeric($search_data['priceMax']) &&
                    $search_data['priceMax'] == $search_data['priceMin']) {
                    $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMin']), 3);
                    if ($sale_mode == 1) {
                        $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price) = '.$price.', IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price) = '.$price.')';
                    } else if ($sale_mode == 2) {
                            $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) = '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) = '.$price.')';
                        } else {
                        $where[] = 'IF (G.price IS NULL, I.price = '.$price.', G.price = '.$price.')';
                    }
                } else {
                    if (!empty($search_data['priceMin']) && is_numeric($search_data['priceMin'])) {
                        $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMin']), 3);
                        if ($sale_mode == 1) {
                            $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price = 0, I.price, I.sale_price) >= '.$price.', IF (G.sale_price = 0, G.price, G.sale_price) >= '.$price.')';
                        } else if ($sale_mode == 2) {
                                $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) >= '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) >= '.$price.')';
                            } else {
                            $where[] = 'IF (G.price IS NULL, I.price >= '.$price.', G.price >= '.$price.')';
                        }
                    }
                    if (!empty($search_data['priceMax']) && is_numeric($search_data['priceMax'])) {
                        $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMax']), 3);
                        if ($sale_mode == 1) {
                            $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price) <= '.$price.', IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price) <= '.$price.')';
                        } else if ($sale_mode == 2) {
                                $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) <= '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) <= '.$price.')';
                            } else {
                            $where[] = 'IF (G.price IS NULL, I.price <= '.$price.', G.price <= '.$price.')';
                        }
                    }
                }
            }
            // Manufacturer
            if (isset($search_data['manufacturer']) && is_array($search_data['manufacturer']) && count($search_data['manufacturer'])>0) {
                $where[] = 'I.manufacturer IN ('.implode(',', $this->get_int_array($search_data['manufacturer'])).')';
                //    $where[] = 'I.manufacturer IN ('.implode(',', '\''.$search_data['manufacturer']).'\')';
            }

            $order = array();
            
            if (isset($_GET['sort']) && is_array($_GET['sort'])) {
                foreach ($_GET['sort'] as $field => $direction) {
                    if(strtolower($field) == 'relevance' && $search_mode !== 'fulltext') {
                        break;    
                    }
                    $order['field'] = $field;
                    if ($field == 'price') {
                        if ($sale_mode == 1) {
                            $order['field'] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price), IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price))';
                        } else {
                            $order['field'] = 'IFNULL (G.price, I.price)';
                        }
                    }
                    $order['sort'] = (strtolower($direction) == 'asc') ? 'ASC' : 'DESC';
                    break;
                }
            } elseif ($search_mode == 'fulltext') {
                $order['field'] = 'Relevance';
                $order['sort'] = 'DESC';
            }
            // Use store settings for sort order if none designated
            if (empty($order)) {
                $order['field'] = $GLOBALS['config']->get('config', 'product_sort_column');
                $order['sort'] = $GLOBALS['config']->get('config', 'product_sort_direction');
                if (empty($order['field']) || empty($order['sort'])) {
                    unset($order); // store settings were somehow invalid
                }
            }
            if (empty($search_data['keywords']) && $order['field'] == 'Relevance') {
                if ($sale_mode == 1) {
                    $order['field'] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price), IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price))';
                } else {
                    $order['field'] = 'IFNULL (G.price, I.price)';
                }
            }
            if (is_array($order)) {
                $order_string = 'ORDER BY `'.$order['field'].'` '.$order['sort'];
            }

            if (isset($search_data['featured'])) {
                $where[] = "I.featured = '1'";
            }
            // Only look for items that are in stock
            if (isset($search_data['inStock']) || $GLOBALS['config']->get('config', 'hide_out_of_stock')) {
                $where[] = "((I.use_stock_level = '0') OR (I.use_stock_level = '1' AND I.stock_level > 0))";
            }

            $whereString = (isset($where) && is_array($where)) ? implode(' AND ', $where) : '';
            if (!empty($whereString)) $whereString = ' AND '.$whereString;

            $joinString = (isset($joins) && is_array($joins)) ? implode(' JOIN ', $joins) : '';
            if (!empty($joinString)) $joinString = ' JOIN '.$joinString;

            $indexes = $GLOBALS['db']->getFulltextIndex('CubeCart_inventory', 'I');

            if (!empty($joins) || isset($search_data['keywords']) && is_array($indexes) && !empty($search_data['keywords'])) {

            // STOCK    if($search_mode == 'fulltext') {
                    $max_word_len = $GLOBALS['db']->getSearchWordLen();
                    $words = explode(' ', $search_data['keywords']);
                    if (is_array($words)) {
                        $search_str_len = 0;
                        foreach ($words as $word) {
                            $search_str_len = ($search_str_len < strlen($word)) ? strlen($word) : $search_str_len;
                        }
                    } else {
                        $search_str_len = strlen($search_data['keywords']);
            // STOCK        }  
                }

                if ($search_mode == 'fulltext') {

                    if($search_str_len < $max_word_len) {
                        return $this->searchCatalogue($original_search_data, 1, $per_page, 'rlike');    
                    }

                    switch (true) {
                    case (preg_match('#[\+\-\>\<][\w]+#iu', $search_data['keywords'])):
                        ## Switch to bolean mode
                        $mode = 'IN BOOLEAN MODE';
                        break;
                    default:
                        $search_data['keywords'] = str_replace(' ', '*) +(*', $search_data['keywords']);
                        $search_data['keywords'] .= '*)';
                        $search_data['keywords'] = '+(*'.$search_data['keywords'];
                        $mode = 'IN BOOLEAN MODE';
                        break;
                    }
                    $words = preg_replace('/[^\p{Greek}a-zA-Z0-9\s]+/u', '', $search_data['keywords']);
                    $words = $GLOBALS['db']->sqlSafe($words);
                    // Score matching string
                    $match = sprintf("MATCH (%s) AGAINST('%s' %s)", implode(',', $indexes), $words, $mode);
                    $match_val = '0.5';

                    $query = sprintf("SELECT I.*, %2\$s AS Relevance FROM %1\$sCubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM %1\$sCubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id $joinString WHERE I.product_id IN (SELECT product_id FROM `%1\$sCubeCart_category_index` as CI INNER JOIN %1\$sCubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 AND (%2\$s) >= %4\$s %3\$s %5\$s %6\$s", $GLOBALS['config']->get('config', 'dbprefix'), $match, $whereString, $match_val, $order_string, $limit);
                    
                    if ($search = $GLOBALS['db']->query($query)) {
                        $q2 = sprintf("SELECT COUNT(I.product_id) as count, %2\$s AS Relevance FROM %1\$sCubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM %1\$sCubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id $joinString WHERE I.product_id IN (SELECT product_id FROM `%1\$sCubeCart_category_index` as CI INNER JOIN %1\$sCubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 AND (%2\$s) >= %4\$s %3\$s GROUP BY I.product_id %5\$s", $GLOBALS['config']->get('config', 'dbprefix'), $match, $whereString, $match_val, $order_string);
                        $count = $GLOBALS['db']->query($q2, false, 0);
                        $this->_category_count  = (int)count($count);
                        $this->_category_products = $search;
                        $this->_sort_by_relevance = true;
                        if(count($this->_category_products)==1 && ctype_digit($this->_category_products[0]['product_id'])) {
                            $GLOBALS['gui']->setNotify(sprintf($GLOBALS['language']->catalogue['notify_product_search_one'], $_REQUEST['search']['keywords']));
                            httpredir('?_a=product&product_id='.$this->_category_products[0]['product_id']);
                        }
                        return true;
                    } elseif ($search_mode == 'fulltext') {
                        return $this->searchCatalogue($original_search_data, 1, $per_page, 'rlike');
                    }
                } else {
/*    STOCK  B4 BSMITHER SEARCH
                    $search_mode = in_array($search_mode, array('rlike','like')) ? $search_mode : 'rlike';
                    $this->_sort_by_relevance = false;
                    $like = '';
                    if (!empty($search_data['keywords'])) {
                        $searchwords = preg_split( '/[\s,]+/', $GLOBALS['db']->sqlSafe($search_data['keywords']));
                        foreach ($searchwords as $word) {
                            if(empty($word) && !is_numeric($word)) continue;
                            $searchArray[] = $word;
                        }

                        $noKeys = count($searchArray);
                        $regexp = $regexp_desc = '';
                        
                        $search_mode = in_array($search_mode, array('rlike','like')) ? $search_mode : 'rlike';

                        if($search_mode == 'rlike') {
                            $like_keyword = "RLIKE";
                            $like_prefix = '[[:<:]]';
                            $like_postfix = '[[:>:]].*';
                        } else {
                            $like_keyword = "LIKE";
                            $like_prefix = '%';
                            $like_postfix = '%';
                        }
                        for ($i=0; $i<$noKeys; ++$i) {
                            $ucSearchTerm = strtoupper($searchArray[$i]);
                            if (($ucSearchTerm != 'AND') && ($ucSearchTerm != 'OR')) {
                                $regexp .= $like_prefix.$searchArray[$i].$like_postfix;
                                $regexp_desc .= $like_prefix.htmlentities(html_entity_decode($searchArray[$i],ENT_COMPAT,'UTF-8'),ENT_QUOTES,'UTF-8',false).$like_postfix;
                            }
                        }
                        if($search_mode == 'rlike') {
                            $regexp = substr($regexp, 0, strlen($regexp)-2);
                            $regexp_desc = substr($regexp_desc, 0, strlen($regexp_desc)-2);
                        }
                        $like = " AND (I.name ".$like_keyword." '".$regexp."' OR I.description ".$like_keyword." '".$regexp_desc."' OR I.product_code ".$like_keyword." '".$regexp."')";
                    }

                    $q2 = "SELECT I.* FROM ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id $joinString WHERE I.product_id IN (SELECT product_id FROM `".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_category_index` as CI INNER JOIN ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 ".$whereString.$like;
                    $query = $q2.' '.$order_string.' '.$limit;
                    $search = $GLOBALS['db']->query($query);
                    if (count($search)>0) {
                        $count = $GLOBALS['db']->query($q2, false, 0);
                        $this->_category_count  = (int)count($count);
                        $this->_category_products = $search;
                        if(count($this->_category_products)==1 && ctype_digit($this->_category_products[0]['product_id'])) {
                            $GLOBALS['gui']->setNotify(sprintf($GLOBALS['language']->catalogue['notify_product_search_one'], $_REQUEST['search']['keywords']));
                            httpredir('?_a=product&product_id='.$this->_category_products[0]['product_id']);
                        }
                        return true;
                    } elseif($search_mode=="rlike") {
                        return $this->searchCatalogue($original_search_data, 1, $per_page, 'like');
                    }
                }
            }
        } else {
  END OF STOCK SEARCH */
                    /* BSMITHER SEARCH */
                    $this->_sort_by_relevance = false;
                    $rlike = '';
                    if (!empty($search_data['keywords'])) {
                                            $searchwords = preg_split( '/[\s,]+/', $GLOBALS['db']->sqlSafe($search_data['keywords']));
                        foreach ($searchwords as $word) {
                    if(empty($word) && !is_numeric($word)) continue;
                            if ((strtoupper($word) != 'AND') && (strtoupper($word) != 'OR')) $searchArray[] = $word;
                        }

                        $regexp = '';
                        $columnsToSearch = array(
                          'I.name',
                            'I.description',
                            'I.product_code',
                    'I.seo_meta_keywords',
                        );

                        foreach($columnsToSearch as $col) {
                            for ($i=0, $noKeys=count($searchArray); $i<$noKeys; ++$i) {
                                $regexp[$col][] = $col."  RLIKE '[[:<:]]".$searchArray[$i]."[[:>:]]'";
                            }
                            $regexp[$col] = '(' . implode(' AND ', $regexp[$col]) . ')';
                        }
                        $rlike = " AND (" . implode(' OR ', $regexp) . ")";
                    }
                    $q2 = "SELECT I.* FROM ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id $joinString WHERE I.product_id IN (SELECT product_id FROM `".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_category_index` as CI INNER JOIN ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 ".$whereString.$rlike;
                    $query = $q2.' '.$order_string.' '.$limit;
                    if (($search = $GLOBALS['db']->query($query)) !== false) {
                        $count = $GLOBALS['db']->query($q2, false, 0);
                        $this->_category_count  = (int)count($count);
                        $this->_category_products = $search;
                        return true;
                    }
                }
            }
        } else {
    /*     END OF BSMITHER SEARCH */
            if (is_numeric($search_data)) {

 

Link to comment
Share on other sites

Not working  - its give white site.

Search engin from site working wrong.

When I in admin panel, and use "Search Products" its working.

I put "Audi TT", adn its working better than the www site search form.

Where i found code who generate "Search Products" in admin site?

 

 

Link to comment
Share on other sites

There are two separate algorithms to search the Inventory: a complicated yet versatile method for the storefront customers, and a simpler specific method for the backend administrator.

For the storefront, there are three attempts, made in the following order: Fulltext Relevance, RLIKE, then LIKE. I do not fully understand Relevance. RLIKE uses the words entered as whole, individual words. LIKE uses the whole individual words as part of the entire column's value. For Fulltext, words fewer than three characters are discarded. Words are mangled by having anything not a letter or number removed. There is code that supposedly respects the AND keyword (the default search is OR of everything), and code that supposedly respects a prepended + or - to any word (must contain, must not contain). The inventory fields searched are the OR'd summation of the product name, product code, and product description. These fields comprise a FULLTEXT index for faster searching.

Also, additional conditions exist and additional search constraints is offered: any item to be returned must be in-stock (or stock not used), be enabled, any category associated with the item be enabled, and match any price ranges, manufacturers, conditions, etc.

For the backend, the entire phrase is applied as the argument for LIKE - finding the complete phrase exactly as entered contained within the entire value for only product name and product code.

Another obstacle to overcome is that there are several search syntaxes. I am not familiar with the science of "search" to guess which syntax CubeCart uses, if any. (It's not Google's.)

As an affront against the customer, the Advanced Search page does not include any instruction on how to compose a 'tight' search query.

The storefront code is found in /classes/catalogue.class.php, function searchCatalogue(), which is also used to find items on sale, and items that are members of a specific category.

The code used by the backend (it's an AJAX call, so pretty much anyone can use it) is at /classes/ajax.class.php, static function search().

Link to comment
Share on other sites

  • 1 year later...

Coming back for more help with my VERY custom Search. Most recent changes involved using my own search_keywords, but something has changed in the last upgrade or so. Now I'm getting results for PIECES of words - something I do not want. Finding plurals is kind of nice, but I have already added plurals in my own search_keywords database - so I don't need that.

Problem: Searching for UGA finds titles with Sugar Loaf, Sugarplum, and Sugarbunnies in them.

I would have preferred it come back as not found.

Here's my catalog.class.php search portion:

    /**
     * Search product catalog
     *
     * @param string $search_data
     * @param int $page
     * @param int $per_page
     * @param string $search_mode
     * @return bool
     */
	// ORIGINAL B4 BSMITHER SEARCH CHANGE TO LIKE INSTEAD OF FULLTEXT public function searchCatalogue($search_data = null, $page = 1, $per_page = 10, $search_mode = 'fulltext') {
 public function searchCatalogue($search_data = null, $page = 1, $per_page = 10, $search_mode = 'rlike')
    {
        $per_page = (!is_numeric($per_page) || $per_page < 1) ? 10 : $per_page;

        $original_search_data = $search_data;

        /*	Allow plugins to add to conditions and joins or change the search_data
            Where conditions may be added to the $where variable and must be self contained (e.g. no AND prefix or suffix) since they will be ANDed together below
            $where[] = "I.price > 100";
            Joins may be added to the $joins variable - keep in mind the need for unique table aliases as appropriate
            $joins[] = "`plugin_myPlugin` as P ON P.`product_id`=I.`product_id` AND P.`my_field`='some_value'";
            The only guaranteed table alias is I for CubeCart_inventory
            G for CubeCart_pricing_group
            CI for CubeCart_category_index
            C for CubeCart_category
        */
        $where = array();
        $joins = array();
        foreach ($GLOBALS['hooks']->load('class.catalogue.pre_search') as $hook) {
            include $hook;
        }

        $sale_mode = $GLOBALS['config']->get('config', 'catalogue_sale_mode');

        if ($sale_mode == 2) {
            $sale_percentage = $GLOBALS['config']->get('config', 'catalogue_sale_percentage');
        }
        $user = (array)$GLOBALS['user']->get();
        $group_id = 'WHERE group_id = 0';
        if (($memberships = $GLOBALS['user']->getMemberships()) !== false) {
            $group_id = 'WHERE ';
            foreach ($memberships as $membership) {
                $group_id .= 'group_id = '.$membership['group_id'].' OR ';
            }
            $group_id = substr($group_id, 0, -4);
        }

        if (strtolower($page) != 'all') {
            $page = (is_numeric($page)) ? $page : 1;
            $limit = sprintf('LIMIT %d OFFSET %d', (int)$per_page, $per_page*($page-1));
        } else {
            $limit = 'LIMIT 100';
        }

        // Presence of a join is similar to presence of a search keyword
        if (!empty($joins) || is_array($search_data)) {
            if (!empty($search_data['priceVary'])) {
                // Allow for a 5% variance in prices
                if (!empty($search_data['priceMin']) && is_numeric($search_data['priceMin'])) {
                    $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMin'])/1.05, 3);
                    if ($sale_mode == 1) {
                        $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price) >= '.$price.', IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price) >= '.$price.')';
                    } elseif ($sale_mode == 2) {
                        $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) >= '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) >= '.$price.')';
                    } else {
                        $where[] = 'IF (G.price IS NULL, I.price >= '.$price.', G.price >= '.$price.')';
                    }
                }

                if (!empty($search_data['priceMax']) && is_numeric($search_data['priceMax'])) {
                    $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMax'])*1.05, 3);
                    if ($sale_mode == 1) {
                        $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price) <= '.$price.', IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price) <= '.$price.')';
                    } elseif ($sale_mode == 2) {
                        $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) <= '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) <= '.$price.')';
                    } else {
                        $where[] = 'IF (G.price IS NULL, I.price <= '.$price.', G.price <= '.$price.')';
                    }
                }
            } else {
                ## Basic price searching
                if (!empty($search_data['priceMin']) && is_numeric($search_data['priceMin']) &&
                    !empty($search_data['priceMax']) && is_numeric($search_data['priceMax']) &&
                    $search_data['priceMax'] == $search_data['priceMin']) {
                    $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMin']), 3);
                    if ($sale_mode == 1) {
                        $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price) = '.$price.', IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price) = '.$price.')';
                    } elseif ($sale_mode == 2) {
                        $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) = '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) = '.$price.')';
                    } else {
                        $where[] = 'IF (G.price IS NULL, I.price = '.$price.', G.price = '.$price.')';
                    }
                } else {
                    if (!empty($search_data['priceMin']) && is_numeric($search_data['priceMin'])) {
                        $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMin']), 3);
                        if ($sale_mode == 1) {
                            $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price = 0, I.price, I.sale_price) >= '.$price.', IF (G.sale_price = 0, G.price, G.sale_price) >= '.$price.')';
                        } elseif ($sale_mode == 2) {
                            $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) >= '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) >= '.$price.')';
                        } else {
                            $where[] = 'IF (G.price IS NULL, I.price >= '.$price.', G.price >= '.$price.')';
                        }
                    }
                    if (!empty($search_data['priceMax']) && is_numeric($search_data['priceMax'])) {
                        $price = round($GLOBALS['tax']->priceConvertFX($search_data['priceMax']), 3);
                        if ($sale_mode == 1) {
                            $where[] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price) <= '.$price.', IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price) <= '.$price.')';
                        } elseif ($sale_mode == 2) {
                            $where[] = 'IF (G.price IS NULL, (I.price - ((I.price / 100) * '.$sale_percentage.')) <= '.$price.', (G.price - ((G.price / 100) * '.$sale_percentage.')) <= '.$price.')';
                        } else {
                            $where[] = 'IF (G.price IS NULL, I.price <= '.$price.', G.price <= '.$price.')';
                        }
                    }
                }
            }
            // Manufacturer
            if (isset($search_data['manufacturer']) && is_array($search_data['manufacturer']) && count($search_data['manufacturer'])>0) {
                $where[] = 'I.manufacturer IN ('.implode(',', $this->get_int_array($search_data['manufacturer'])).')';
                //    $where[] = 'I.manufacturer IN ('.implode(',', '\''.$search_data['manufacturer']).'\')';
            }

            $order = array();
            
            if (isset($_GET['sort']) && is_array($_GET['sort'])) {
                foreach ($_GET['sort'] as $field => $direction) {
                    if (strtolower($field) == 'relevance' && $search_mode !== 'fulltext') {
                        break;
                    }
                    $order['field'] = $field;
                    if ($field == 'price') {
                        if ($sale_mode == 1) {
                            $order['field'] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price), IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price))';
                        } else {
                            $order['field'] = 'IFNULL (G.price, I.price)';
                        }
                    }
                    $order['sort'] = (strtolower($direction) == 'asc') ? 'ASC' : 'DESC';
                    break;
                }
            } elseif ($search_mode == 'fulltext') {
                $order['field'] = 'Relevance';
                $order['sort'] = 'DESC';
            }
            // Use store settings for sort order if none designated
            if (empty($order)) {
                $order['field'] = $GLOBALS['config']->get('config', 'product_sort_column');
                $order['sort'] = $GLOBALS['config']->get('config', 'product_sort_direction');
                if (empty($order['field']) || empty($order['sort'])) {
                    unset($order); // store settings were somehow invalid
                }
            }
            if (empty($search_data['keywords']) && $order['field'] == 'Relevance') {
                if ($sale_mode == 1) {
                    $order['field'] = 'IF (G.product_id IS NULL, IF (I.sale_price IS NULL OR I.sale_price = 0, I.price, I.sale_price), IF (G.sale_price IS NULL OR G.sale_price = 0, G.price, G.sale_price))';
                } else {
                    $order['field'] = 'IFNULL (G.price, I.price)';
                }
            }
            if (is_array($order)) {
                $field_format = preg_match('/\s/', $order['field']) ? $order['field'] : '`'.$order['field'].'`';
                $order_string = 'ORDER BY '.$field_format.' '.$order['sort'];
            }

            if (isset($search_data['featured'])) {
                $where[] = "AND I.featured = '1'";
            }
            // Only look for items that are in stock
            if (isset($search_data['inStock'])) {
                $where[] = $this->outOfStockWhere();
            }

            $whereString = (isset($where) && is_array($where)) ? implode(' ', $where) : '';
            $whereString .= $this->_where_live_from;

            $joinString = (isset($joins) && is_array($joins)) ? implode(' JOIN ', $joins) : '';
            if (!empty($joinString)) {
                $joinString = ' JOIN '.$joinString;
            }

            $indexes = $GLOBALS['db']->getFulltextIndex('CubeCart_inventory', 'I');

            if (!empty($joins) || isset($search_data['keywords']) && is_array($indexes) && !empty($search_data['keywords'])) {
                if ($search_mode == 'fulltext') {
                    $max_word_len = $GLOBALS['db']->getSearchWordLen();
                    $words = explode(' ', $search_data['keywords']);
                    if (is_array($words)) {
                        $search_str_len = 0;
                        foreach ($words as $word) {
                            $search_str_len = ($search_str_len < strlen($word)) ? strlen($word) : $search_str_len;
                        }
                    } else {
                        $search_str_len = strlen($search_data['keywords']);
                    }
                }

                if ($search_mode == 'fulltext') {
                    if ($search_str_len < $max_word_len) {
                        return $this->searchCatalogue($original_search_data, $page, $per_page, 'rlike');
                    }

                    switch (true) {
                    case (preg_match('#[\+\-\>\<][\w]+#iu', $search_data['keywords'])):
                        ## Switch to bolean mode
                        $mode = 'IN BOOLEAN MODE';
                        break;
                    default:
                        $search_data['keywords'] = str_replace(' ', '*) +(*', $search_data['keywords']);
                        $search_data['keywords'] .= '*)';
                        $search_data['keywords'] = '+(*'.$search_data['keywords'];
                        $mode = 'IN BOOLEAN MODE';
                        break;
                    }
                    $words = preg_replace('/[^\p{Greek}a-zA-Z0-9\s]+/u', '', $search_data['keywords']);
                    $words = $GLOBALS['db']->sqlSafe($words);
                    // Score matching string
                    $match = sprintf("MATCH (%s) AGAINST('%s' %s)", implode(',', $indexes), $words, $mode);
                    $match_val = '0.5';

                    $query = sprintf("SELECT I.*, %2\$s AS Relevance FROM %1\$sCubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM %1\$sCubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id $joinString WHERE I.product_id IN (SELECT product_id FROM `%1\$sCubeCart_category_index` as CI INNER JOIN %1\$sCubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 AND (%2\$s) >= %4\$s %3\$s %5\$s %6\$s", $GLOBALS['config']->get('config', 'dbprefix'), $match, $whereString, $match_val, $order_string, $limit);
                    
                    if ($search = $GLOBALS['db']->query($query)) {
                        $q2 = sprintf("SELECT COUNT(I.product_id) as count, %2\$s AS Relevance FROM %1\$sCubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM %1\$sCubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id $joinString WHERE I.product_id IN (SELECT product_id FROM `%1\$sCubeCart_category_index` as CI INNER JOIN %1\$sCubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 AND (%2\$s) >= %4\$s %3\$s GROUP BY I.product_id %5\$s", $GLOBALS['config']->get('config', 'dbprefix'), $match, $whereString, $match_val, $order_string);
                        $count = $GLOBALS['db']->query($q2);
                        $this->_category_count  = (int)count($count);
                        $this->_category_products = $search;
                        $this->_sort_by_relevance = true;
                        if (count($this->_category_products)==1 && ctype_digit($this->_category_products[0]['product_id']) && $_SERVER['HTTP_X_REQUESTED_WITH']!=='XMLHttpRequest') {
                            $GLOBALS['gui']->setNotify(sprintf($GLOBALS['language']->catalogue['notify_product_search_one'], $_REQUEST['search']['keywords']));
                            httpredir('?_a=product&product_id='.$this->_category_products[0]['product_id']);
                        }
                        return true;
                    } elseif ($search_mode == 'fulltext') {
                        return $this->searchCatalogue($original_search_data, 1, $per_page, 'rlike');
                    }
                } else {
                    $search_mode = in_array($search_mode, array('rlike','like')) ? $search_mode : 'rlike';
                    $this->_sort_by_relevance = false;
                    $like = '';
                    if (!empty($search_data['keywords'])) {
                        $searchwords = preg_split('/[\s,]+/', $GLOBALS['db']->sqlSafe($search_data['keywords']));
                        $searchArray = array();
                        foreach ($searchwords as $word) {
                            if (empty($word) && !is_numeric($word)) {
                                continue;
                            }
                            $searchArray[] = $word;
                        }
			/* ORIGINAL Code follows BSMITHER EDITS TO COME
                        $noKeys = count($searchArray);
                        $regexp = $regexp_desc = '';
                        
                        $search_mode = in_array($search_mode, array('rlike','like')) ? $search_mode : 'rlike';

                        if ($search_mode == 'rlike') {
                            $like_keyword = "RLIKE";
                            $like_prefix = '[[:<:]]';
                            $like_postfix = '[[:>:]].*';
                        } else {
                            $like_keyword = "LIKE";
                            $like_prefix = '%';
                            $like_postfix = '%';
                        }
                        for ($i=0; $i<$noKeys; ++$i) {
                            $ucSearchTerm = strtoupper($searchArray[$i]);
                            if (($ucSearchTerm != 'AND') && ($ucSearchTerm != 'OR')) {
                                $regexp .= $like_prefix.$searchArray[$i].$like_postfix;
                                $regexp_desc .= $like_prefix.htmlentities(html_entity_decode($searchArray[$i], ENT_COMPAT, 'UTF-8'), ENT_QUOTES, 'UTF-8', false).$like_postfix;
                            }
                        }
                        if ($search_mode == 'rlike') {
                            $regexp = substr($regexp, 0, strlen($regexp)-2);
                            $regexp_desc = substr($regexp_desc, 0, strlen($regexp_desc)-2);
                        }
                        $like = " AND (I.name ".$like_keyword." '".$regexp."' OR I.description ".$like_keyword." '".$regexp_desc."' OR I.product_code ".$like_keyword." '".$regexp."')";
                    }
			ORIGINAL Code above ends here - REST OF BSMITHER SEARCH BELOW */
						$noKeys = count($searchArray);
						$regexp = $regexp_desc = array();
						$columnsToSearch = array('I.name','I.product_code','I.search_keywords',); // columns where contents are plain words
						$columnsToSearch_desc = array('I.description',); // columns where contents can be rich text
						$search_mode = in_array($search_mode, array('rlike','like')) ? $search_mode : 'rlike';
						if($search_mode == 'rlike') {
							$like_keyword = "RLIKE";
							$like_prefix = '[[:<:]]';
							$like_postfix = '[[:>:]]';
						} else {
							$like_keyword = "LIKE";
							$like_prefix = '%';
							$like_postfix = '%';
						}
						foreach($columnsToSearch as $col) {
							for ($i=0; $i<$noKeys; ++$i) {
								$ucSearchTerm = strtoupper($searchArray[$i]);
								if (($ucSearchTerm != 'AND') && ($ucSearchTerm != 'OR')) {
									$regexp[$col][] = $col." ".$like_keyword." '".$like_prefix.$searchArray[$i].$like_postfix."'";
								}
							}
							$regexp[$col] = '('.implode(' AND ', $regexp[$col]).')';
						}
						foreach($columnsToSearch_desc as $col) {
							for ($i=0; $i<$noKeys; ++$i) {
								$ucSearchTerm = strtoupper($searchArray[$i]);
								if (($ucSearchTerm != 'AND') && ($ucSearchTerm != 'OR')) {
									$regexp_desc[$col][] = $col." ".$like_keyword." '".$like_prefix.htmlentities(html_entity_decode($searchArray[$i],ENT_COMPAT,'UTF-8'),ENT_QUOTES,'UTF-8',false).$like_postfix."'";
								}
							}
							$regexp_desc[$col] = '('.implode(' AND ', $regexp_desc[$col]).')';
						}
						$like = ' AND ('.implode(' OR ', $regexp).' OR '.implode(' OR ', $regexp_desc).')';
					}
		//END OF NEW BSMITHER SEARCH CODE
                    $q2 = "SELECT I.* FROM ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id $joinString WHERE I.product_id IN (SELECT product_id FROM `".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_category_index` as CI INNER JOIN ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 ".$whereString.$like;
                    $query = $q2.' '.$order_string.' '.$limit;
                    $search = $GLOBALS['db']->query($query);
                    if (count($search)>0) {
                        $count = $GLOBALS['db']->query($q2);
                        $this->_category_count  = (int)count($count);
                        $this->_category_products = $search;
                        if (count($this->_category_products)==1 && ctype_digit($this->_category_products[0]['product_id']) && $_SERVER['HTTP_X_REQUESTED_WITH']!=='XMLHttpRequest') {
                            $GLOBALS['gui']->setNotify(sprintf($GLOBALS['language']->catalogue['notify_product_search_one'], $_REQUEST['search']['keywords']));
                            httpredir('?_a=product&product_id='.$this->_category_products[0]['product_id']);
                        }
                        return true;
                    } elseif ($search_mode=="rlike") {
                        return $this->searchCatalogue($original_search_data, 1, $per_page, 'like');
                    }
                }
            }
        } else {
            if (is_numeric($search_data)) {
                if (($category = $this->getCategoryData((int)$search_data)) !== false) {
                    if (($products = $this->getCategoryProducts((int)$search_data, $page, $per_page)) !== false) {
                        $this->_category_products = $products;
                        return true;
                    }
                }
            } elseif (strtolower($search_data) == 'sale') {
                if (isset($_GET['sort']) && is_array($_GET['sort'])) {
                    foreach ($_GET['sort'] as $field => $direction) {
                        $order[$field] = (strtolower($direction) == 'asc') ? 'ASC' : 'DESC';
                        break;
                    }
                } else {
                    $order['price'] = 'DESC';
                }

                if (is_array($order)) {
                    if (key($order) == "price") {
                        if ($GLOBALS['config']->get('config', 'catalogue_sale_mode') == '1') {
                            $order_string = 'ORDER BY (I.price-I.sale_price) '.current($order);
                        } elseif ($GLOBALS['config']->get('config', 'catalogue_sale_mode') == '2' && $GLOBALS['config']->get('config', 'catalogue_sale_percentage'>0)) {
                            $order_string = 'ORDER BY (I.price - (I.price / 100) * '.$GLOBALS['config']->get('config', 'catalogue_sale_percentage').') '.current($order);
                        }
                        $_GET['sort']['price'] = current($order);
                    } else {
                        $_GET['sort'][key($order)] = current($order);
                        $order_string = 'ORDER BY `'.key($order).'` '.current($order);
                    }
                }
                $where2 = $this->outOfStockWhere(false, 'I', true);
                $whereString = 'IF (G.sale_price IS NULL, I.sale_price, G.sale_price) > 0'.$where2;
                if ($GLOBALS['config']->get('config', 'catalogue_sale_mode') == '1') {
                    $query = sprintf("SELECT I.* FROM %1\$sCubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM %1\$sCubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id WHERE I.product_id IN (SELECT product_id FROM `%1\$sCubeCart_category_index` as CI INNER JOIN %1\$sCubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 AND %2\$s %3\$s %4\$s", $GLOBALS['config']->get('config', 'dbprefix'), $whereString, $order_string, $limit);
                } elseif ($GLOBALS['config']->get('config', 'catalogue_sale_mode') == '2') {
                    $decimal_percent = $GLOBALS['config']->get('config', 'catalogue_sale_percentage')/100;
                    $query = sprintf("SELECT I.* FROM %1\$sCubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, price*%4\$s as sale_price FROM %1\$sCubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id WHERE I.product_id IN (SELECT product_id FROM `%1\$sCubeCart_category_index` as CI INNER JOIN %1\$sCubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 %2\$s %3\$s", $GLOBALS['config']->get('config', 'dbprefix'), $order_string, $limit, $decimal_percent);
                } else {
                    return false;
                }
                foreach ($GLOBALS['hooks']->load('class.cubecart.search_catalogue') as $hook) {
                    include $hook;
                }
                if (($sale = $GLOBALS['db']->query($query)) !== false) {
                    $q2 = sprintf("SELECT SQL_CALC_FOUND_ROWS I.* FROM %1\$sCubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM %1\$sCubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id WHERE I.product_id IN (SELECT product_id FROM `%1\$sCubeCart_category_index` as CI INNER JOIN %1\$sCubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 AND %2\$s %3\$s", $GLOBALS['config']->get('config', 'dbprefix'), $whereString, $order_string);
                    $count = $GLOBALS['db']->query($q2);
                    $this->_category_count  = (int)count($count);
                    $this->_category_products = $sale;
                    foreach ($GLOBALS['hooks']->load('class.catalogue.search_catalogue.sale_items.post') as $hook) {
                        include $hook;
                    }
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Set category id/name
     *
     * @param string $id
     * @param string $name
     */
    public function setCategory($id, $name)
    {
        $this->_categoryData[$id] = $name;
    }

 

Link to comment
Share on other sites

You would prefer to come back as not found.

This section of the new code:

						if($search_mode == 'rlike') {
							$like_keyword = "RLIKE";
							$like_prefix = '[[:<:]]';
							$like_postfix = '[[:>:]]';
						} else {
							$like_keyword = "LIKE";
							$like_prefix = '%';
							$like_postfix = '%';
						}
Change to:

						if($search_mode == 'rlike' || $search_mode == 'like') {
							$like_keyword = "RLIKE";
							$like_prefix = '[[:<:]]';
							$like_postfix = '[[:>:]]';
						} else {
							$like_keyword = "LIKE";
							$like_prefix = '%';
							$like_postfix = '%';
						}

Then, make this change:

	                    return true;
                    } elseif ($search_mode=="rlike") {
                        return $this->searchCatalogue($original_search_data, 1, $per_page, 'like');
                    }

To:

	                    return true;
                    } elseif (false && $search_mode=="rlike") {
                        return $this->searchCatalogue($original_search_data, 1, $per_page, 'like');
                    }

This makes RLIKE and LIKE to have the same SQL phrase. So, if this function is entered using "like", it will actually create the "rlike" phrase.

The second edit will inhibit trying the "like" method if the "rlike" method finds nothing.

Link to comment
Share on other sites

Did I do what you wanted? It's finding totally irrelevant titles now. And I made sure to clear all caches. This is on my test site, not live store.

			ORIGINAL Code above ends here - REST OF BSMITHER SEARCH BELOW */
						$noKeys = count($searchArray);
						$regexp = $regexp_desc = array();
						$columnsToSearch = array('I.name','I.product_code','I.search_keywords',); // columns where contents are plain words
						$columnsToSearch_desc = array('I.description',); // columns where contents can be rich text
						$search_mode = in_array($search_mode, array('rlike','like')) ? $search_mode : 'rlike';
						// ORIGINAL B4 BSMITHER EDIT BELOW TO REMOVE PIECES OF WORDS if($search_mode == 'rlike') {
						if($search_mode == 'rlike' || $search_mode == 'like') {
							$like_keyword = "RLIKE";
							$like_prefix = '[[:<:]]';
							$like_postfix = '[[:>:]]';
						} else {
							$like_keyword = "LIKE";
							$like_prefix = '%';
							$like_postfix = '%';
						}
						foreach($columnsToSearch as $col) {
							for ($i=0; $i<$noKeys; ++$i) {
								$ucSearchTerm = strtoupper($searchArray[$i]);
								if (($ucSearchTerm != 'AND') && ($ucSearchTerm != 'OR')) {
									$regexp[$col][] = $col." ".$like_keyword." '".$like_prefix.$searchArray[$i].$like_postfix."'";
								}
							}
							$regexp[$col] = '('.implode(' AND ', $regexp[$col]).')';
						}
						foreach($columnsToSearch_desc as $col) {
							for ($i=0; $i<$noKeys; ++$i) {
								$ucSearchTerm = strtoupper($searchArray[$i]);
								if (($ucSearchTerm != 'AND') && ($ucSearchTerm != 'OR')) {
									$regexp_desc[$col][] = $col." ".$like_keyword." '".$like_prefix.htmlentities(html_entity_decode($searchArray[$i],ENT_COMPAT,'UTF-8'),ENT_QUOTES,'UTF-8',false).$like_postfix."'";
								}
							}
							$regexp_desc[$col] = '('.implode(' AND ', $regexp_desc[$col]).')';
						}
						$like = ' AND ('.implode(' OR ', $regexp).' OR '.implode(' OR ', $regexp_desc).')';
					}
		//END OF NEW BSMITHER SEARCH CODE
                    $q2 = "SELECT I.* FROM ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_inventory AS I LEFT JOIN (SELECT product_id, MAX(price) as price, MAX(sale_price) as sale_price FROM ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_pricing_group $group_id GROUP BY product_id) as G ON G.product_id = I.product_id $joinString WHERE I.product_id IN (SELECT product_id FROM `".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_category_index` as CI INNER JOIN ".$GLOBALS['config']->get('config', 'dbprefix')."CubeCart_category as C where CI.cat_id = C.cat_id AND C.status = 1) AND I.status = 1 ".$whereString.$like;
                    $query = $q2.' '.$order_string.' '.$limit;
                    $search = $GLOBALS['db']->query($query);
                    if (count($search)>0) {
                        $count = $GLOBALS['db']->query($q2);
                        $this->_category_count  = (int)count($count);
                        $this->_category_products = $search;
                        if (count($this->_category_products)==1 && ctype_digit($this->_category_products[0]['product_id']) && $_SERVER['HTTP_X_REQUESTED_WITH']!=='XMLHttpRequest') {
                            $GLOBALS['gui']->setNotify(sprintf($GLOBALS['language']->catalogue['notify_product_search_one'], $_REQUEST['search']['keywords']));
                            httpredir('?_a=product&product_id='.$this->_category_products[0]['product_id']);
                        }
                        return true;
                   // STOCK LINE B4 BSMITHER CHANGE BELOW TO ELIMINATE PIECES OF WORDS FROM BEING FOUND } elseif ($search_mode=="rlike") {
		   } elseif (false && $search_mode=="rlike") {
                        return $this->searchCatalogue($original_search_data, 1, $per_page, 'like');
                    }
                }
            }
        } else {

 

Link to comment
Share on other sites

So, it seems there is a recent change to the code (not yet released but being tested from HEAD in the Github (and not shown in the code boxes above) -- and not related to the OP of this conversation) that includes the manufacturer's name in the search. This inclusion is not made evident, gets included even if using simple search, the search syntax is improperly loose, which then causes irrelevant products to turn up in the search results.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...