You are here:  » boolean mode no results?


boolean mode no results?

Submitted by quokka on Fri, 2011-09-30 21:11 in

Hi David,
Sorry for bothering you again.

I changed to boolean mode by changing

$where = "MATCH ".$matchFields." AGAINST ('".database_safe($parts[0])."')";

to

$where = "MATCH ".$matchFields." AGAINST ('+".str_replace(" "," +",$parts[0])."' IN BOOLEAN MODE)";

in search.php

I see strange results..For example:
Any idea Why searching for "Hanglamp cars"doesn't return results, and "Hanglamp cars 2" does?
Product name: Hanglamp cars 2 / Decofun

{link saved}

Thanks again!

Submitted by support on Sat, 2011-10-01 10:03

Hi,

That will be a conflict with the stemming code; what's happening is because cars is plural the stemming code is adding "car" to the query; and with the boolean mode + operator then applied to that it's looking for both "cars" and "car".

To disable stemming, look for the following code at line 204:

$parts[0] = implode(" ",$allWords);

...and either comment out or delete that line and your queries should then work as expected. Note that boolean mode only applies to full text queries; and full text mode is only used if every keyword in the query is 4 or more characters (the full text index doesn't index short words by default...)

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Thu, 2015-04-09 21:19

Hello David,

May I ask how can I combine both AND and OR operators in Boolean mode at

$match = "+".str_replace(" "," +",$parts[0]);

Thank you for your help.

Cheers

S

Submitted by support on Fri, 2015-04-10 07:45

Hi Steve,

The full reference for BOOLEAN mode match values can be found at:

https://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

If you wanted to experiment with different queries, one option would be add a special handler that uses the query with a BOOLEAN MODE fulltext search directly. To try this, edit search.php and look for the following code at line 194:

      case "bw":

...and REPALCE with:

      case "boolean:":
        $q = $_GET["q"];
        $parts = explode(":",$q);
        $where = "MATCH name AGAINST ('".database_safe($parts[1])."' IN BOOLEAN MODE)";
        $sql = "SELECT SQL_CALC_FOUND_ROWS id,COUNT(id) AS numMerchants,MIN(price) as minPrice,MATCH name AGAINST ('".database_safe($parts[1])."' IN BOOLEAN MODE) AS relevance FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." GROUP BY search_name";
        $orderBySelection = $orderByFullText;
      case "bw":

With that in place, you can query, for example:

boolean:+dog -cat

...which means MUST INCLUDE "dog" and MUST NOT INCLUDE "cat"

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Fri, 2015-04-10 11:59

Hello David!

Thank you for your email and your modification concerning BOOLEAN.

I will test it more during the weekend.

Hope you have a great weekend!

Cheers

S