Advertisement:

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

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Search Problem OC 3.5.3
« Reply #30 on: March 23, 2016, 11:00:34 pm »
When you cheat the System, the System will get back at you sooner or later.  ;D :D

Well, let's hope you find out what's happening. :)

Regards

arcsales

  • Full Member
  • ***
  • Posts: 192
Re: Search Problem OC 3.5.3
« Reply #31 on: March 24, 2016, 02:16:37 pm »
I've tested version 7 on bender theme and its same result. After you subscribe to alert... not really sure how or why the language changes to english. Is it possible the system to avoid the original .po files and read directly from the source?

However i've tested your 3th version and it seem to be working fine and not mixing my language but...
1. There is no sorting by relevance
2. When unregistered user subscribe to search and the validation link is clicked from the email there is an error message "There was an error. Please contact us". Further investigation reveals that the subscription went fine but the alert is inactive and the admin have to activate it manually. (not important at the moment)

My question is - Can you combine 3th version to search by relevance too?
Im really eager to provide my users with relevant results of their searches.

Pigeon

  • Sr. Member
  • ****
  • Posts: 498
remove
« Reply #32 on: May 02, 2016, 03:06:43 am »
remove
« Last Edit: July 02, 2016, 10:23:09 am by Pigeon »

Pigeon

  • Sr. Member
  • ****
  • Posts: 498
remove
« Reply #33 on: May 02, 2016, 04:15:06 am »
remove
« Last Edit: July 02, 2016, 10:22:35 am by Pigeon »

Pigeon

  • Sr. Member
  • ****
  • Posts: 498
remove
« Reply #34 on: June 18, 2016, 10:33:14 pm »
remove
« Last Edit: July 02, 2016, 10:22:06 am by Pigeon »

liriosfamily

  • Newbie
  • *
  • Posts: 12
Re: Search Problem OC 3.5.3
« Reply #35 on: August 12, 2016, 04:08:33 am »
hello friends , which version works in Portuguese language Brazil -My search does not work

mnpartner

  • Newbie
  • *
  • Posts: 23
Re: Search Problem OC 3.5.3
« Reply #36 on: February 08, 2017, 12:00:49 pm »
***UPDATED with 9th version*** :o :) (19 April 2016)

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.

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 duplicates

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



Hello, I'm trying to use a script to find the 9 version, everything works fine, except "Subscribe to this search", when I try to "Subscribe to this search" have lost  site language, how can I fix it?

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Search Problem OC 3.5.3
« Reply #37 on: February 08, 2017, 04:44:53 pm »
Quote
when I try to "Subscribe to this search" have lost  site language

What do you mean by "lost  site language"? ??? Please try to be more specific.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Search Problem OC 3.5.3
« Reply #38 on: February 14, 2017, 06:25:55 pm »
Hi,

Hello, I'm trying to use a script to find the 9 version, everything works fine, except "Subscribe to this search", when I try to "Subscribe to this search" have lost  site language, how can I fix it?

I think I've fixed now this problem (and others that I found while reviewing the code). Now there's new versions for "multilanguage search" only:

http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113711/#msg113711 (5th version)

And "multilanguage search with sorting by relevance":

http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113778/#msg113778 (10th version).

I strongly recommend updating to anyone using these functions.

Regards

mnpartner

  • Newbie
  • *
  • Posts: 23
Re: Search Problem OC 3.5.3
« Reply #39 on: February 17, 2017, 12:35:36 am »
Hi,

Hello, I'm trying to use a script to find the 9 version, everything works fine, except "Subscribe to this search", when I try to "Subscribe to this search" have lost  site language, how can I fix it?

I think I've fixed now this problem (and others that I found while reviewing the code). Now there's new versions for "multilanguage search" only:


http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113711/#msg113711 (5th version)

And "multilanguage search with sorting by relevance":

http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113778/#msg113778 (10th version).

I strongly recommend updating to anyone using these functions.

Regards

***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 17, 2017, 12:39:23 am by mnpartner »

mnpartner

  • Newbie
  • *
  • Posts: 23
Re: Search Problem OC 3.5.3
« Reply #40 on: February 17, 2017, 12:41:30 am »
Hi,

Hello, I'm trying to use a script to find the 9 version, everything works fine, except "Subscribe to this search", when I try to "Subscribe to this search" have lost  site language, how can I fix it?

I think I've fixed now this problem (and others that I found while reviewing the code). Now there's new versions for "multilanguage search" only:

http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113711/#msg113711 (5th version)

And "multilanguage search with sorting by relevance":

http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113778/#msg113778 (10th version).

I strongly recommend updating to anyone using these functions.

Regards



Thank you. How about location translation???

zovi

  • Newbie
  • *
  • Posts: 11
Re: Search Problem OC 3.5.3
« Reply #41 on: February 02, 2018, 02:21:46 am »
Hey teseo
You are my HERO  :)

Thank you very much. Your Code is helping me a lot.

Great Job  8), thx

lexioo

  • Newbie
  • *
  • Posts: 1
Re: Search Problem OC 3.5.3
« Reply #42 on: November 01, 2018, 11:09:30 am »
Hi,

Hello, I'm trying to use a script to find the 9 version, everything works fine, except "Subscribe to this search", when I try to "Subscribe to this search" have lost  site language, how can I fix it?

I think I've fixed now this problem (and others that I found while reviewing the code). Now there's new versions for "multilanguage search" only:

http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113711/#msg113711 (5th version)

And "multilanguage search with sorting by relevance":

http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/msg113778/#msg113778 (10th version).

I strongly recommend updating to anyone using these functions.

Regards

Hello,
I copy the code into function.php but the search does not work on a multilingual site, where no title is specified, does not search in this language. How to start your function?

jazepsmalta

  • Newbie
  • *
  • Posts: 19
Re: Search Problem OC 3.5.3
« Reply #43 on: March 22, 2019, 10:33:21 pm »
Hello, there is a solution for the osclass version 3.8 ?
My search finds ads only in the language in which they were published.

For example: the customer has published Apple iPhone 7, he used the English language of the site.
I use Russian version, I write Apple iPhone 7 in the search box, and I don’t find anything in the Russian version.
I turn webpage to  English version, I write the same text "Apple iPhone 7".  and an ad finds.
How to fix this issue?

Thanks

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Search Problem OC 3.5.3
« Reply #44 on: March 22, 2019, 11:51:27 pm »
That is by design, you have to do custom changes in many places to make it work differently. I think there was one older post about instructions, not sure if it is still functional.