Search problem
« on: February 02, 2018, 09:13:07 AM »
F.e this product name is Volvo s40, i searched volv, or volvo , doesnt match any ad. Is anybody solved this problem? :o

Re: Search problem
« Reply #1 on: February 02, 2018, 09:32:40 AM »
its problem coming from adding new language. If you add new language, old ads doesnt show any search

*

MB Themes

Re: Search problem
« Reply #2 on: February 02, 2018, 09:34:42 AM »
@Şahin
Did not hear about such language issue yet, only what I know is that search works just on titles of current user active language... so if those titles were made in english and you add and switch to german, these listings has no titles for these languages.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

zovi

  • ***
  • 29 posts
Re: Search problem
« Reply #3 on: February 04, 2018, 11:16:12 PM »
Hello
I found a solution for this problem on osclass forums.

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_refined_pattern_search($params) {
    if (@
$params['sPattern'] != '') {
        
$mSearch Search::newInstance();
        
$query_elements = (array) json_decode($mSearch->toJson());
        
        
$mSearch->addLocale('%');
        
$mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
        if (@
$params['sOrder'] != 'i_price') {
            
$mSearch->addJoinTable(count($query_elements['tables_join']), sprintf("(SELECT fk_i_item_id, MATCH(s_title, s_description) AGAINST('%s') AS relevance FROM %st_item_description) des"$params['sPattern'], DB_TABLE_PREFIX), 'des.fk_i_item_id = '.DB_TABLE_PREFIX.'t_item.pk_i_id''INNER' );
            
$mSearch->order("des.relevance DESC, dt_pub_date""DESC");
        }        
    }
}

osc_add_hook('search_conditions''cust_refined_pattern_search');

function 
cust_alerts_user_dashboard() {
    if (
Params::getParam('page') == "user" && Params::getParam('action') == "alerts") {
        
$webUser = new CWebUser;

        
$aAlerts Alerts::newInstance()->findByUserSession::newInstance()->_get('userId'), false );
        
$user User::newInstance()->findByPrimaryKeySession::newInstance()->_get('userId'));
        foreach(
$aAlerts as $k => $a) {
            
$array_conditions   = (array)json_decode($a['s_search']);

            
$search = new Search();
            
$search->setJsonAlert($array_conditions);
            if (
osc_version() > 361$search->notFromUser(Session::newInstance()->_get('userId'));
            
$search->addLocale('%');
            
$search->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
            
$search->limit(03);

            
$aAlerts[$k]['items'] = $search->doSearch();
        }

        
$webUser->_exportVariableToView('alerts'$aAlerts);
        
View::newInstance()->_reset('alerts');
        
$webUser->_exportVariableToView('user'$user);
    }
}

osc_add_hook('before_html''cust_alerts_user_dashboard');
?>



Works exactly as I want. Hope it helps someone.

cheers
« Last Edit: November 02, 2018, 01:32:11 PM by MB Themes »

Re: Search problem
« Reply #4 on: November 02, 2018, 10:31:50 AM »
Hello
I found a solution for this problem on forums.osclass.org:
https://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113711/#msg113711

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_refined_pattern_search($params) {
    if (@
$params['sPattern'] != '') {
        
$mSearch Search::newInstance();
        
$query_elements = (array) json_decode($mSearch->toJson());
        
        
$mSearch->addLocale('%');
        
$mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
        if (@
$params['sOrder'] != 'i_price') {
            
$mSearch->addJoinTable(count($query_elements['tables_join']), sprintf("(SELECT fk_i_item_id, MATCH(s_title, s_description) AGAINST('%s') AS relevance FROM %st_item_description) des"$params['sPattern'], DB_TABLE_PREFIX), 'des.fk_i_item_id = '.DB_TABLE_PREFIX.'t_item.pk_i_id''INNER' );
            
$mSearch->order("des.relevance DESC, dt_pub_date""DESC");
        }        
    }
}

osc_add_hook('search_conditions''cust_refined_pattern_search');

function 
cust_alerts_user_dashboard() {
    if (
Params::getParam('page') == "user" && Params::getParam('action') == "alerts") {
        
$webUser = new CWebUser;

        
$aAlerts Alerts::newInstance()->findByUserSession::newInstance()->_get('userId'), false );
        
$user User::newInstance()->findByPrimaryKeySession::newInstance()->_get('userId'));
        foreach(
$aAlerts as $k => $a) {
            
$array_conditions   = (array)json_decode($a['s_search']);

            
$search = new Search();
            
$search->setJsonAlert($array_conditions);
            if (
osc_version() > 361$search->notFromUser(Session::newInstance()->_get('userId'));
            
$search->addLocale('%');
            
$search->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
            
$search->limit(03);

            
$aAlerts[$k]['items'] = $search->doSearch();
        }

        
$webUser->_exportVariableToView('alerts'$aAlerts);
        
View::newInstance()->_reset('alerts');
        
$webUser->_exportVariableToView('user'$user);
    }
}

osc_add_hook('before_html''cust_alerts_user_dashboard');
?>



Works exactly as I want. Hope it helps someone.

cheers

How install? Need run hook?

*

Rick

  • ***
  • 36 posts
Re: Search problem
« Reply #5 on: December 22, 2022, 09:09:14 PM »
Lift this theard up, its still a problem.