Advertisement:

Author Topic: Search Problem OC 3.5.3  (Read 13110 times)

Nex23

  • Newbie
  • *
  • Posts: 20
Search Problem OC 3.5.3
« on: January 05, 2015, 07:45:04 pm »
I have again a problem with my search.
My searches do not return any item.

The website is : http://xoor.ro

What can I do ? The install is fresh and installed with Softaculous .

Nex23

  • Newbie
  • *
  • Posts: 20
Re: Search Problem OC 3.5.3
« Reply #1 on: January 07, 2015, 01:00:47 pm »
Ok , I've figured out that the search problem appears after I change the default language to another language . What may be the problem ?

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Search Problem OC 3.5.3
« Reply #2 on: January 07, 2015, 01:17:09 pm »
Hi,

Yes, searches are made over current selected language. Any ad with title/description marked as written in other language won't be taken into consideration.

***UPDATED with 5th version*** (February, 14 2017)

If you're interested in your searches covering all enabled languages, 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.

5th version (Alerts compatible -no duplicate ads, Multilanguage on User Alerts, solved problem with page language changing)

Code: [Select]
<?php
function cust_refined_pattern_search($params) {
    if (@
$params['sPattern'] != '') {
        
$mSearch Search::newInstance();
        
        
$mSearch->addLocale('%');
        
$mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');       
    }
}

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');

?>

4th version (Alerts compatible -no duplicate ads, Multilanguage on User Alerts, problem with page language changing, other bugs)

Code: [Select]
<?php
function cust_pattern_search_all_locales($params) {
    
    if (
$params['sPattern'] != '') {
        
$mSearch =  Search::newInstance();
        
$mSearch->addLocale('%');
        
$mSearch->addGroupBy("pk_i_id"); 
    }
}

osc_add_hook('search_conditions''cust_pattern_search_all_locales');

function 
cust_alerts_locale_hack_start() {

    if (
osc_get_osclass_section() == "alerts") {
        
View::newInstance()->_exportVariableToView('aUserLocale'Session::newInstance()->_get('userLocale'));
        
Session::newInstance()->_set('userLocale''%');
    }
}

osc_add_hook('init''cust_alerts_locale_hack_start');

function 
cust_alerts_locale_hack_end($conditions) {

    if (
osc_get_osclass_section() == "alerts") {
        
Session::newInstance()->_set('userLocale'View::newInstance()->_get('aUserLocale'));
    }

    return 
$conditions;
}

osc_add_filter('sql_search_item_conditions''cust_alerts_locale_hack_end');
?>


3rd version (Alerts compatible -no duplicate ads, No multilanguage on User Alerts)

Code: [Select]
<?php
function cust_pattern_search_all_locales($params) {
    
$mSearch =  Search::newInstance();

    if (
$params['sPattern'] != '') {
        
$mSearch->addConditions("d.fk_c_locale_code LIKE '%'");
        
$mSearch->addGroupBy("pk_i_id");
    }
}

osc_add_hook('search_conditions''cust_pattern_search_all_locales');

function 
cust_clean_duplicate_ads_user_alerts() {
    
    
$clean_alerts View::newInstance()->_get('alerts');

    if (
$clean_alerts) {
        foreach (
$clean_alerts as $key => $alert) {

            
$outputArray = array();
            
$keysArray = array();
            foreach (
$clean_alerts[$key]['items'] as $innerArray) {
                if (!
in_array($innerArray['pk_i_id'], $keysArray)) {
                    
$keysArray[] = $innerArray['pk_i_id'];
                    
$outputArray[] = $innerArray;
                }
            }

            
$clean_alerts[$key]['items'] = $outputArray;
        }

    
View::newInstance()->_exportVariableToView('alerts'$clean_alerts);
    }  
}

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

2nd version (Alerts compatible -but including duplicate ads under certain circumstances)

Code: [Select]
<?php
function cust_pattern_search_all_locales($params) {
    
$mSearch =  Search::newInstance();

    if (
$params['sPattern'] != '') {
        
$mSearch->addConditions("d.fk_c_locale_code LIKE '%'");
        
$mSearch->addGroupBy("pk_i_id");
    }
}

osc_add_hook('search_conditions''cust_pattern_search_all_locales');
?>


1st version (Alerts uncompatible)

