Bug: Keywords appear multiple times on the search page. Bug: Keywords appear multiple times on the search page.
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Bug: Keywords appear multiple times on the search page.

Started by Absoblogginlutely, November 24, 2005, 02:32:03 PM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

Absoblogginlutely

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?

Absoblogginlutely

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.

Tranz

That's pretty cool. Would you mind sharing the code for search2?

artistsinhawaii

Quote from: 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?

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
Learn and live ... In January of 2011, after a botched stent attempt, the doctors told me I needed a multiple bypass surgery or I could die.  I told them I needed new doctors.

Nibbler

include/keywords.inc.php

change

if (!in_array(strtolower($word),$keywords_array)) $keywords_array[] = $word;

to

if (!in_array($word = strtolower($word),$keywords_array)) $keywords_array[] = $word;

Absoblogginlutely

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.


<?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();

?>


Nibbler

Please post mods on the mods board and bugs on the bugs board, it gets confusing otherwise. Can someone confirm my fix ?

Absoblogginlutely

Quote from: 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 ?
I can confirm this works fine. If someone wants to move my other code to the other forum then feel free.

flogghe

Kind regards,

Frederic Logghe
Webmaster MaritimeDigital Archive
http://www.ibiblio.org/maritime

DJMaze

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
There are 2 kinds of users in this world: satisfied and complainers.
Why do we never hear something from the satisfied users?
http://coppermine-gallery.net/forum/index.php?topic=24315.0


artistsinhawaii

Quote from: 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


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

Dennis.
Learn and live ... In January of 2011, after a botched stent attempt, the doctors told me I needed a multiple bypass surgery or I could die.  I told them I needed new doctors.

DJMaze

Quote from: Nibbler on November 25, 2005, 12:51:30 AM
if (!in_array(strtolower($word),$keywords_array)) $keywords_array[] = $word;
to
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 'fôo' doesn't find 'fÔo'.
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
There are 2 kinds of users in this world: satisfied and complainers.
Why do we never hear something from the satisfied users?
http://coppermine-gallery.net/forum/index.php?topic=24315.0