Author Topic: Howto set wildcard as default at beginning and end of search term?  (Read 4287 times)

0 Members and 1 Guest are viewing this topic.

Offline x23piracy

  • Sr. Member
  • ****
  • Posts: 420
    • View Profile
    • FHG
Hi,

is it possible to set wildcard as default for search terms the user inputs?

Example:

User searches for "apple" the script automatically add "*apple*"
if the user not allready used a wildcard at the beginnig and/or end of the search term.

Also nice would be an radio button option like: contains, begins and ends with...

Most users don't understand how to use the wildcard right or are to blind to see that the
wildcard option is available...



Greetz X23

Don't trust in md5 it's unsafe change your 4i galerys password hash algorythm! second pw db field, create new hashes over some time, deny old hash. Help members that cry, send informationen mail to the rest. Camouflage new pw hash in cookie. Done!

--(◔̯◔)--

Offline morfer

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: Howto set wildcard as default at beginning and end of search term?
« Reply #1 on: May 08, 2012, 11:35:44 AM »
This is exactly what I am looking for.

Any ideas? I am not a PHP professional...

Greetings
morfer

Offline morfer

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: Howto set wildcard as default at beginning and end of search term?
« Reply #2 on: May 24, 2012, 03:22:09 PM »
I got the solution:

Change in /includes/search_utils.php:

Insert in line 97:

function bettersearch($val)
{
$pattern "/[\s,\*]*\\\"([^\\\"]+)\\\"[\s,\*]*|" "[\s,\*]*'([^']+)'[\s,\*]*|" "[\s,\*]+/";
$words preg_split($pattern$val0PREG_SPLIT_NO_EMPTY PREG_SPLIT_DELIM_CAPTURE);
array_walk($wordscreate_function('&$v,$k''$v = "*" . $v . "*";'));
$words implode(" "$words);
return 
$words;
}


Change the code (line 106, after insert the mentioned function):

function prepare_searchwords_for_search($val)
{
    
$val clean_search_word($val);
    
// $val = preg_replace('/\s+/', ' ', $val);
    
$val bettersearch($val); //bettersearch fix

    
$stopword_list get_stopwords();

    
$tokens = array();
    
$modifier null;
    ...
    ...


What this fix does:
If your search is for example:
*Keyword1Keyword2Keyword3 Keyword4

The function generates:
*Keyword1* *Keyword2* *Keyword3* *Keyword4*