Code: [Select]
<?php
function cust_pattern_search_all_locales($params) {
    
$mSearch =  Search::newInstance();
    
    if (
$params['sPattern'] != '') {
        
$mSearch->addLocale('%');
        
$mSearch->addGroupBy("pk_i_id");
    }
}

osc_add_hook('search_conditions''cust_pattern_search_all_locales');
?>

Regards
« Last Edit: February 14, 2017, 06:01:05 pm by teseo »

Nex23

  • Newbie
  • *
  • Posts: 20
Re: Search Problem OC 3.5.3
« Reply #3 on: January 07, 2015, 06:48:59 pm »
Yep , that worked for me . Thanks a lot !

There is another problem with the search algorithm .
Let's say I have: Blue T-Shirt and Black T-Shirt .
If I search after "T-Shirt" I will receive both results , if I search after "Black T-Shirt" I will receive again both results BUT they will be ordered by "Newest first" or by price , not by relevance !
And by this I mean if the Blue one is the newest added if I search for Black T-Shirt , the Blue one will come up first . How can I change that ? The blue one has two matches while the black one only one !!
« Last Edit: January 07, 2015, 06:55:32 pm by Nex23 »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Search Problem OC 3.5.3
« Reply #4 on: January 08, 2015, 01:39:57 pm »
***UPDATED with 10th version*** :o :) (February, 14 2017)

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.

10th version (Alerts compatible, Multilanguage on User Alerts), no Sorting by relevance on See By Price, Compatibility with other possible custom JOINS, ignore duplicates, fixed problem with page language changing and other bugs

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');
?>

9th version (Alerts compatible, Multilanguage on User Alerts), no Sorting by relevance on See By (another little fix), Compatibility with other possible custom JOINS, Discard duplicatesproblem with page language changing, other bugs

