mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 03:39:57 +03:00
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"
This commit is contained in:
parent
a6fbaf69c7
commit
713bc49746
3 changed files with 42 additions and 2 deletions
|
@ -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');
|
$fields = array('file', 'name', 'comment');
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ function get_sql_search_clause($search)
|
||||||
{
|
{
|
||||||
$fields = array_intersect($fields, $search['fields']['allwords']['fields']);
|
$fields = array_intersect($fields, $search['fields']['allwords']['fields']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// in the OR mode, request bust be :
|
// in the OR mode, request bust be :
|
||||||
// ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
|
// ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
|
||||||
// OR (field1 LIKE '%word2%' OR field2 LIKE '%word2%'))
|
// 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='')
|
function get_regular_search_results($search, $images_where='')
|
||||||
{
|
{
|
||||||
|
// echo '<pre>'; print_r($search); echo '</pre>';
|
||||||
global $conf;
|
global $conf;
|
||||||
$forbidden = get_sql_condition_FandF(
|
$forbidden = get_sql_condition_FandF(
|
||||||
array
|
array
|
||||||
|
@ -213,6 +214,37 @@ function get_regular_search_results($search, $images_where='')
|
||||||
$items = array();
|
$items = array();
|
||||||
$tag_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']))
|
if (isset($search['fields']['tags']))
|
||||||
{
|
{
|
||||||
$tag_items = get_image_ids_for_tags(
|
$tag_items = get_image_ids_for_tags(
|
||||||
|
|
|
@ -72,6 +72,11 @@ if (isset($_POST['submit']))
|
||||||
'mode' => $_POST['mode'],
|
'mode' => $_POST['mode'],
|
||||||
'fields' => $_POST['fields'],
|
'fields' => $_POST['fields'],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isset($_POST['search_in_tags']))
|
||||||
|
{
|
||||||
|
$search['fields']['search_in_tags'] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST['tags']))
|
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="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="comment" checked="checked"> {'Photo description'|translate}</label>
|
||||||
<label><input type="checkbox" name="fields[]" value="file" checked="checked"> {'File name'|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>
|
</p>
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue