forum.coppermine-gallery.net

Dev Board => cpg1.4 Testing/Bugs => cpg1.4 Testing/Bugs: FIXED/CLOSED => Topic started by: Absoblogginlutely on November 24, 2005, 02:32:03 pm

Title: Bug: Keywords appear multiple times on the search page.
Post by: Absoblogginlutely on November 24, 2005, 02:32:03 pm
I have tagged some of my photos with keywords but when i go to my search page (http://www.absoblogginlutely.net/gallery/search.php) all the keywords appear multiple times, so I  have Brian listed 20+ times. I'm guessing there should be some form of unique within the search statement?
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: Absoblogginlutely on November 24, 2005, 06:18:01 pm
Using one of the other search pages I now have http://absoblogginlutely.net/gallery/search2.php which not only has 1 entry per word but also sizes the words ala flickr tags depending on the number of times it has been used. The code is messy and hacked but works.
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: Tranz on November 24, 2005, 06:21:01 pm
That's pretty cool. Would you mind sharing the code for search2?
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: artistsinhawaii on November 25, 2005, 12:44:27 am
I have tagged some of my photos with keywords but when i go to my search page (http://www.absoblogginlutely.net/gallery/search.php) all the keywords appear multiple times, so I  have Brian listed 20+ times. I'm guessing there should be some form of unique within the search statement?

Strange, this isn't happening on my setup at all. But then, I haven't uploaded all the updated files from the newly released, stable version into my setup yet.


Dennis
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: Nibbler on November 25, 2005, 12:51:30 am
include/keywords.inc.php

change

Code: [Select]
if (!in_array(strtolower($word),$keywords_array)) $keywords_array[] = $word;
to

Code: [Select]
if (!in_array($word = strtolower($word),$keywords_array)) $keywords_array[] = $word;
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: Absoblogginlutely on November 25, 2005, 02:02:57 am
the code i've used is as follows - note I'm not a php coder *at all* so there are probably some awful code things in there. I didn't care too much about the speed (I do a count of each keyword within the loop so there are a lot of database lookups) but as I don't have many keywords *I* don't really care but if someone else wants to improve that would be great.

Code: [Select]
<?php
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.2.0                                            //
// ------------------------------------------------------------------------- //
// Copyright (C) 2002,2003 Gregory DEMAR <gdemar@wanadoo.fr>                 //
// http://www.chezgreg.net/coppermine/                                       //
// ------------------------------------------------------------------------- //
// Updated by the Coppermine Dev Team                                        //
// (http://coppermine.sf.net/team/)                                          //
// see /docs/credits.html for details                                        //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify      //
// it under the terms of the GNU General Public License as published by      //
// the Free Software Foundation; either version 2 of the License, or         //
// (at your option) any later version.                                       //
// ------------------------------------------------------------------------- //

define('IN_COPPERMINE'true);
define('SEARCH_PHP'true);

require(
'include/init.inc.php');

pageheader($lang_search_php[0]);

starttable(500$lang_search_php[0]);
echo <<< EOT
        <tr><td>Please enter a keyword:</td></tr>
        <tr>
                <form method="get" action="thumbnails.php">
               <input type="hidden" name="album" value="search">
               <input type="hidden" name="type" value="full">
        <td class="tableb" align="center" height="60">
                <input type="input" style="width: 90%" name="search" maxlength="255" value="" class="textinput">
                </td>
        </tr>
        <tr>
                <td colspan="8" align="center" class="tablef">
                        <input type="submit" value="
{$lang_search_php[0]}" class="button">
                </td>
                </form>
        </tr>

EOT;
endtable();

echo 
"<br><br>" ;

// Select all keywords
starttable("80%""All keywords in the database"1);

$result mysql_query("select keywords from {$CONFIG['TABLE_PICTURES']}");

if (!
mysql_num_rows($result)) cpg_die(ERROR$lang_errors['non_exist_ap']);

// Find unique keywords
$keywords_array = array();

while (list(
$keywords) = mysql_fetch_row($result)) {
        
$array explode(" ",$keywords);

        foreach(
$array as $word)
        {
        if (!
in_array($word,$keywords_array)) $keywords_array[] = $word;
       }
}

sort($keywords_array);
$count count($keywords_array);

// Result to table
echo "<tr><td>" ;
for (
$i 0$i $count$i++) {
//get count of each word.
$keywordcountmysql_query("SELECT *  FROM {$CONFIG['TABLE_PICTURES']} where keywords like '%$keywords_array[$i]%'");
        
        
//First divide the number of times a keyword appears by 4, then round down to the nearest whole number. Add 10 to this number to get the pixel size and create a style for this magic number.
        //I couldn't work out how to do a select count * in sql and return data that works hence the my_sql_num_rows instead


        
echo "<a href=\"thumbnails.php?album=search&search=$keywords_array[$i]\" style=\"font-size: " .  floor(10+(mysql_num_rows($keywordcount)/4)) . "px;\">$keywords_array[$i]</a></font> ";
}
echo 
"</td></tr>" ;
endtable();

echo 
pagefooter();
ob_end_flush();

?>

Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: Nibbler on November 25, 2005, 01:17:26 pm
Please post mods on the mods board and bugs on the bugs board, it gets confusing otherwise. Can someone confirm my fix ?
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: Absoblogginlutely on November 25, 2005, 08:14:56 pm
Please post mods on the mods board and bugs on the bugs board, it gets confusing otherwise. Can someone confirm my fix ?
I can confirm this works fine. If someone wants to move my other code to the other forum then feel free.
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: flogghe on November 28, 2005, 11:23:12 pm
Thanks Nibbler, it does indeed work!!!  :)

Frederic
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: DJMaze on November 29, 2005, 04:04:59 am
I've opened the bug again since there are still issues.
strtolower() only works on ANSI characters, not utf8. Use utf_strtolower() instead.

Secondly it seems to be a bug related to PHP 4.4.1, could some confirm this so we can write a report at http://bugs.php.net
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: Nibbler on November 29, 2005, 10:23:55 am
What's the bug ?
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: artistsinhawaii on November 29, 2005, 10:27:25 am
I've opened the bug again since there are still issues.
strtolower() only works on ANSI characters, not utf8. Use utf_strtolower() instead.

Secondly it seems to be a bug related to PHP 4.4.1, could some confirm this so we can write a report at http://bugs.php.net


Woah, are you saying that we should replace all such instance in all 10 affected files?

Dennis.
Title: Re: Bug: Keywords appear multiple times on the search page.
Post by: DJMaze on November 29, 2005, 05:49:32 pm
Code: [Select]
if (!in_array(strtolower($word),$keywords_array)) $keywords_array[] = $word;to
Code: [Select]
if (!in_array($word = strtolower($word),$keywords_array)) $keywords_array[] = $word;

The above code stores the keywords in lowercase format inside $keywords_array.
This is because in_array() can only handle ANSI upper/lower casing
So Nibbler's solution makes shure $word is lowercase in any way BUT... since 1.4.x is UTF8 based strtolower() fails since it can't handle multibyte strings. Therefore the new utf_strtolower() function (and some others) are added to handle them even if the PHP functionality mb_* isn't available.

All keywords and keyword searching must be done in lowercase, especialy when you move on to MySQL 5.x since query searching on 'fo' doesn't find 'fo'.
MySQL 4.0.x is no problem since that only understands ANSI and is thereby case-insensitive. Anything else (including Postgre, Oracle, etc.) is case-sensitive.

That's why i re-opened the topic, the issue is wider then that small fix especialy now that there's MySQL 5 support