aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_search.inc.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2006-04-02 22:26:19 +0000
committerplegall <plg@piwigo.org>2006-04-02 22:26:19 +0000
commit42abf4c57664d2596872d437f70b95193f9a5d18 (patch)
treea1262b8601d5ac5b04b5b2e71af52c453712b9df /include/functions_search.inc.php
parent68ed2ea617ede199a0e2f15fdd4886095ae600cb (diff)
improvement: tags replace keywords. Better data model, less
limitations. Each image can be associated to as many tag as needed. Tags can contain non ASCII characters. Oriented navigation with tags by association. git-svn-id: http://piwigo.org/svn/trunk@1119 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/functions_search.inc.php')
-rw-r--r--include/functions_search.inc.php68
1 files changed, 62 insertions, 6 deletions
diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php
index 2ca87969e..7e55160c8 100644
--- a/include/functions_search.inc.php
+++ b/include/functions_search.inc.php
@@ -84,7 +84,7 @@ function get_sql_search_clause($search_id)
// construction
$clauses = array();
- foreach (array('file','name','comment','keywords','author') as $textfield)
+ foreach (array('file','name','comment','author') as $textfield)
{
if (isset($search['fields'][$textfield]))
{
@@ -109,7 +109,7 @@ function get_sql_search_clause($search_id)
if (isset($search['fields']['allwords']))
{
- $fields = array('file', 'name', 'comment', 'keywords', 'author');
+ $fields = array('file', 'name', 'comment', 'author');
// in the OR mode, request bust be :
// ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
// OR (field1 LIKE '%word2%' OR field2 LIKE '%word2%'))
@@ -208,12 +208,68 @@ function get_sql_search_clause($search_id)
$search_clause = $where_separator;
- if (isset($forbidden))
+ return $search_clause;
+}
+
+/**
+ * returns the list of items corresponding to the search id
+ *
+ * @param int search id
+ * @return array
+ */
+function get_search_items($search_id)
+{
+ $items = array();
+
+ $search_clause = get_sql_search_clause($search_id);
+
+ if (!empty($search_clause))
{
- $search_clause.= "\n AND ".$forbidden;
+ $query = '
+SELECT DISTINCT(id)
+ FROM '.IMAGES_TABLE.'
+ INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
+ WHERE '.$search_clause.'
+;';
+ $items = array_from_query($query, 'id');
}
- return $search_clause;
-}
+ $search = get_search_array($search_id);
+ if (isset($search['fields']['tags']))
+ {
+ $tag_items = get_image_ids_for_tags(
+ $search['fields']['tags']['words'],
+ $search['fields']['tags']['mode']
+ );
+
+ switch ($search['mode'])
+ {
+ case 'AND':
+ {
+ if (empty($search_clause))
+ {
+ $items = $tag_items;
+ }
+ else
+ {
+ $items = array_intersect($items, $tag_items);
+ }
+ break;
+ }
+ case 'OR':
+ {
+ $items = array_unique(
+ array_merge(
+ $items,
+ $tag_items
+ )
+ );
+ break;
+ }
+ }
+ }
+
+ return $items;
+}
?> \ No newline at end of file