*

webcity

  • ****
  • 219 posts
Search results - Match all keywords
« on: June 14, 2022, 02:25:46 PM »
Hi,

Can we have the option in the search setting for the default search to match all keywords, just like this forum search bar defaults to?

How it works now - type say "silver kettle", you will get every advert containing the word "silver", plus every advert with the keyword "kettle". Most people would expect to get search results with both the keywords kettle and silver listed, as they are looking for a silver kettle.

Many thanks
« Last Edit: June 14, 2022, 02:27:39 PM by webcity »

*

MB Themes

Re: Search results - Match all keywords
« Reply #1 on: June 14, 2022, 03:36:25 PM »
@webcity
It can be more complicated to use it with long text as listing description is, especially when you enter like 10 keywords. Not sure how currentl search engines works with multiple keywords.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

webcity

  • ****
  • 219 posts
Re: Search results - Match all keywords
« Reply #2 on: June 14, 2022, 05:18:24 PM »
@webcity
It can be more complicated to use it with long text as listing description is, especially when you enter like 10 keywords. Not sure how currentl search engines works with multiple keywords.

Hi,

I had used the option many years ago with some code from the old osclass.org forums but I can't find the code now. It was a bit of code that you added to the theme function.php .

It would be a good option to limit the keywords to say 5 words to reduce server overheads.

If anyone else has the code or can suggest a solution , that would be great.

Many thanks

*

MB Themes

Re: Search results - Match all keywords
« Reply #3 on: June 16, 2022, 05:56:52 PM »
@webcity
Will put it on list to review, but osclass 8.0.3 log is almost full and has work for at least 3 months :D
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

atba

  • ****
  • 190 posts
Re: Search results - Match all keywords
« Reply #4 on: June 19, 2022, 02:48:25 PM »
Correct remark! The search leaves much to be desired. For when trying to find, for example, a woman's bag, it will give out everything that is female with a catch and everything that is a bag. And as a result, the search results are full of porridge.

*

webcity

  • ****
  • 219 posts
Re: Search results - Match all keywords
« Reply #5 on: June 27, 2022, 12:50:17 PM »
Found the answer on a osclass support forum. Seems to work OK on the Epsilon theme.
Include the following in the theme function.php to search all keywords:


Code: [Select]

function cust_pattern_search_all_keywords_only($params) {
    if (@$params['sPattern'] != '') {
        $mSearch = Search::newInstance();
        $query_elements = json_decode($mSearch->toJson(), true);
        $pattern = $query_elements['sPattern'];

        foreach (explode(' ', $pattern) as $word) {
            //$query_elements['sPattern'] = str_replace($word, '+' . $word . '*', $query_elements['sPattern']); //search with wildcard egg => eggs
            $query_elements['sPattern'] = str_replace($word, '+' . $word, $query_elements['sPattern']);
        }

        $mSearch->addLocale('%');
        $mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');

        $mSearch->setJsonAlert($query_elements);
    }
}

osc_add_hook('search_conditions', 'cust_pattern_search_all_keywords_only', 10);

*

MB Themes

Re: Search results - Match all keywords
« Reply #6 on: June 29, 2022, 04:42:58 PM »
Looks good ;)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots