diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index ce1ca3c30..7e8ec5960 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -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 { diff --git a/include/section_init.inc.php b/include/section_init.inc.php index b6d3b5bcf..0dd5d13ff 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -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, diff --git a/index.php b/index.php index fedcbb26a..ce131886f 100644 --- a/index.php +++ b/index.php @@ -393,27 +393,49 @@ SELECT ) ); - // TODO: Send actual data -/* - $template->assign('TAGS_FOUND', - array( - 'Link 1 / Sub link 1 / Sub sub', - '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 / Sub sub', - '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('%s', $url, $tag['name']); + } + $template->assign('TAGS_FOUND', $tags_found); + } + } } if ('categories' == $page['section'] and isset($page['category']) and !isset($page['combined_categories'])) diff --git a/language/en_UK/common.lang.php b/language/en_UK/common.lang.php index 1b275396e..75d757c4b 100644 --- a/language/en_UK/common.lang.php +++ b/language/en_UK/common.lang.php @@ -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.'; ?> diff --git a/language/fr_FR/common.lang.php b/language/fr_FR/common.lang.php index 7937a5d39..16c6fa7a3 100644 --- a/language/fr_FR/common.lang.php +++ b/language/fr_FR/common.lang.php @@ -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.'; diff --git a/themes/default/template/include/search_filters.inc.tpl b/themes/default/template/include/search_filters.inc.tpl index a5b3b0aa5..200ba2d30 100644 --- a/themes/default/template/include/search_filters.inc.tpl +++ b/themes/default/template/include/search_filters.inc.tpl @@ -350,7 +350,7 @@ str_empty_search_bot_alt = "{'Pre-established filters are proposed, but you can