Index: extensions/AMetaData/amd_ajax.php
===================================================================
--- extensions/AMetaData/amd_ajax.php	(revision 6977)
+++ extensions/AMetaData/amd_ajax.php	(revision 7443)
@@ -40,4 +40,9 @@
   class AMD_ajax extends AMD_root
   {
+    private $tagSeparators=array(
+      'xmp.digiKam:TagsList' => '/',
+      'xmp.lr:hierarchicalSubject' => '|'
+    );
+
     /**
      * constructor
@@ -1505,10 +1510,11 @@
       $returned=array();
       $keywordsList=array();
-      $sql="SELECT pait.value, pait.imageId, paut.numId
+      $sql="SELECT DISTINCT pait.value, pait.imageId, paut.numId, paut.tagId
             FROM (".$this->tables['images_tags']." pait
               JOIN ".$this->tables['used_tags']." paut ON pait.numId = paut.numId)
 
             WHERE (paut.tagId = 'xmp.dc:subject' OR
-                   paut.tagId = 'xmp.digiKam:tagsList' OR
+                   paut.tagId = 'xmp.digiKam:TagsList' OR
+                   paut.tagId = 'xmp.lr:hierarchicalSubject' OR
                    paut.tagId = 'iptc.Keywords');";
       $result=pwg_query($sql);
@@ -1525,5 +1531,16 @@
             foreach($tmp['values'] as $val)
             {
-              $keywordsList[]="('".mysql_escape_string($val)."', ".$row['imageId'].")";
+              if($row['tagId']=='xmp.digiKam:TagsList' or $row['tagId']=='xmp.lr:hierarchicalSubject')
+              {
+                $list=explode($this->tagSeparators[$row['tagId']], $val);
+                foreach($list as $subTag)
+                {
+                  $keywordsList[]="('".mysql_escape_string(trim($subTag))."', ".$row['imageId'].")";
+                }
+              }
+              else
+              {
+                $keywordsList[]="('".mysql_escape_string($val)."', ".$row['imageId'].")";
+              }
             }
           }
@@ -1554,5 +1571,6 @@
                       LEFT JOIN ".IMAGE_TAG_TABLE." pit ON pit.tag_id = ptt.id
                     GROUP BY att.value
-                    HAVING nbPicturesTagged < nbPictures";
+                    HAVING nbPicturesTagged < nbPictures
+                    ORDER BY att.value";
               $result=pwg_query($sql);
               if($result)
@@ -1595,10 +1613,11 @@
        */
       $keywordsList=array();
-      $sql="SELECT pait.value, pait.imageId, paut.numId
+      $sql="SELECT DISTINCT pait.value, pait.imageId, paut.numId, paut.tagId
             FROM (".$this->tables['images_tags']." pait
               JOIN ".$this->tables['used_tags']." paut ON pait.numId = paut.numId)
 
             WHERE (paut.tagId = 'xmp.dc:subject' OR
-                   paut.tagId = 'xmp.digiKam:tagsList' OR
+                   paut.tagId = 'xmp.digiKam:TagsList' OR
+                   paut.tagId = 'xmp.lr:hierarchicalSubject' OR
                    paut.tagId = 'iptc.Keywords');";
       $result=pwg_query($sql);
@@ -1615,5 +1634,16 @@
             foreach($tmp['values'] as $val)
             {
-              $keywordsList[]="('".mysql_escape_string($val)."', ".$row['imageId'].")";
+              if($row['tagId']=='xmp.digiKam:TagsList')
+              {
+                $list=explode($this->tagSeparators[$row['tagId']], $val);
+                foreach($list as $subTag)
+                {
+                  $keywordsList[]="('".mysql_escape_string(trim($subTag))."', ".$row['imageId'].")";
+                }
+              }
+              else
+              {
+                $keywordsList[]="('".mysql_escape_string($val)."', ".$row['imageId'].")";
+              }
             }
           }
@@ -1640,10 +1670,10 @@
             /*
              * 2/ join temp table with piwigo tags table, found the keywords
-             *    that don't have a corresponding keyword
+             *    that don't have a corresponding tag
              */
             $sql="SELECT DISTINCT att.value
                   FROM amd_temp_tags att LEFT JOIN ".TAGS_TABLE." ptt ON att.value = ptt.name
                   WHERE ptt.id IS NULL
-                    AND".implode(' OR ', $keywords);
+                    AND (".implode(' OR ', $keywords).") ";
             $result=pwg_query($sql);
             if($result)
@@ -1675,5 +1705,4 @@
         }
       }
-
       return($returned);
     }
