aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2016-02-13 18:36:55 +0100
committerplegall <plg@piwigo.org>2016-02-13 18:36:55 +0100
commit713bc497466a364c97c27398c0264699c4db2c9a (patch)
tree9ed7d8632b52a175f7c2c8d04debe8c3ffe3bc78
parenta6fbaf69c71c3b39666a6323c4c6bbb7cbb98310 (diff)
feature #355, apply search by word on tags
we "simulate" a search by tag, but we still perform a "search by words" AND "search by tags", which lead to different result compared to "word on title OR file OR description OR tags"
-rw-r--r--include/functions_search.inc.php36
-rw-r--r--search.php5
-rw-r--r--themes/default/template/search.tpl3
3 files changed, 42 insertions, 2 deletions
diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php
index 69c57faa7..9a9842e7d 100644
--- a/include/functions_search.inc.php
+++ b/include/functions_search.inc.php
@@ -90,7 +90,7 @@ function get_sql_search_clause($search)
}
}
- if (isset($search['fields']['allwords']))
+ if (isset($search['fields']['allwords']) and count($search['fields']['allwords']['fields']) > 0)
{
$fields = array('file', 'name', 'comment');
@@ -98,7 +98,7 @@ function get_sql_search_clause($search)
{
$fields = array_intersect($fields, $search['fields']['allwords']['fields']);
}
-
+
// in the OR mode, request bust be :
// ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
// OR (field1 LIKE '%word2%' OR field2 LIKE '%word2%'))
@@ -199,6 +199,7 @@ function get_sql_search_clause($search)
*/
function get_regular_search_results($search, $images_where='')
{
+ // echo '<pre>'; print_r($search); echo '</pre>';
global $conf;
$forbidden = get_sql_condition_FandF(
array
@@ -213,6 +214,37 @@ function get_regular_search_results($search, $images_where='')
$items = array();
$tag_items = array();
+ if (isset($search['fields']['search_in_tags']))
+ {
+ $word_clauses = array();
+ foreach ($search['fields']['allwords']['words'] as $word)
+ {
+ $word_clauses[] = "name LIKE '%".$word."%'";
+ }
+
+ $query = '
+SELECT
+ id
+ FROM '.TAGS_TABLE.'
+ WHERE '.implode(' OR ', $word_clauses).'
+;';
+ // echo '<pre>'.$query.'</pre>';
+ $tag_ids = query2array($query, null, 'id');
+
+ if (!isset($search['fields']['tags']))
+ {
+ $search['fields']['tags'] = array(
+ 'words' => $tag_ids,
+ 'mode' => 'OR',
+ );
+ }
+ else
+ {
+ $search['fields']['tags']['words'] = array_merge($search['fields']['tags']['words'], $tag_ids);
+ }
+ // echo '<pre>'; print_r($search); echo '</pre>';
+ }
+
if (isset($search['fields']['tags']))
{
$tag_items = get_image_ids_for_tags(
diff --git a/search.php b/search.php
index 9d33c7b3c..f8f0a1949 100644
--- a/search.php
+++ b/search.php
@@ -72,6 +72,11 @@ if (isset($_POST['submit']))
'mode' => $_POST['mode'],
'fields' => $_POST['fields'],
);
+
+ if (isset($_POST['search_in_tags']))
+ {
+ $search['fields']['search_in_tags'] = true;
+ }
}
if (isset($_POST['tags']))
diff --git a/themes/default/template/search.tpl b/themes/default/template/search.tpl
index 1a12e9832..4129746bd 100644
--- a/themes/default/template/search.tpl
+++ b/themes/default/template/search.tpl
@@ -47,6 +47,9 @@ jQuery(document).ready(function() {
<label><input type="checkbox" name="fields[]" value="name" checked="checked"> {'Photo title'|translate}</label>
<label><input type="checkbox" name="fields[]" value="comment" checked="checked"> {'Photo description'|translate}</label>
<label><input type="checkbox" name="fields[]" value="file" checked="checked"> {'File name'|translate}</label>
+{if isset($TAGS)}
+ <label><input type="checkbox" name="search_in_tags" value="tags"> {'Tags'|translate}</label>
+{/if}
</p>
</fieldset>