Code: [Select]
<?php
function cust_refined_pattern_search($params) {
    
    if (
$params['sPattern'] != '' && !Session::newInstance()->_get('seeBy')) {
        
$mSearch Search::newInstance();
        
$query_elements = (array) json_decode($mSearch->toJson());
    
        
$mSearch->addJoinTable(count($query_elements['tables_join']), sprintf("(SELECT DISTINCT(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->addLocale('%');
        
$mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
        
$mSearch->order("des.relevance DESC, dt_pub_date""DESC"); 
    }

    
Session::newInstance()->_drop('seeBy');
}

osc_add_hook('search_conditions''cust_refined_pattern_search');

function 
cust_alerts_locale_hack_start() {

    if (
osc_get_osclass_section() == "alerts") {
        
View::newInstance()->_exportVariableToView('aUserLocale'Session::newInstance()->_get('userLocale'));
        
Session::newInstance()->_set('userLocale''%');
    }

    
// Detect See By link     
    
if (Session::newInstance()->_get('seeBy') == '')  Session::newInstance()->_set('seeBy', (Params::getParam('seeBy') ? 0));
    
Params::unsetParam('seeBy');
}

osc_add_hook('init''cust_alerts_locale_hack_start');

function 
cust_alerts_locale_hack_end($conditions) {

    if (
osc_get_osclass_section() == "alerts") {
        
Session::newInstance()->_set('userLocale'View::newInstance()->_get('aUserLocale'));
    }

    return 
$conditions
}

osc_add_filter('sql_search_item_conditions''cust_alerts_locale_hack_end');

function 
cust_seeBy_link_add_identifier() { ?>

    <script type="text/javascript">
        $(".see_by a").on('click', function(e) {
            $(this).prop('href', $(this).prop('href') + '?seeBy=1');
            return true;
        })
    </script>
<?php  }

osc_add_hook('footer''cust_seeBy_link_add_identifier');
?>


8th version (Alerts compatible - no duplicate ads, Multilanguage on User Alerts), no Sorting by relevance on See By (another little fix), Compatibility with other possible custom JOINS

Code: [Select]
<?php
function cust_refined_pattern_search($params) {
    
    if (
$params['sPattern'] != '' && !Session::newInstance()->_get('seeBy')) {
        
$mSearch Search::newInstance();
        
$query_elements = (array) json_decode($mSearch->toJson());
    
        
$mSearch->addJoinTable(count($query_elements['tables_join']), sprintf("(SELECT DISTINCT(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->addLocale('%');
        
$mSearch->order("des.relevance DESC, dt_pub_date""DESC"); 
    }

    
Session::newInstance()->_drop('seeBy');
}

osc_add_hook('search_conditions''cust_refined_pattern_search');

function 
cust_alerts_locale_hack_start() {

    if (
osc_get_osclass_section() == "alerts") {
        
View::newInstance()->_exportVariableToView('aUserLocale'Session::newInstance()->_get('userLocale'));
        
Session::newInstance()->_set('userLocale''%');
    }

    
// Detect See By link     
    
if (Session::newInstance()->_get('seeBy') == '')  Session::newInstance()->_set('seeBy', (Params::getParam('seeBy') ? 0));
    
Params::unsetParam('seeBy');
}

osc_add_hook('init''cust_alerts_locale_hack_start');

function 
cust_alerts_locale_hack_end($conditions) {

    if (
osc_get_osclass_section() == "alerts") {
        
Session::newInstance()->_set('userLocale'View::newInstance()->_get('aUserLocale'));
    }

    return 
$conditions
}

osc_add_filter('sql_search_item_conditions''cust_alerts_locale_hack_end');

function 
cust_seeBy_link_add_identifier() { ?>

    <script type="text/javascript">
        $(".see_by a").on('click', function(e) {
            $(this).prop('href', $(this).prop('href') + '?seeBy=1');
            return true;
        })
    </script>
<?php  }

osc_add_hook('footer''cust_seeBy_link_add_identifier');
?>


7th version (Alerts compatible - no duplicate ads, Multilanguage on User Alerts), no Sorting by relevance on See By (little fix), Compatibility with other possible custom JOINS

Code: [Select]
<?php
function cust_refined_pattern_search($params) {
    
    if (
$params['sPattern'] != '' && !Session::newInstance()->_get('seeBy')) {
        
$mSearch Search::newInstance();
        
$query_elements = (array) json_decode($mSearch->toJson());
    
        
$mSearch->addJoinTable(count($query_elements['tables_join']), sprintf("(SELECT DISTINCT(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->addLocale('%');
        
$mSearch->order("des.relevance DESC, dt_pub_date""DESC"); 
    }

    
Session::newInstance()->_drop('seeBy');
}

osc_add_hook('search_conditions''cust_refined_pattern_search');

function 
cust_alerts_locale_hack_start() {

    if (
osc_get_osclass_section() == "alerts") {
        
View::newInstance()->_exportVariableToView('aUserLocale'Session::newInstance()->_get('userLocale'));
        
Session::newInstance()->_set('userLocale''%');
    }

    
// Detect See By link     
    
if (Session::newInstance()->_get('seeBy') == '')  Session::newInstance()->_set('seeBy', (Params::getParam('seeBy') ? 0));
    
Params::unsetParam('seeBy');
}

osc_add_hook('init''cust_alerts_locale_hack_start');

function 
cust_alerts_locale_hack_end($conditions) {

    if (
osc_get_osclass_section() == "alerts") {
        
Session::newInstance()->_set('userLocale'View::newInstance()->_get('aUserLocale'));
    }

    return 
$conditions
}

osc_add_filter('sql_search_item_conditions''cust_alerts_locale_hack_end');

function 
cust_seeBy_link_add_identifier() { ?>

    <script type="text/javascript">
        $(".see_by a").on('click', function(e) {
            e.preventDefault();
            window.location = $(this).prop('href') + '?seeBy=1';
        })
    </script>
<?php  }

osc_add_hook('footer''cust_seeBy_link_add_identifier');
?>


6th version (Alerts compatible - no duplicate ads, Multilanguage on User Alerts), no Sorting by relevance on See By (little bug)

Code: [Select]
<?php
function cust_refined_pattern_search($params) {
    
    if (
$params['sPattern'] != '' && !Session::newInstance()->_get('seeBy')) {
        
$mSearch Search::newInstance();
        
$mSearch->addJoinTablenullsprintf("(SELECT DISTINCT(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->addLocale('%');
        
$mSearch->order("des.relevance DESC, dt_pub_date""DESC"); 
    }

    
Session::newInstance()->_drop('seeBy');
}

osc_add_hook('search_conditions''cust_refined_pattern_search');

function 
cust_alerts_locale_hack_start() {

    if (
osc_get_osclass_section() == "alerts") {
        
View::newInstance()->_exportVariableToView('aUserLocale'Session::newInstance()->_get('userLocale'));
        
Session::newInstance()->_set('userLocale''%');
    }

    
// Detect See By link     
    
if (Session::newInstance()->_get('seeBy') == '')  Session::newInstance()->_set('seeBy', (Params::getParam('seeBy') ? 0));
    
Params::unsetParam('seeBy');
}

osc_add_hook('init''cust_alerts_locale_hack_start');

function 
cust_alerts_locale_hack_end($conditions) {

    if (
osc_get_osclass_section() == "alerts") {
        
Session::newInstance()->_set('userLocale'View::newInstance()->_get('aUserLocale'));
    }

    return 
$conditions
}

osc_add_filter('sql_search_item_conditions''cust_alerts_locale_hack_end');

function 
cust_seeBy_link_add_identifier() { ?>

    <script type="text/javascript">
        $(".see_by a").on('click', function(e) {
            e.preventDefault();
            window.location = $(this).prop('href') + '/?seeBy=1';
        })
    </script>
<?php  }

osc_add_hook('footer''cust_seeBy_link_add_identifier');
?>


5th version (Alerts compatible - no duplicate ads, Multilanguage on User Alerts), no Sorting by relevance on See By (incomplete)

Code: [Select]
<?php
function cust_refined_pattern_search($params) {

    if (
$params['sPattern'] != '' && !Params::existParam('sOrder')) {
        
$mSearch Search::newInstance();
        
$mSearch->addJoinTablenullsprintf("(SELECT DISTINCT(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->addLocale('%');
        
$mSearch->order("des.relevance DESC, dt_pub_date""DESC");
    }
}

osc_add_hook('search_conditions''cust_refined_pattern_search');

function 
cust_alerts_locale_hack_start() {
    
    if (
osc_get_osclass_section() == "alerts") {
        
View::newInstance()->_exportVariableToView('aUserLocale'Session::newInstance()->_get('userLocale'));
        
Session::newInstance()->_set('userLocale''%');
    }
}

osc_add_hook('init''cust_alerts_locale_hack_start'); 

function 
cust_alerts_locale_hack_end($conditions) {

    if (
osc_get_osclass_section() == "alerts") {
        
Session::newInstance()->_set('userLocale'View::newInstance()->_get('aUserLocale'));
    }
    
    return 
$conditions;
}

osc_add_filter('sql_search_item_conditions''cust_alerts_locale_hack_end');
?>


Well, first, I've realized that my previous solution to include all languages in the search could retrieve same ad several times, so I've added now a GROUP BY to prevent that happening.

And regarding your request for including all languages plus relevance ordering, here it's the solution (of course, use one or another):

4th version (Alerts compatible -no duplicate ads, Multilanguage on User Alerts)

Code: [Select]
<?php
function cust_refined_pattern_search($params) {

    if (
$params['sPattern'] != '') {
        
$mSearch Search::newInstance();
        
$mSearch->addJoinTablenullsprintf("(SELECT DISTINCT(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->addLocale('%');
        
$mSearch->order("des.relevance DESC, dt_pub_date""DESC");
    }
}

osc_add_hook('search_conditions''cust_refined_pattern_search');

function 
cust_alerts_locale_hack_start() {
    
    if (
osc_get_osclass_section() == "alerts") {
        
View::newInstance()->_exportVariableToView('aUserLocale'Session::newInstance()->_get('userLocale'));
        
Session::newInstance()->_set('userLocale''%');
    }
}

osc_add_hook('init''cust_alerts_locale_hack_start'); 

function 
cust_alerts_locale_hack_end($conditions) {

    if (
osc_get_osclass_section() == "alerts") {
        
Session::newInstance()->_set('userLocale'View::newInstance()->_get('aUserLocale'));
    }
    
    return 
$conditions;
}

osc_add_filter('sql_search_item_conditions''cust_alerts_locale_hack_end');
?>


3rd version (Alerts compatible -no duplicate ads, No multilanguage on User Alerts)

Code: [Select]
<?php
function cust_refined_pattern_search($params) {

    
$mSearch =  Search::newInstance();

    if (
$params['sPattern'] != '') {
        
$mSearch->addJoinTablenullsprintf("(SELECT DISTINCT(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->addLocale('%');
        
$mSearch->addGroupBy("pk_i_id");
        
$mSearch->order("des.relevance DESC, dt_pub_date""DESC");
    }
}

osc_add_hook('search_conditions''cust_refined_pattern_search');

function 
cust_clean_duplicate_ads_user_alerts() {
    
    
$clean_alerts View::newInstance()->_get('alerts');

    if (
$clean_alerts) {
        foreach (
$clean_alerts as $key => $alert) {

            
$outputArray = array();
            
$keysArray = array();
            foreach (
$clean_alerts[$key]['items'] as $innerArray) {
                if (!
in_array($innerArray['pk_i_id'], $keysArray)) {
                    
$keysArray[] = $innerArray['pk_i_id'];
                    
$outputArray[] = $innerArray;
                }
            }

            
$clean_alerts[$key]['items'] = $outputArray;
        }

    
View::newInstance()->_exportVariableToView('alerts'$clean_alerts);
    }  
}

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


2nd version (Alerts compatible -but including duplicate ads under certain circumstances)

Code: [Select]
<?php
function cust_refined_pattern_search($params) {

    
$mSearch =  Search::newInstance();

    if (
$params['sPattern'] != '') {
        
$mSearch->addJoinTablenullsprintf("(SELECT DISTINCT(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->addLocale('%');
        
$mSearch->order("des.relevance DESC, dt_pub_date""DESC");
    }
}

osc_add_hook('search_conditions''cust_refined_pattern_search');
?>

1st version (Alerts uncompatible)

Code: [Select]
<?php
function cust_refined_pattern_search($params) {
    
$mSearch =  Search::newInstance();
    
    if (
$params['sPattern'] != '') {
        
$mSearch->addFieldsprintf("MATCH(d.s_title, d.s_description) AGAINST('%s') AS relevance"$params['sPattern']) );
        
$mSearch->addLocale('%');
        
$mSearch->order("relevance DESC, dt_pub_date""DESC");
        
$mSearch->addGroupBy("pk_i_id");
    }
}

osc_add_hook('search_conditions''cust_refined_pattern_search');
?>

Regards
« Last Edit: February 14, 2017, 06:17:00 pm by teseo »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Search Problem OC 3.5.3
« Reply #5 on: January 17, 2015, 07:47:35 pm »
Hi, sorry to butt in but I always thought the search was done on solely the string that was being input by the user no matter what language.

So first it's good to see a better understanding of the search thanks to nex23 and great to have a solution however in this particular case I wonder if this should not just be an Admin option?  ::)

I mean let admin decide whether a search will be language dependable or cross languages.
Can we make this into a plugin or even better how can we get this in the next updated Osclass? (Basic yet important functionality)

Just an example, we have lots of people not speaking the dutch language so they could be using english as their site language but living in The Netherlands I WANT them to be able to search on dutch terms having the site in english....

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Search Problem OC 3.5.3
« Reply #6 on: January 17, 2015, 08:50:07 pm »
Well, you already have the functions here, it's just a matter of moving them to a proper plugin. ;) Myself, I haven't much time, so I find solutions and then it is "Add this at the very bottom of your theme functions.php (take care not to leave blank lines after this)" for me :D

Regards

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Search Problem OC 3.5.3
« Reply #7 on: January 17, 2015, 10:26:58 pm »
I know teseo, I moved it towards guardians of code because I think this really should be core Admin. 
Now I'm waiting for _Conejo to respond.... 8)

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Search Problem OC 3.5.3
« Reply #8 on: March 22, 2015, 07:15:38 pm »
Just wanted to post a warning about this one, using code underneith (inside quote) did break my 'Alert Saving' in search but the earlier posted solution doesn't so maybe the 'relevance' part is causing this breaking? Anyway, if you want to use this code my advise would be to stick with the first solution offered:

Code: [Select]
function cust_pattern_search_all_locales($params) {
    $mSearch =  Search::newInstance();
   
    if ($params['sPattern'] != '') {
        $mSearch->addLocale('%');
        $mSearch->addGroupBy("pk_i_id");
    }
}

osc_add_hook('search_conditions', 'cust_pattern_search_all_locales');

Regards,
Eric

Well, first, I've realized that my previous solution to include all languages in the search could retrieve same ad several times, so I've added now a GROUP BY to prevent that happening.

And regarding your request for including all languages plus relevance ordering, here it's the solution (of course, use one or another):

Code: [Select]
<?php
function cust_refined_pattern_search($params) {
    
$mSearch =  Search::newInstance();
    
    if (
$params['sPattern'] != '') {
        
$mSearch->addFieldsprintf("MATCH(d.s_title, d.s_description) AGAINST('%s') AS relevance"$params['sPattern']) );
        
$mSearch->addLocale('%');
        
$mSearch->order("relevance DESC, dt_pub_date""DESC");
        
$mSearch->addGroupBy("pk_i_id");
    }
}

osc_add_hook('search_conditions''cust_refined_pattern_search');
?>

Regards

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Search Problem OC 3.5.3
« Reply #9 on: March 22, 2015, 08:41:59 pm »
Hi,

No, none of them will work for alerts, it's just alerts aren't programmed to really retain all data on the search query. The first function won't keep "search in all languages" and the second will provoke an error (ORDER including a missing "relevance" field present in the original query but not in the stored alert).

No workaround for this I'm afraid, unless you were to modify a couple of core files.

Regards


SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Search Problem OC 3.5.3
« Reply #10 on: March 23, 2015, 01:50:21 am »
..... :( So actually a nice fix independant locale search is not working with the saving of Alerts..... a sad day today!  :-X

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Search Problem OC 3.5.3
« Reply #11 on: March 23, 2015, 02:23:28 am »
Well, took me a while, but in the end it was not impossible to solve. :)

Please check the second versions of both methods in the posts above and tell me if Alerts are working now (I've kept old versions, it might be useful to be able to compare them).

Regards

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Search Problem OC 3.5.3
« Reply #12 on: March 23, 2015, 09:19:15 pm »
Nice!  :)

I tested the latest with 'relevance' inthere and my Alert is being saved as expected but I am unable to test it with actually more than 1 language at the moment. For now I would say SUCCESS and big thank you for taking the time figuring it out, no more broken Alerts.

 8)

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Search Problem OC 3.5.3
« Reply #13 on: March 28, 2015, 07:05:26 pm »
EDIT: I have to stand correct still, the Alert IS working but in the search result the same ad was shown twice which is not good so I added the group by, that did the trick for the search results BUT now I have a working search and a working Alert where the Alert is showing the ad twice!  ??? So this means that the Alert query also needs a group by somehow when watching your own Alerts in private user menu.

So there are still some minor issues to solve and I was wondering if any crons would be affected as well?

I used the following fixed code and I did a text search that should only return 1 ad (also has premium status):
Code: [Select]
function cust_refined_pattern_search($params) {

    $mSearch =  Search::newInstance();

    if (isset($params['sPattern'])) {
        $mSearch->addJoinTable( null, sprintf("(SELECT fk_i_item_id, MATCH(s_title, s_description) AGAINST('%s') AS relevance FROM oc_t_item_description ) des", $params['sPattern']), 'des.fk_i_item_id = oc_t_item.pk_i_id', 'INNER' );
        $mSearch->addLocale('%');
        $mSearch->order("des.relevance DESC, dt_pub_date", "DESC");
    }
}

This gave me a double result so I added this: $mSearch->addGroupBy("pk_i_id");
Now search is doing okay, the alert gets saved but is showing the double result  :D


Regards,
Eric

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Search Problem OC 3.5.3
« Reply #14 on: March 28, 2015, 10:39:28 pm »
You've ruined my saturday...  >:( :D

Well, seems the problem of duplicate ads appears when an ad has non-empty description in at least two languages. Indeed adding a GROUP BY solves the issue on normal search pages, but with alerts there's the same problem as my first version of the relevance variant (there was that no new fields are stored on alerts table, here is the GROUP BY, same case).

So, the only solution I've found with no core modifications is to clean up duplicated ads on User Alerts view, adding a new function cust_clean_duplicate_ads_user_alerts(), check my 3rd version:

http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113778/#msg113778

Now, this seems to be working fine for User Dashboard, but I don't know if mailed alerts would still be affected. ??? I leave to you to check that, my Osclass internal crons don't like me... :D

Regards