Jump to content
thirty bees forum

How to change searching multiple terms from "or" to "and"


musicmaster

Recommended Posts

Just a little trick:

The problem is well known. Searching for more than one word gives all products that contain at least one of the words. It is rather easy to change that. You need to change just a few lines in classes/Search.php

On line 232 of Search.php you will find:

 $eligibleProducts2 = [];
 foreach ($intersectArray as $query) {
     foreach ($db->executeS($query, true, false) as $row) {
         $eligibleProducts2[] = $row['id_product'];
     }
 }
 $eligibleProducts = array_unique(array_intersect($eligibleProducts, array_unique($eligibleProducts2)));
 if (!count($eligibleProducts)) {
     return ($ajax ? [] : ['total' => 0, 'result' => []]);
 }

You should change that to 

 $eligibleProducts2 = [];
 foreach ($intersectArray as $query) {
    foreach ($db->executeS($query, true, false) as $row) {
        $eligibleProducts2[] = $row['id_product'];
    }
    $eligibleProducts = array_unique(array_intersect($eligibleProducts, array_unique($eligibleProducts2)));
    $eligibleProducts2 = [];
 }
 if (!count($eligibleProducts)) {
     return ($ajax ? [] : ['total' => 0, 'result' => []]);
 }

This was done in TB 1.02. If you have a different version the line numbers may be slightly different.

Edited by musicmaster
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...