Advertisement:

Author Topic: IMPORTANT - How to Have a really funcional Search  (Read 10219 times)

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #15 on: December 14, 2014, 12:44:48 am »
Yup, this worked flawlessly up to Osclass 3.4.2 but something must have changed in latest version (hopefully for the best, we'll see) ???

I'll study this tomorrow, regards.

darmeth

  • Jr. Member
  • **
  • Posts: 75
Re: IMPORTANT - How to Have a really funcional Search
« Reply #16 on: December 14, 2014, 01:47:33 am »
Thanks for all your help Teseo

brenosilver

  • Newbie
  • *
  • Posts: 21
Re: IMPORTANT - How to Have a really funcional Search
« Reply #17 on: December 16, 2014, 11:02:30 pm »
On v3.4.3 doesn't work =(

Looking at the commit history https://github.com/osclass/Osclass/commit/a5bf12853eca96331ddb3160eb24a6db6a888495 They did change oc-includes/osclass/controller/search.php
« Last Edit: December 16, 2014, 11:15:01 pm by brenosilver »

darmeth

  • Jr. Member
  • **
  • Posts: 75
Re: IMPORTANT - How to Have a really funcional Search
« Reply #18 on: December 17, 2014, 02:55:37 am »
 :(
I've been trying to read more about searching MySQL ...it is a very tough nut to crack! The reason I have seen over and over is because too many wildcards plus too many rows in the tables can make the search and server slow down a lot.

I think I will put this one to sleep now and perhaps revisit it in the future when the traffic and listings pickup. It seems that the best solution is to have a separate table that is used to index the search terms and every search will query only that table.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #19 on: December 18, 2014, 09:42:12 pm »
***CORRECTED***

Hi,

Sorry for the delay, but my computer had a major accident,  :o still recovering, but I'm back...

In the end this was no big issue, just tested this on latest Osclass 3.5.3.

Add this at the very bottom of your theme functions.php (take care not to leave blank lines after this):

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

    if (@
$params['sPattern']) {
        
$mSearch =  Search::newInstance();
        
$query_elements = (array) json_decode($mSearch->toJson());
    
        
$query_elements['sPattern'] = str_replace(' ''* '$query_elements['sPattern']) . '*';
    
        
$mSearch->setJsonAlert($query_elements);
    }
}

osc_add_hook('search_conditions''cust_search_keyword_wildcard'10);  
?>


Regards
« Last Edit: September 23, 2015, 01:27:12 pm by teseo »

Adyyda

  • Sr. Member
  • ****
  • Posts: 435
Re: IMPORTANT - How to Have a really funcional Search
« Reply #20 on: December 18, 2014, 10:21:59 pm »
Hi,

Sorry for the delay, but my computer had a major accident,  :o still recovering, but I'm back...

In the end this was no big issue, just tested this on latest Osclass 3.5.3.

Add this at the very bottom of your theme functions.php (take care not to leave blank lines after this):

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

    if (
$params['sPattern']) {
        
$mSearch =  Search::newInstance();
        
$query_elements = (array) json_decode($mSearch->toJson());
    
        
$query_elements['sPattern'] = str_replace(' ''* '$query_elements['sPattern']) . '*';
    
        
$mSearch->setJsonAlert($query_elements);
    }
}

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


Regards

Can you tune it up a little?
Word "Apple"
If i search for "apple" works ok with your fix.
If i search for "pple", no results - so can you fix this as well? Thanks

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #21 on: December 18, 2014, 10:39:04 pm »
Not possible, regards

Adyyda

  • Sr. Member
  • ****
  • Posts: 435
Re: IMPORTANT - How to Have a really funcional Search
« Reply #22 on: December 18, 2014, 11:22:06 pm »

darmeth

  • Jr. Member
  • **
  • Posts: 75
Re: IMPORTANT - How to Have a really funcional Search
« Reply #23 on: January 10, 2015, 07:08:23 pm »
@teseo - sorry for the delay in replying. I have just added this and tested and it works 100%. Many thanks again for your help.

ricardiinhu

  • Newbie
  • *
  • Posts: 8
Re: IMPORTANT - How to Have a really funcional Search
« Reply #24 on: April 29, 2015, 07:00:47 am »
hey teseo, thank you!! i had this problem too and the solution you gave works fine!!
thanks a lot!!

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #25 on: April 29, 2015, 01:55:40 pm »
You're welcome. :) Regards.

tims

  • Guest
Re: IMPORTANT - How to Have a really funcional Search
« Reply #26 on: April 30, 2015, 04:27:06 pm »
Hello teseo. I don't know if this is right to ask this question in this tread but do you know how to add the user/contact name to the search? I search already the how forum and ask it so many times but no one can answer it or demo how to do it. Kindly help us. Thank you

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #27 on: April 30, 2015, 06:17:10 pm »
Hi,

Do you want that to add it to the method described on this thread or should it work with default search? ???

Regards

tims

  • Guest
Re: IMPORTANT - How to Have a really funcional Search
« Reply #28 on: May 01, 2015, 10:27:26 am »
If possible to the search of this thread. If not even in default will do. Thank you very much

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #29 on: May 01, 2015, 01:53:29 pm »
Well, first I have to warn you that this will be expensive in terms of time, because it adds to the normal query (made over a table built for that -t_description) a search over t_item table that it's not optimized for that kind on use. If there are many search terms, each one must be processed independently. So, I wouldn't recommend this unless you don't have a lot of ads or your server is rather powerful. ???

Anyway, here it is:

Add this at the very bottom of your theme functions.php (take care not to leave blank lines after this):

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

    if (
$params['sPattern']) {
        
$mSearch =  Search::newInstance();
        
$query_elements = (array) json_decode($mSearch->toJson());
        
$pattern $query_elements['sPattern'];


        
$query_elements['sPattern'] = str_replace(' ''* '$pattern) . '*';

        
$mSearch->setJsonAlert($query_elements);

        
// Search by Username too
        
$aPattern explode(' '$pattern);
        
$userNameCond '';

        foreach (
$aPattern as $word) {
            if (
$word$userNameCond .= sprintf(" || %st_item.s_contact_name LIKE '%s%%'"DB_TABLE_PREFIX$word);
        }

        
$mSearch->addConditions("1 = 1 " $userNameCond);
        
$mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id'); 
    }
}

osc_add_hook('search_conditions''cust_search_keyword_wildcard_with_username'1); 
?>


Regards