Search engine redesign, second part :

improvement: in category.php, an icon opening a popup display the list of
search rules.

modification: function get_search_array is responsible of search rules
retrieving from database. This function is called from get_sql_search_clause
and from search_rules.php

modification: ability to search multiple authors. Warning: this version of
search tool can't search author names including any blank space.


git-svn-id: http://piwigo.org/svn/trunk@1015 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
plegall 2006-01-27 22:40:51 +00:00
parent a8fd5ee6cf
commit 61668e4cf7
9 changed files with 378 additions and 30 deletions

View file

@ -165,6 +165,16 @@ $template->assign_vars(
'U_PROFILE'=> PHPWG_ROOT_PATH.'profile.php'
)
);
if (isset($page['cat']) and 'search' == $page['cat'])
{
$template->assign_block_vars(
'search_rules',
array(
'URL' => PHPWG_ROOT_PATH.'/search_rules.php?search_id='.$_GET['search'],
)
);
}
//-------------------------------------------------------------- external links
if (count($conf['links']) > 0)
{

View file

@ -772,6 +772,30 @@ function prepend_append_array_items($array, $prepend_str, $append_str)
return $array;
}
/**
* returns search rules stored into a serialized array in "search"
* table. Each search rules set is numericaly identified.
*
* @param int search_id
* @return array
*/
function get_search_array($search_id)
{
if (!is_numeric($search_id))
{
die('Search id must be an integer');
}
$query = '
SELECT rules
FROM '.SEARCH_TABLE.'
WHERE id = '.$search_id.'
;';
list($serialized_rules) = mysql_fetch_row(pwg_query($query));
return unserialize($serialized_rules);
}
/**
* returns the SQL clause from a search identifier
*
@ -783,24 +807,8 @@ function prepend_append_array_items($array, $prepend_str, $append_str)
*/
function get_sql_search_clause($search_id)
{
if (!is_numeric($search_id))
{
die('Search id must be an integer');
}
$search = get_search_array($search_id);
$query = '
SELECT rules
FROM '.SEARCH_TABLE.'
WHERE id = '.$_GET['search'].'
;';
list($serialized_rules) = mysql_fetch_row(pwg_query($query));
$search = unserialize($serialized_rules);
// echo '<pre>';
// print_r($search);
// echo '</pre>';
// SQL where clauses are stored in $clauses array during query
// construction
$clauses = array();

View file

@ -41,21 +41,22 @@ $lang['%d new elements'] = '%d new elements';
$lang['%d new users'] = '%d new users';
$lang['%d waiting elements'] = '%d waiting elements';
$lang['About'] = 'About';
$lang['At least one listed rule must be satisfied.'] = 'At least one listed rule must be satisfied.';
$lang['Author'] = 'Author';
$lang['Average rate'] = 'Average rate';
$lang['Categories'] = 'Categories';
$lang['Category'] = 'Category';
$lang['Close this window'] = 'Close this window';
$lang['Confirm Password'] = 'Confirm Password';
$lang['Connection'] = 'Connection';
$lang['Quick connect'] = 'Quick connect';
$lang['Connection settings'] = 'Connection settings';
$lang['Connection'] = 'Connection';
$lang['Contact webmaster'] = 'Contact webmaster';
$lang['Create a new account'] = 'Create a new account';
$lang['Created on'] = 'Created on';
$lang['Current password is wrong'] = 'Current password is wrong';
$lang['Dimensions'] = 'Dimensions';
$lang['Display'] = 'Display';
$lang['Each listed rule must be satisfied.'] = 'Each listed rule must be satisfied.';
$lang['Email address is missing'] = 'Email address is missing';
$lang['Email address'] = 'Email address';
$lang['Enter your personnal informations'] = 'Enter your personnal informations';
@ -85,12 +86,14 @@ $lang['Password forgotten'] = 'Password forgotten';
$lang['Password'] = 'Password';
$lang['PhpWebGallery Help'] = 'PhpWebGallery Help';
$lang['Profile'] = 'Profile';
$lang['Quick connect'] = 'Quick connect';
$lang['RSS feed'] = 'RSS feed';
$lang['Register'] = 'Register';
$lang['Registered on'] = 'Registered on';
$lang['Registration'] = 'Registration';
$lang['Reset'] = 'Reset';
$lang['Retrieve password'] = 'Retrieve password';
$lang['Search rules'] = 'Search rules';
$lang['Search'] = 'Search';
$lang['Send new password'] = 'Send new password';
$lang['Since'] = 'Since';
@ -108,9 +111,16 @@ $lang['add to caddie'] = 'add to caddie';
$lang['add_favorites_alt'] = 'Add to favorites';
$lang['add_favorites_hint'] = 'Add this picture to your favorites';
$lang['admin'] = 'Administration';
$lang['all'] = 'all';
$lang['all_categories'] = 'all categories';
$lang['already_rated'] = 'You\'ve already rated this item';
$lang['ascending'] = 'ascending';
$lang['author(s) : %s'] = 'author(s) : %s';
$lang['auto_expand'] = 'Expand all categories';
$lang['became available after %s (%s)'] = 'became available after %s (%s)';
$lang['became available before %s (%s)'] = 'became available before %s (%s)';
$lang['became available between %s (%s) and %s (%s)'] = 'became available between %s (%s) and %s (%s)';
$lang['became available on %s'] = 'became available on %s';
$lang['best_rated_cat'] = 'best rated';
$lang['best_rated_cat_hint'] = 'displays best rated items';
$lang['caddie'] = 'caddie';
@ -118,6 +128,7 @@ $lang['calendar'] = 'Calendar';
$lang['calendar_hint'] = 'displays each day with pictures, month per month';
$lang['calendar_picture_hint'] = 'displays pictures added on ';
$lang['categories'] = 'Categories';
$lang['comment date'] = 'comment date';
$lang['comment'] = 'Comment';
$lang['comment_added'] = 'Your comment has been registered';
$lang['comment_anti-flood'] = 'Anti-flood system : please wait for a moment before trying to post another comment';
@ -128,6 +139,10 @@ $lang['comments_add'] = 'Add a comment';
$lang['comments_del'] = 'delete this comment';
$lang['comments_title'] = 'Comments from the users of the site';
$lang['confirm_password_hint'] = 'You only have to confirm your new password if you wish to change it.';
$lang['created after %s (%s)'] = 'created after %s (%s)';
$lang['created before %s (%s)'] = 'created before %s (%s)';
$lang['created between %s (%s) and %s (%s)'] = 'created between %s (%s) and %s (%s)';
$lang['created on %s'] = 'created on %s';
$lang['customize'] = 'Customize';
$lang['customize_page_title'] = 'Your Gallery Customization ';
$lang['customize_title'] = 'Customization';
@ -142,11 +157,13 @@ $lang['days'] = 'days';
$lang['del_favorites_alt'] = 'Delete from favorites';
$lang['del_favorites_hint'] = 'Delete this picture from your favorites';
$lang['delete'] = 'Delete';
$lang['descending'] = 'descending';
$lang['download'] = 'download';
$lang['download_hint'] = 'download this file';
$lang['edit category informations'] = 'edit category informations';
$lang['edit'] = 'edit';
$lang['err_date'] = 'wrong date';
$lang['excluded'] = 'excluded';
$lang['favorite_cat'] = 'My favorites';
$lang['favorite_cat_hint'] = 'display my favorites pictures';
$lang['favorites'] = 'Favorites';
@ -168,6 +185,7 @@ $lang['ident_register'] = 'Register';
$lang['ident_title'] = 'ident_title';
$lang['identification'] = 'Identification';
$lang['images_available'] = 'images in this category';
$lang['included'] = 'included';
$lang['invalid_pwd'] = 'Invalid password!';
$lang['language']='Language';
$lang['last %d days'] = 'last %d days';
@ -210,6 +228,7 @@ $lang['password updated'] = 'password updated';
$lang['password'] = 'Password';
$lang['password_hint'] = 'You only have to give your password if you wish to change your e-mail';
$lang['periods_error'] = 'Recent period must be a positive integer value';
$lang['picture'] = 'picture';
$lang['picture_high'] = 'Click on the picture to see it in high definition';
$lang['picture_show_metadata'] = 'Show file metadata';
$lang['powered_by'] = 'Powered by';
@ -258,6 +277,7 @@ $lang['search_result'] = 'Search results';
$lang['search_sort'] = 'Sort results by';
$lang['search_subcats_included'] = 'Search in subcategroies';
$lang['search_title'] = 'Search';
$lang['searched words : %s'] = 'searched words : %s';
$lang['send_mail'] = 'Contact';
$lang['set as category representative'] = 'set as category representative';
$lang['show_nb_comments'] = 'Show number of comments';
@ -299,10 +319,4 @@ $lang['upload_username'] = 'Username';
$lang['useful when password forgotten'] = 'useful when password forgotten';
$lang['w_month'] = 'Month';
$lang['yes'] = 'Yes';
$lang['descending'] = 'descending';
$lang['all'] = 'all';
$lang['ascending'] = 'ascending';
$lang['comment date'] = 'comment date';
$lang['picture'] = 'picture';
?>

View file

@ -40,21 +40,22 @@ $lang['%d new comments'] = '%d nouveaux commentaires utilisateur';
$lang['%d new elements'] = '%d nouveaux éléments';
$lang['%d new users'] = '%d nouveaux utilisateurs';
$lang['About'] = 'À propos';
$lang['At least one listed rule must be satisfied.'] = 'Au moins un des critères doit être satisfait.';
$lang['Author'] = 'Auteur';
$lang['Average rate'] = 'Note moyenne';
$lang['Categories'] = 'Catégories';
$lang['Category'] = 'Catégorie';
$lang['Close this window'] = 'Fermer cette fenêtre';
$lang['Confirm Password'] = 'Confirmer le mot de passe';
$lang['Connection'] = 'Connexion';
$lang['Quick connect'] = 'Connexion rapide';
$lang['Connection settings'] = 'Paramètres de connexion';
$lang['Connection'] = 'Connexion';
$lang['Contact webmaster'] = 'Contacter le webmestre';
$lang['Create a new account'] = 'Créer un nouveau compte';
$lang['Created on'] = 'Créée le';
$lang['Current password is wrong'] = 'Erreur sur le mot de passe actuel';
$lang['Dimensions'] = 'Dimensions';
$lang['Display'] = 'Affichage';
$lang['Each listed rule must be satisfied.'] = 'Chaque critère doit être satisfait';
$lang['Email address is missing'] = 'L\'adresse e-mail manque';
$lang['Email address'] = 'Adresse e-mail';
$lang['Enter your personnal informations'] = 'Entrer vos informations personnelles';
@ -84,12 +85,14 @@ $lang['Password forgotten'] = 'Mot de passe oubli
$lang['Password'] = 'Mot de passe';
$lang['PhpWebGallery Help'] = 'Aide de PhpWebGallery';
$lang['Profile'] = 'Profil';
$lang['Quick connect'] = 'Connexion rapide';
$lang['RSS feed'] = 'flux RSS';
$lang['Register'] = 'S\'enregistrer';
$lang['Registered on'] = 'Enregistrée le';
$lang['Registration'] = 'Enregistrement';
$lang['Reset'] = 'Annuler';
$lang['Retrieve password'] = 'Récupérer un mot de passe';
$lang['Search rules'] = 'Critères de recherche';
$lang['Search'] = 'Rechercher';
$lang['Send new password'] = 'Envoyer le nouveau mot de passe';
$lang['Since'] = 'Depuis';
@ -111,7 +114,12 @@ $lang['all'] = 'tout';
$lang['all_categories'] = 'toutes les catégories';
$lang['already_rated'] = 'Vous avez déjà voté pour cette image';
$lang['ascending'] = 'croissant';
$lang['author(s) : %s'] = 'auteur(s) : %s';
$lang['auto_expand'] = 'Développer toutes les catégories';
$lang['became available after %s (%s)'] = 'mis à disposition après le %s (%s)';
$lang['became available before %s (%s)'] = 'mis à disposition avant le %s (%s)';
$lang['became available between %s (%s) and %s (%s)'] = 'mis à disposition entre le %s (%s) et le %s (%s)';
$lang['became available on %s'] = 'mis à disposition le %s';
$lang['best_rated_cat'] = 'Mieux notées';
$lang['best_rated_cat_hint'] = 'affiche les images les mieux notées';
$lang['caddie'] = 'Panier';
@ -130,6 +138,10 @@ $lang['comments_add'] = 'Ajouter un commentaire';
$lang['comments_del'] = 'Supprimer ce commentaire';
$lang['comments_title'] = 'Commentaires des utilisateurs';
$lang['confirm_password_hint'] = 'Vous n\'avez à confirmer votre mot de passe que si vous désirez en changer.';
$lang['created after %s (%s)'] = 'créée après le %s (%s)';
$lang['created before %s (%s)'] = 'créée avant le %s (%s)';
$lang['created between %s (%s) and %s (%s)'] = 'créée entre le %s (%s) et le %s (%s)';
$lang['created on %s'] = 'créée le %s';
$lang['customize'] = 'Personnaliser';
$lang['customize_page_title'] = 'Personnalisation de votre affichage ';
$lang['customize_title'] = 'Personnaliser';
@ -150,6 +162,7 @@ $lang['download_hint'] = 't
$lang['edit category informations'] = 'éditer les informations de cette catégorie';
$lang['edit'] = 'éditer';
$lang['err_date'] = 'date erronée';
$lang['excluded'] = 'exclus';
$lang['favorite_cat'] = 'Mes favorites';
$lang['favorite_cat_hint'] = 'afficher mes images favorites';
$lang['favorites'] = 'Favoris';
@ -171,6 +184,7 @@ $lang['ident_register'] = 'S\'enregistrer';
$lang['ident_title'] = 'Identification (FIXME)';
$lang['identification'] = 'Identification';
$lang['images_available'] = 'images dans cette catégorie';
$lang['included'] = 'inclus';
$lang['invalid_pwd'] = 'Mot de passe invalide !';
$lang['language'] = 'Langue';
$lang['last %d days'] = '%d derniers jours';
@ -262,6 +276,7 @@ $lang['search_result'] = 'R
$lang['search_sort'] = 'Trier les résultats de recherche selon';
$lang['search_subcats_included'] = 'Rechercher dans les sous-catégories';
$lang['search_title'] = 'Recherche';
$lang['searched words : %s'] = 'mots recherchés : %s';
$lang['send_mail'] = 'Contacter';
$lang['set as category representative'] = 'élire comme représentant de cette catégorie';
$lang['show_nb_comments'] = 'Montrer le nombre de commentaires';

View file

@ -64,7 +64,11 @@ if (isset($_POST['submit']))
if ($_POST['search_author'])
{
$search['fields']['author'] = array(
'words' => array($_POST['search_author']),
'words' => preg_split(
'/\s+/',
$_POST['search_author']
),
'mode' => 'OR',
);
}

243
search_rules.php Normal file
View file

@ -0,0 +1,243 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2005-09-27 23:57:14 +0200 (mar, 27 sep 2005) $
// | last modifier : $Author: plg $
// | revision : $Revision: 879 $
// +-----------------------------------------------------------------------+
// | 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 |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
/**
* returns language value 'included' or 'excluded' depending on boolean
* value. This function is useful only to make duplicate code shorter
*
* @param bool is_included
* @return string
*/
function inc_exc_str($is_included)
{
return $is_included ? l10n('included') : l10n('excluded');
}
// +-----------------------------------------------------------------------+
// | initialization |
// +-----------------------------------------------------------------------+
define('PHPWG_ROOT_PATH','./');
include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
$page['body_id'] = 'thePopuphelpPage';
$page['gallery_title'] = $title = l10n('PhpWebGallery Help');
include(PHPWG_ROOT_PATH.'include/page_header.php');
$template->set_filenames(array('search_rules' => 'search_rules.tpl'));
// +-----------------------------------------------------------------------+
// | Textual rules creation |
// +-----------------------------------------------------------------------+
// Rules are stored in database, serialized in an array. This array must be
// transformed into a list of textual rules.
$search = get_search_array($_GET['search_id']);
$template->assign_vars(
array(
'INTRODUCTION'
=> 'OR' == $search['mode']
? l10n('At least one listed rule must be satisfied.')
: l10n('Each listed rule must be satisfied.'),
)
);
if (isset($search['fields']['allwords']))
{
$template->assign_block_vars(
'words',
array(
'CONTENT' => sprintf(
l10n('searched words : %s'),
join(', ', $search['fields']['allwords']['words'])
)
)
);
}
if (isset($search['fields']['author']))
{
$template->assign_block_vars(
'words',
array(
'CONTENT' => sprintf(
l10n('author(s) : %s'),
join(', ', $search['fields']['author']['words'])
)
)
);
}
if (isset($search['fields']['cat']))
{
if ($search['fields']['cat']['sub_inc'])
{
// searching all the categories id of sub-categories
$cat_ids = get_subcat_ids($search['fields']['cat']['words']);
}
else
{
$cat_ids = $search['fields']['cat']['words'];
}
$template->assign_block_vars(
'categories',
array(
'LIST_INTRO' => l10n('categories'),
)
);
$query = '
SELECT id, uppercats, global_rank
FROM '.CATEGORIES_TABLE.'
WHERE id IN ('.
implode(',', $cat_ids).
')
;';
$result = pwg_query($query);
$categories = array();
if (!empty($result))
{
while ($row = mysql_fetch_array($result))
{
array_push($categories, $row);
}
}
usort($categories, 'global_rank_compare');
foreach ($categories as $category)
{
$template->assign_block_vars(
'categories.category',
array(
'NAME' => get_cat_display_name_cache(
$category['uppercats'],
'', // no url on category names
false // no blank replacement
)
)
);
}
}
foreach (array('date_available', 'date_creation') as $datefield)
{
if ('date_available' == $datefield)
{
$lang_items = array(
'date' => 'became available on %s',
'period' => 'became available between %s (%s) and %s (%s)',
'after' => 'became available after %s (%s)',
'before' => 'became available before %s (%s)',
);
}
elseif ('date_creation' == $datefield)
{
$lang_items = array(
'date' => 'created on %s',
'period' => 'created between %s (%s) and %s (%s)',
'after' => 'created after %s (%s)',
'before' => 'created before %s (%s)',
);
}
$keys = array(
'date' => $datefield,
'after' => $datefield.'-after',
'before' => $datefield.'-before',
);
if (isset($search['fields'][ $keys['date'] ]))
{
$template->assign_block_vars(
$datefield,
array(
'CONTENT' => sprintf(
l10n($lang_items['date']),
format_date($search['fields'][ $keys['date'] ])
),
)
);
}
elseif (isset($search['fields'][ $keys['before'] ])
and isset($search['fields'][ $keys['after'] ]))
{
$template->assign_block_vars(
$datefield,
array(
'CONTENT' => sprintf(
l10n($lang_items['period']),
format_date($search['fields'][ $keys['after'] ]['date']),
inc_exc_str($search['fields'][ $keys['after'] ]['inc']),
format_date($search['fields'][ $keys['before'] ]['date']),
inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
),
)
);
}
elseif (isset($search['fields'][ $keys['before'] ]))
{
$template->assign_block_vars(
$datefield,
array(
'CONTENT' => sprintf(
l10n($lang_items['before']),
format_date($search['fields'][ $keys['before'] ]['date']),
inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
),
)
);
}
elseif (isset($search['fields'][ $keys['after'] ]))
{
$template->assign_block_vars(
$datefield,
array(
'CONTENT' => sprintf(
l10n($lang_items['after']),
format_date($search['fields'][ $keys['after'] ]['date']),
inc_exc_str($search['fields'][ $keys['after'] ]['inc'])
)
)
);
}
}
// +-----------------------------------------------------------------------+
// | html code display |
// +-----------------------------------------------------------------------+
$template->parse('search_rules');
include(PHPWG_ROOT_PATH.'include/page_tail.php');
?>

View file

@ -107,15 +107,25 @@
<div class="titrePage">
<ul class="categoryActions">
<li>&nbsp;</li>
<!-- BEGIN caddie -->
<li><a href="{caddie.URL}" title="{lang:add to caddie}"><img src="{themeconf:icon_dir}/caddie_add.png" class="button" alt="{lang:caddie}"/></a></li>
<!-- END caddie -->
<!-- BEGIN edit -->
<li><a href="{edit.URL}" title="{lang:edit category informations}"><img src="{themeconf:icon_dir}/category_edit.png" class="button" alt="{lang:edit}"/></a></li>
<!-- END edit -->
<!-- BEGIN search_rules -->
<li><a href="{search_rules.URL}" style="border:none;" onclick="popuphelp(this.href); return false;" title="{lang:Search rules}"><img src="{themeconf:icon_dir}/search_rules.png" class="button" alt="(?)"></a></li>
<!-- END search_rules -->
</ul>
<h2>{TITLE}</h2>
</div>
<h2>{TITLE}</h2>
</div> <!-- content -->
<!-- BEGIN calendar -->
<div class="navigationBar">{calendar.YEARS_NAV_BAR}</div>
<div class="navigationBar">{calendar.MONTHS_NAV_BAR}</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,44 @@
<div id="content">
<h2>{lang:Search rules}</h2>
<p>{INTRODUCTION}</p>
<ul>
<!-- BEGIN words -->
<li>{words.CONTENT}</li>
<!-- END words -->
<!-- BEGIN author -->
<li>{author.CONTENT}</li>
<!-- END author -->
<!-- BEGIN date_creation -->
<li>{date_creation.CONTENT}</li>
<!-- END date_creation -->
<!-- BEGIN date_available -->
<li>{date_available.CONTENT}</li>
<!-- END date_available -->
<!-- BEGIN categories -->
<li>
<p>{categories.LIST_INTRO}</p>
<ul>
<!-- BEGIN category -->
<li>{categories.category.NAME}</li>
<!-- END category -->
</ul>
</li>
<!-- END categories -->
</ul>
</div> <!-- content -->
<p id="pageBottomActions">
<a href="#" onclick="window.close();" title="{lang:Close this window}">
<img src="{themeconf:icon_dir}/exit.png" class="button" alt="close">
</a>
</p>