You are here:  » Wordpress Boolean Search


Wordpress Boolean Search

Submitted by ccgale on Thu, 2018-07-12 11:01 in

Hi, sorry another quick question

Is there a way to make the wordpress search results better? Let's take the example 'leather dress' if I search for that with $config_useFullText I get Showing: 1 to 40 of 67252 (hmm), as you would expect, 99% of those are not leather dresses - the first product in the results is 'White Lace Sheath Short Cocktail Dres Wedding Guest Dress Milanoo' - not very leathery!

If I change this to $config_useFullText, the same query then yields just 112 results, which is much better, however, if I then search for 'Leather Dresses' under this condition I get just 4 results, all of which have Dresses in the name.

My question, then, is how can I set wordpress up to search for Dresses & Dress or Skirts & Skirt etc without pulling in 50,000 unrelated terms.

I read up on your site and you hint a lot at Boolean search. I tried this for the normal installation but didn't see any improvement in the results

Any pointers would be great, please

Submitted by support on Thu, 2018-07-12 14:55

Hi,

The FULLTEXT search already adds singulars for plurals simply ending in "s", so with $config_useFullText enabled a search for "denim skirts" would be expanded to "denim skirts skirt".

However, this wouldn't work for "leather dresses" as the query would be expanded to "leather dresses dresse" but for a niche site, if it would be manageable to create a lookup array of plurals to their correct singular version that would be straight forward to implement.

To give this a go for "dresses" > "dress", edit pto_search.php and look for the following code beginning at line 192:

        foreach($words as $word)
        {
          if (substr($word,-1)=="s")
          {
            $newWords[] = substr($word,0,-1);
          }
        }

...and REPLACE with:

        foreach($words as $k => $word)
        {
          $words[$k] = strtolower($word);
        }
        $singulars = array(
          "dresses" => "dress"
        );
        foreach($words as $word)
        {
          if (isset($singulars[$word]))
          {
            $newWords[] = $singulars[$word];
          }
          elseif (substr($word,-1)=="s")
          {
            $newWords[] = substr($word,0,-1);
          }
        }

To add additional translations to the $singulars array, simply add "plural" => "singular" pairs as required, separated by commas.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ccgale on Thu, 2018-07-12 15:18

Hi, still no luck. If I have $config_useFullText=True I get Showing: 1 to 40 of 67781 if I have it $config_useFullText=False I get 6 results - all of which have leather dresses in the name. If I search for just leather dresses, I have 81 items.

Submitted by support on Thu, 2018-07-12 16:44

Hi,

Sorry about that - could you perhaps email me your modified pto_search.php and also if possible a link to the /shopping (container permalink) page of the installation and I'll check it out further with you...

Thanks,
David.
--
PriceTapestry.com