mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-06-02 04:15:05 +02:00
Merge branch 'feature/355-search-by-words-on-tags'
This commit is contained in:
@@ -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,7 +199,10 @@ function get_sql_search_clause($search)
|
||||
*/
|
||||
function get_regular_search_results($search, $images_where='')
|
||||
{
|
||||
global $conf;
|
||||
global $conf, $logger;
|
||||
|
||||
$logger->debug(__FUNCTION__, 'search', $search);
|
||||
|
||||
$forbidden = get_sql_condition_FandF(
|
||||
array
|
||||
(
|
||||
@@ -213,12 +216,35 @@ 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).'
|
||||
;';
|
||||
$tag_ids = query2array($query, null, 'id');
|
||||
|
||||
$search_in_tags_items = get_image_ids_for_tags($tag_ids, 'OR');
|
||||
|
||||
$logger->debug(__FUNCTION__.' '.count($search_in_tags_items).' items in $search_in_tags_items');
|
||||
}
|
||||
|
||||
if (isset($search['fields']['tags']))
|
||||
{
|
||||
$tag_items = get_image_ids_for_tags(
|
||||
$search['fields']['tags']['words'],
|
||||
$search['fields']['tags']['mode']
|
||||
);
|
||||
|
||||
$logger->debug(__FUNCTION__.' '.count($tag_items).' items in $tag_items');
|
||||
}
|
||||
|
||||
$search_clause = get_sql_search_clause($search);
|
||||
@@ -237,6 +263,18 @@ SELECT DISTINCT(id)
|
||||
$query .= $forbidden.'
|
||||
'.$conf['order_by'];
|
||||
$items = array_from_query($query, 'id');
|
||||
|
||||
$logger->debug(__FUNCTION__.' '.count($items).' items in $items');
|
||||
}
|
||||
|
||||
if (isset($search_in_tags_items))
|
||||
{
|
||||
$items = array_unique(
|
||||
array_merge(
|
||||
$items,
|
||||
$search_in_tags_items
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( !empty($tag_items) )
|
||||
@@ -244,7 +282,7 @@ SELECT DISTINCT(id)
|
||||
switch ($search['mode'])
|
||||
{
|
||||
case 'AND':
|
||||
if (empty($search_clause))
|
||||
if (empty($search_clause) and !isset($search_in_tags_items))
|
||||
{
|
||||
$items = $tag_items;
|
||||
}
|
||||
@@ -254,7 +292,6 @@ SELECT DISTINCT(id)
|
||||
}
|
||||
break;
|
||||
case 'OR':
|
||||
$before_count = count($items);
|
||||
$items = array_unique(
|
||||
array_merge(
|
||||
$items,
|
||||
|
||||
@@ -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']))
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user