Skip to content

Commit 713bc49

Browse files
committed
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"
1 parent a6fbaf6 commit 713bc49

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

include/functions_search.inc.php

+34-2
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ function get_sql_search_clause($search)
9090
}
9191
}
9292

93-
if (isset($search['fields']['allwords']))
93+
if (isset($search['fields']['allwords']) and count($search['fields']['allwords']['fields']) > 0)
9494
{
9595
$fields = array('file', 'name', 'comment');
9696

9797
if (isset($search['fields']['allwords']['fields']) and count($search['fields']['allwords']['fields']) > 0)
9898
{
9999
$fields = array_intersect($fields, $search['fields']['allwords']['fields']);
100100
}
101-
101+
102102
// in the OR mode, request bust be :
103103
// ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
104104
// OR (field1 LIKE '%word2%' OR field2 LIKE '%word2%'))
@@ -199,6 +199,7 @@ function get_sql_search_clause($search)
199199
*/
200200
function get_regular_search_results($search, $images_where='')
201201
{
202+
// echo '<pre>'; print_r($search); echo '</pre>';
202203
global $conf;
203204
$forbidden = get_sql_condition_FandF(
204205
array
@@ -213,6 +214,37 @@ function get_regular_search_results($search, $images_where='')
213214
$items = array();
214215
$tag_items = array();
215216

217+
if (isset($search['fields']['search_in_tags']))
218+
{
219+
$word_clauses = array();
220+
foreach ($search['fields']['allwords']['words'] as $word)
221+
{
222+
$word_clauses[] = "name LIKE '%".$word."%'";
223+
}
224+
225+
$query = '
226+
SELECT
227+
id
228+
FROM '.TAGS_TABLE.'
229+
WHERE '.implode(' OR ', $word_clauses).'
230+
;';
231+
// echo '<pre>'.$query.'</pre>';
232+
$tag_ids = query2array($query, null, 'id');
233+
234+
if (!isset($search['fields']['tags']))
235+
{
236+
$search['fields']['tags'] = array(
237+
'words' => $tag_ids,
238+
'mode' => 'OR',
239+
);
240+
}
241+
else
242+
{
243+
$search['fields']['tags']['words'] = array_merge($search['fields']['tags']['words'], $tag_ids);
244+
}
245+
// echo '<pre>'; print_r($search); echo '</pre>';
246+
}
247+
216248
if (isset($search['fields']['tags']))
217249
{
218250
$tag_items = get_image_ids_for_tags(

search.php

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
'mode' => $_POST['mode'],
7373
'fields' => $_POST['fields'],
7474
);
75+
76+
if (isset($_POST['search_in_tags']))
77+
{
78+
$search['fields']['search_in_tags'] = true;
79+
}
7580
}
7681

7782
if (isset($_POST['tags']))

themes/default/template/search.tpl

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ jQuery(document).ready(function() {
4747
<label><input type="checkbox" name="fields[]" value="name" checked="checked"> {'Photo title'|translate}</label>
4848
<label><input type="checkbox" name="fields[]" value="comment" checked="checked"> {'Photo description'|translate}</label>
4949
<label><input type="checkbox" name="fields[]" value="file" checked="checked"> {'File name'|translate}</label>
50+
{if isset($TAGS)}
51+
<label><input type="checkbox" name="search_in_tags" value="tags"> {'Tags'|translate}</label>
52+
{/if}
5053
</p>
5154

5255
</fieldset>

0 commit comments

Comments
 (0)