• Osclass Evolution is an official classifieds script based on Osclass v. 3.8 which was officially closed on September 5, 2019.
    This engine maintains support for old templates and plugins, and it is constantly being updated and improved. Using this script, we guarantee that you will get a quality product with all the necessary support.

    All other improvements of this script are Amateur work of third-party developers.

Suggestion Improve search function

p206ab

New member
Hi all,
I've been trying to finally break through the issues with search functionality on Osclass.
My issue is that when I have a listing for "Peugeot 208", it will be found if searched by Peugeot, but not if query is 208, which I'm now trying to fix.

So far I've found this in the oc-includes/osclass/model/Search.php:


Code:
if ($this->withPattern ) {
                    $this->dao->join(DB_TABLE_PREFIX.'t_item_description as d','d.fk_i_item_id = '.DB_TABLE_PREFIX.'t_item.pk_i_id','LEFT');
                    $this->dao->where(sprintf("MATCH(d.s_title, d.s_description) AGAINST('%s' IN BOOLEAN MODE)", $this->sPattern) );

where the last line is the WHERE part in SQL query, which matches the search query to title or description inside item_description table.
I got the most accurate results when I ran a query using either LIKE %string% or REGEXP, so I used the latter and edited the last line.

So to search only by listing titles, change it to this:
Code:
$this->dao->where(sprintf("(d.s_title REGEXP '%s' )", $this->sPattern) );

while for titles and descriptions, use this:
Code:
$this->dao->where(sprintf("(d.s_title OR d.s_description REGEXP '%s' )", $this->sPattern) );

Please note, that this was not fully tested, use it on your own responsibility and make backup before any edits.

But it works lovely for me, so let me know if it solves your issue too.
This could probably be implemented also as a custom function in the theme functions.php, to avoid messing with the core, but I'm not good with those, so if anyone can sort it out, please do.
 
Top