Advertisement:

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

tims

  • Guest
Re: IMPORTANT - How to Have a really funcional Search
« Reply #30 on: May 01, 2015, 03:32:57 pm »
Amazing Thank you. :)

tims

  • Guest
Re: IMPORTANT - How to Have a really funcional Search
« Reply #31 on: May 06, 2015, 04:42:53 am »
Hello teseo,

I would like to ask how can I limit the result? example I will only display the first 1000 result instead of showing all result.

I read something in sql to limit the result but I don't know how to apply it.

http://www.w3schools.com/sql/sql_top.asp


Thank you in advance

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #32 on: May 06, 2015, 01:05:54 pm »
Hi,

Are you still talking about my solutions here in this thread? ??? They don't change nor include LIMIT, that is set in the original search query that this code modifies. That original query usually takes the value you have set on Admin Dashboard / General ("Search page shows X listings at most").

Regards
 

tims

  • Guest
Re: IMPORTANT - How to Have a really funcional Search
« Reply #33 on: May 06, 2015, 01:15:48 pm »
Yes. Sorry I thought it can be modified so it will only show number of search result so let us say I have 10,000 search result it will only give the user the first 1000. Is that possible? I check the dashboard->general settings but that is "Search page shows X listings at most" is only limiting per page... example the page result is 10,000 it will be divide into pages that have 12 listing per page. What I want is to really limit the result 1000 only...

Thank you

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #34 on: May 06, 2015, 02:39:13 pm »
The vanilla mechanism already does something like that. Total results are 10*X in "Search page shows X listings at most", so if your "X" is 10 you'll have a total limited to 1000 results max.

Changing that default behaviour and having a fixed total independent of results per page, that you can't do it without modifying a core file. For instance, here there is info on how to get real total of ads (no limit), that should give you an idea:

http://forums.osclass.org/3-2-x/total-search-results/msg98573/#msg98573

Regards

misa22

  • Newbie
  • *
  • Posts: 15
Re: IMPORTANT - How to Have a really funcional Search
« Reply #35 on: May 06, 2015, 02:47:00 pm »
Hi i have another question too :) Sory for my english...
For real esteta full functional search is to have one autocomplete search with citis regions and  specific custom fields like "near the sea" etc. And with number of ads in this search resoults.
Off course another custom atributes are in search results like number of bedrooms etc.
Is this option possible in ossclass?

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #36 on: May 06, 2015, 02:55:52 pm »
@misa22

That has nothing to do with the real subject of this thread, please open a new one.

Regards

misa22

  • Newbie
  • *
  • Posts: 15
Re: IMPORTANT - How to Have a really funcional Search
« Reply #37 on: May 08, 2015, 10:03:23 am »
@teseo
ok sorry ;/

Adyyda

  • Sr. Member
  • ****
  • Posts: 435
Re: IMPORTANT - How to Have a really funcional Search
« Reply #38 on: September 22, 2015, 11:31:26 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'10);  
?>


Regards

Hello Teseo

I have added your code in functions.php, works ok but i have found via debug this error message
PHP Notice:  Undefined index: sPattern in /xxx/functions.php on line 261
and the line is
Code: [Select]
if ($params['sPattern']) {Can you fix this? Thanks

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #39 on: September 23, 2015, 01:29:33 pm »
Hi,

Yes, any variable that might or not might exist must be preceded with "@" to avoid a Warning appearing in error log:

Code: [Select]
if (@$params['sPattern']) {
Regards

Adyyda

  • Sr. Member
  • ****
  • Posts: 435
Re: IMPORTANT - How to Have a really funcional Search
« Reply #40 on: September 23, 2015, 01:44:29 pm »
Issue fixed. Thanks

Pirulina

  • Jr. Member
  • **
  • Posts: 78
  • What you give is what you take back in return!
Re: IMPORTANT - How to Have a really funcional Search
« Reply #41 on: March 01, 2016, 05:09:35 am »
Thanks a lot teseo, search box working like a charm! :) :)

gaissa

  • Newbie
  • *
  • Posts: 13
Re: IMPORTANT - How to Have a really funcional Search
« Reply #42 on: April 25, 2016, 08:36:54 am »
I added a % -prefix to the username-search so I am able to search 'sername' (and also 'usernam') instead of full username like: 'username'.

Code: [Select]
if ($word) $userNameCond .= sprintf(" || %st_item.s_contact_name LIKE '%s%%'", DB_TABLE_PREFIX, '%' . $word);
How to do the same for the Titles (and the other stuff like Description)? Any "simple" solution to this?
« Last Edit: April 27, 2016, 07:47:20 pm by gaissa »

jericcarino

  • Newbie
  • *
  • Posts: 2
Re: IMPORTANT - How to Have a really funcional Search
« Reply #43 on: May 12, 2016, 01:47:12 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


First of all, YOU SIR ARE A GENIUS! :D
A million thank yous to you. :)
When I search
SEARCH: PS
RESULT: PS4
Which is so freaking awesome and I love it! :D

But I have a problem when I'm searching for keywords with numbers.
Example:
SEARCH: S6
RESULT: Nothing
SEARCH: Galaxy
RESULT: Galaxy S6

I don't know what's wrong. Please help me out.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: IMPORTANT - How to Have a really funcional Search
« Reply #44 on: May 12, 2016, 06:41:05 pm »
Hi,

MySQL Fulltext search will discard keywords having less than X characters (on shared hosting that X is usually 4). Nothing you can do about it unless you have a VPS or dedicated server where you may change the value of that MySQL setting.

Regards