mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-07-21 00:53:04 +02:00
issue #1957 albums/tags found now correctly filled
This commit is contained in:
@@ -146,6 +146,7 @@ function get_sql_search_clause($search)
|
||||
// ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
|
||||
// AND (field1 LIKE '%word2%' OR field2 LIKE '%word2%'))
|
||||
$word_clauses = array();
|
||||
$cat_ids_by_word = array();
|
||||
foreach ($search['fields']['allwords']['words'] as $word)
|
||||
{
|
||||
$field_clauses = array();
|
||||
@@ -173,6 +174,7 @@ SELECT
|
||||
WHERE '.implode(' OR ', $cat_word_clauses).'
|
||||
;';
|
||||
$cat_ids = query2array($query, null, 'id');
|
||||
$cat_ids_by_word[$word] = $cat_ids;
|
||||
if (count($cat_ids) == 0)
|
||||
{
|
||||
$cat_ids = array(-1);
|
||||
@@ -210,6 +212,35 @@ SELECT
|
||||
$word_clauses
|
||||
);
|
||||
|
||||
if (count($cat_ids_by_word) > 0)
|
||||
{
|
||||
$matching_cat_ids = null;
|
||||
foreach ($cat_ids_by_word as $idx => $cat_ids)
|
||||
{
|
||||
if (is_null($matching_cat_ids))
|
||||
{
|
||||
// first iteration
|
||||
$matching_cat_ids = $cat_ids;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ('OR' == $search['fields']['allwords']['mode'])
|
||||
{
|
||||
$matching_cat_ids = array_merge($matching_cat_ids, $cat_ids);
|
||||
}
|
||||
else
|
||||
{
|
||||
$matching_cat_ids = array_intersect($matching_cat_ids, $cat_ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ('OR' == $search['fields']['allwords']['mode'])
|
||||
{
|
||||
$matching_cat_ids = array_unique($matching_cat_ids);
|
||||
}
|
||||
}
|
||||
|
||||
// 3) the case of searching among tags is handled by search_in_tags in function get_regular_search_results
|
||||
}
|
||||
|
||||
@@ -287,7 +318,7 @@ SELECT
|
||||
|
||||
$search_clause = $where_separator;
|
||||
|
||||
return $search_clause;
|
||||
return array($search_clause, isset($matching_cat_ids) ? array_values($matching_cat_ids) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,13 +365,13 @@ function get_regular_search_results($search, $images_where='')
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
id
|
||||
id, name, url_name
|
||||
FROM '.TAGS_TABLE.'
|
||||
WHERE '.implode(' OR ', $word_clauses).'
|
||||
;';
|
||||
$tag_ids = query2array($query, null, 'id');
|
||||
$matching_tags = query2array($query, 'id');
|
||||
|
||||
$search_in_tags_items = get_image_ids_for_tags($tag_ids, 'OR');
|
||||
$search_in_tags_items = get_image_ids_for_tags(array_keys($matching_tags), 'OR');
|
||||
|
||||
$logger->debug(__FUNCTION__.' '.count($search_in_tags_items).' items in $search_in_tags_items');
|
||||
}
|
||||
@@ -355,7 +386,7 @@ SELECT
|
||||
$logger->debug(__FUNCTION__.' '.count($tag_items).' items in $tag_items');
|
||||
}
|
||||
|
||||
$search_clause = get_sql_search_clause($search);
|
||||
list($search_clause, $matching_cat_ids) = get_sql_search_clause($search);
|
||||
|
||||
if (!empty($search_clause))
|
||||
{
|
||||
@@ -419,7 +450,13 @@ SELECT DISTINCT(id)
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
return array(
|
||||
'items' => $items,
|
||||
'search_details' => array(
|
||||
'matching_cat_ids' => $matching_cat_ids,
|
||||
'matching_tags' => @$matching_tags,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1619,8 +1656,7 @@ function get_search_results($search_id, $super_order_by, $images_where='')
|
||||
$search = get_search_array($search_id);
|
||||
if ( !isset($search['q']) )
|
||||
{
|
||||
$result['items'] = get_regular_search_results($search, $images_where);
|
||||
return $result;
|
||||
return get_regular_search_results($search, $images_where);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -368,6 +368,10 @@ else
|
||||
{
|
||||
$page['qsearch_details'] = $search_result['qs'];
|
||||
}
|
||||
else if (isset($search_result['search_details']))
|
||||
{
|
||||
$page['search_details'] = $search_result['search_details'];
|
||||
}
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
|
||||
@@ -393,27 +393,49 @@ SELECT
|
||||
)
|
||||
);
|
||||
|
||||
// TODO: Send actual data
|
||||
/*
|
||||
$template->assign('TAGS_FOUND',
|
||||
array(
|
||||
'Link 1 / Sub link 1 / <a href="https://www.google.com"> Sub sub</a>',
|
||||
'Link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2.2.2',
|
||||
'Link 3',
|
||||
'Link 4',
|
||||
'Link 5'
|
||||
)
|
||||
);
|
||||
|
||||
$template->assign('ALBUMS_FOUND',
|
||||
array(
|
||||
'Link 1 / Sub link 1 / <a href="https://www.google.com"> Sub sub</a>',
|
||||
'Link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2 / Sub link 2.2.2',
|
||||
'Link 3',
|
||||
'Link 4',
|
||||
)
|
||||
);
|
||||
*/
|
||||
if (0 == $page['start'] and !isset($page['chronology_field']) and isset($page['search_details']))
|
||||
{
|
||||
if (isset($page['search_details']['matching_cat_ids']))
|
||||
{
|
||||
$cat_ids = $page['search_details']['matching_cat_ids'];
|
||||
if (count($cat_ids))
|
||||
{
|
||||
$query = '
|
||||
SELECT
|
||||
*
|
||||
FROM '.CATEGORIES_TABLE.'
|
||||
WHERE id IN ('.implode(',', $cat_ids).')
|
||||
;';
|
||||
$cats = query2array($query);
|
||||
usort($cats, 'name_compare');
|
||||
$albums_found = array();
|
||||
foreach ($cats as $cat)
|
||||
{
|
||||
$single_link = false;
|
||||
$albums_found[] = get_cat_display_name_cache(
|
||||
$cat['uppercats'],
|
||||
'',
|
||||
$single_link
|
||||
);
|
||||
}
|
||||
$template->assign('ALBUMS_FOUND', $albums_found);
|
||||
}
|
||||
}
|
||||
if (isset($page['search_details']['matching_tags']))
|
||||
{
|
||||
$tags_found = array();
|
||||
foreach ($page['search_details']['matching_tags'] as $tag)
|
||||
{
|
||||
$url = make_index_url(
|
||||
array(
|
||||
'tags' => array($tag)
|
||||
)
|
||||
);
|
||||
$tags_found[] = sprintf('<a href="%s">%s</a>', $url, $tag['name']);
|
||||
}
|
||||
$template->assign('TAGS_FOUND', $tags_found);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ('categories' == $page['section'] and isset($page['category']) and !isset($page['combined_categories']))
|
||||
|
||||
@@ -437,4 +437,6 @@ $lang['Unknown time period'] = 'Unknown time period';
|
||||
$lang['Tags found'] = 'Tags found';
|
||||
$lang['Albums found'] = 'Albums found';
|
||||
$lang['Search in this set'] = 'Search in this set';
|
||||
$lang['Tags listed here match your search by word. Click on one to browse by tag.'] = 'Tags listed here match your search by word. Click on one to browse by tag.';
|
||||
$lang['Albums listed here match your search by word. Click on one to browse by album.'] = 'Albums listed here match your search by word. Click on one to browse by album.';
|
||||
?>
|
||||
|
||||
@@ -442,3 +442,5 @@ $lang['Unknown time period'] = 'Période inconnue';
|
||||
$lang['Tags found'] = 'Tags trouvés';
|
||||
$lang['Albums found'] = 'Albums trouvés';
|
||||
$lang['Search in this set'] = 'Rechercher dans ce lot';
|
||||
$lang['Tags listed here match your search by word. Click on one to browse by tag.'] = 'Les tags ci-dessous correspondent à votre recherche par mot. Cliquez sur l\'un d\'eux pour basculer en navigation par tag.';
|
||||
$lang['Albums listed here match your search by word. Click on one to browse by album.'] = 'Les albums ci-dessous correspondent à votre recherche par mot. Cliquez sur l\'un d\'eux pour basculer en navigation par album.';
|
||||
|
||||
@@ -350,7 +350,7 @@ str_empty_search_bot_alt = "{'Pre-established filters are proposed, but you can
|
||||
<div class="tags-found-popin-container">
|
||||
<span class="pwg-icon-cancel tags-found-close"></span>
|
||||
<div class="mcs-popin-title">{'Tags found'|@translate}</div>
|
||||
|
||||
<div class="mcs-popin-desc">{'Tags listed here match your search by word. Click on one to browse by tag.'|translate}</div>
|
||||
<div class="tags-found-container">
|
||||
{foreach from=$TAGS_FOUND item=tag_path key=k}
|
||||
<div class="tag-item">
|
||||
@@ -366,7 +366,7 @@ str_empty_search_bot_alt = "{'Pre-established filters are proposed, but you can
|
||||
<div class="albums-found-popin-container">
|
||||
<span class="pwg-icon-cancel albums-found-close"></span>
|
||||
<div class="mcs-popin-title">{'Albums found'|@translate}</div>
|
||||
|
||||
<div class="mcs-popin-desc">{'Albums listed here match your search by word. Click on one to browse by album.'|translate}</div>
|
||||
<div class="albums-found-container">
|
||||
{foreach from=$ALBUMS_FOUND item=album_path key=k}
|
||||
<div class="album-item">
|
||||
|
||||
Reference in New Issue
Block a user