Author Topic: [1.7.9] Fix for search  (Read 21082 times)

0 Members and 1 Guest are viewing this topic.

Offline kai

  • Administrator
  • Addicted member
  • *****
  • Posts: 1.421
    • View Profile
    • 4images - Image Gallery Management System
[1.7.9] Fix for search
« on: January 05, 2011, 11:25:59 AM »
In 4images 1.7.9 the search with more than one keyword, the use of operators (AND OR NOT) and two-word-keywords like "red car" is not working properly.
To fix this please apply this patch to the 3 files:

/includes/functions.php
/search.php
/includes/search_utils.php

The patched files are attached to this post (see below).
The fix will also be included in the next release of 4images.

Tip: If you want to search for a two-word-keyword like "red car", then you have to enter the ".



1.) search in /includes/functions.php:


foreach ($split_keywords as $key => $val) {
	
$keywords .= (($keywords != "" ) ? ", " "")."<a href=\"".$site_sess->url(ROOT_PATH."search.php?search_keywords=".urlencode($val))."\">".format_text($val2)."</a>";

and replace with:

    
foreach ($split_keywords as $key => $val) {
      
$url_val $val;
      if (
strpos($url_val' ') !== false) {
        
$url_val '"' $url_val '"';
      }
      
$keywords .= (($keywords != "" ) ? ", " "")."<a href=\"".$site_sess->url(ROOT_PATH."search.php?search_keywords=".urlencode($url_val))."\">".format_text($val2)."</a>";



2.) search in /search.php:


$split_words 
prepare_searchwords($search_keywordstrue);

and replace with:

$split_words 
prepare_searchwords_for_search($search_keywords);



3.) in /includes/search_utils.php:

search for

function prepare_searchwords($val$for_search false)

insert above:

function prepare_searchwords_for_search($val)
{
	
$val strip_tags(trim(stripslashes($val)));
	
$val convert_special($val);
	
$val strtolower($val);
	
$val str_replace(array('+''-'), array(' and '' not '), $val);
	
$val preg_replace('/\s+/'' '$val);

	
$tokens = array();
	
for (
$nextToken strtok($val' '); $nextToken !== false$nextToken strtok(' ')) {
	
	
if (
$nextToken[0] == '"') {
	
	
	
$nextToken $nextToken[strlen($nextToken)-1] == '"' substr($nextToken1, -1) : substr($nextToken1) . ' ' strtok('"');
	
	
}
	
	
$tokens[] = $nextToken;
	
}
	
return 
$tokens;
}


search for
"#[\n\t\r^\$\(\)<>\"\|@\?%~\+\.\[\]{}:\/=!§\\\\]+#s"

and replace with
"#[\n\t\r^\$\(\)<>\"\|,@\?%~\+\.\[\]{}:\/=!§\\\\]+#s"


3.1) search:

function prepare_searchwords($val$for_search false)
{

insert below:

  
// Backwards compatibility
  
if ($for_search) {
      return 
prepare_searchwords_for_search($val);
  }


3.2) search:

    
if ($for_search) {
      
$search_array = array(
        
"/\s+\+/",
        
"/\s+\-/"
      
);

      
$replace_array = array(
        
" and ",
        
" not "
      
);

      
$val preg_replace($search_array$replace_array$val);
    } else {
      
$val str_replace("*"""$val);
    }

and replace with:

    $val 
str_replace("*"""$val);


3.3) search:

      array_walk
($split_words'trim_value');

and replace with:

      $split_words 
array_map('trim'$split_words);
      
$split_words array_map('strip_tags'$split_words);
      
$split_words array_map('convert_special'$split_words);
      
$split_words array_map('strtolower'$split_words);


3.4) search:

    
if ($for_search && ($word == "and" || $word == "und" || $word == "or" || $word == "oder" || $word == "not")) {
      
$clean_words[] = $word;

and replace with:

    
if ($word == "and" || $word == "und" || $word == "or" || $word == "oder" || $word == "not") {


3.5) search and remove:

  
}

  if (
$for_search) {
    
// Add whole string for image_keyword search
    
$clean_words[] = implode(' '$clean_words);

« Last Edit: January 17, 2011, 01:31:01 PM by kai »
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline x23piracy

  • Sr. Member
  • ****
  • Posts: 420
    • View Profile
    • FHG
Re: [1.7.9] Fix for search
« Reply #1 on: January 05, 2011, 01:27:02 PM »
Hallo Kai,

3.3) search:

      array_walk
($split_words'trim_value');

and replace:

      $split_words 
array_map('trim'$split_words);
      
$split_words array_map('strip_tags'$split_words);
      
$split_words array_map('convert_special'$split_words);
      
$split_words array_map('strtolower'$split_words);


hier stimmt was nicht ersteres ist nicht vorhanden und letzeres ist bereits vorhanden...!


Gruß Jens

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!

--(◔̯◔)--

Rembrandt

  • Guest
Re: [1.7.9] Fix for search
« Reply #2 on: January 05, 2011, 01:53:02 PM »
....hier stimmt was nicht ersteres ist nicht vorhanden und letzeres ist bereits vorhanden...!

das ist vorhanden weil du schon einen fix eingespielt hast:  http://www.4homepages.de/forum/index.php?topic=28430.msg153554#msg153554
wenn du dir die aktuelle version V.1.7.9 herunterladest wirst du sehen das diese zeilen vorhanden sind.

Alternativ kannst du dir die "search_utils.php" inkl. beider patches aus dem anhang herrunter laden.

mfg Andi

Offline comicart

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: [1.7.9] Fix for search
« Reply #3 on: January 05, 2011, 08:52:02 PM »
I downloaded the files above and replaced them on my server.
It seems "two word" searches in quotes do not work for me. AND searches do work.

For example - if I search for Green Lantern, I get everything with green plus everything with lantern. - the correct search results.
If I search Green AND Lantern I get only items with both works - the correct search results.

But if I search "Green Lantern" I get no results at all.
http://alrioart.com/search.php?search_keywords=%22green%20lantern%22

Terry

Offline kai

  • Administrator
  • Addicted member
  • *****
  • Posts: 1.421
    • View Profile
    • 4images - Image Gallery Management System
Re: [1.7.9] Fix for search
« Reply #4 on: January 06, 2011, 12:12:33 AM »
@comicart: the pictures on your site don't have any keywords. that's why ;)
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline comicart

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: [1.7.9] Fix for search
« Reply #5 on: January 06, 2011, 12:41:08 AM »
the quotes only searches Keywords?
Oh - sorry  :oops:

You're right - I don't use them. I was hoping that "green lantern" would return the same as Green AND Lantern.
Is there a mod for that?
:)

T

Offline Wuff

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: [1.7.9] Fix for search
« Reply #6 on: April 04, 2011, 11:39:05 AM »
Hallo,
ich hab die aktuelle Version, habe aber trotzdem die 3 Anhänge hier bei mir aktualisiert......da meine Suchfunktion nicht so funktionierte wie sie sollte, aber
leider gehen trotz Schlüsselwörter die Funktionen AND und NOT nicht - auch nicht wenn
ich UND und NICHT eingebe  :?
woran könnte das liegen?