Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-keyword.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-keyword.sql,v
diff -u -r1.8 -r1.9
--- openacs-4/packages/acs-content-repository/sql/postgresql/content-keyword.sql	8 Jun 2001 01:52:31 -0000	1.8
+++ openacs-4/packages/acs-content-repository/sql/postgresql/content-keyword.sql	8 Dec 2001 01:17:59 -0000	1.9
@@ -221,16 +221,14 @@
 --      and
 --	m.item_id = is_assigned__item_id);
 
-      return count(*) > 0 from dual where exists (select 1 from
-	(select keyword_id from cr_keywords
-	  where tree_sortkey like (select tree_sortkey || ''%''
-                                   from cr_keywords
-                                   where keyword_id = is_assigned__keyword_id)
-	 ) t, cr_item_keyword_map m
-      where
-	t.keyword_id = m.keyword_id
-      and
-	m.item_id = is_assigned__item_id);
+      return count(*) > 0
+      where exists (select 1
+                    from (select keyword_id from cr_keywords c, cr_keywords c2
+	                  where c2.keyword_id = is_assigned__keyword_id
+                            and c.tree_sortkey between c2.tree_sortkey and tree_right(c2.tree_sortkey))) t,
+                      cr_item_keyword_map m
+                    where t.keyword_id = m.keyword_id
+                      and m.item_id = is_assigned__item_id);
   end if;
 
   if is_assigned__recurse = ''down'' then
@@ -244,22 +242,15 @@
 --      and
 --	m.item_id = is_assigned__item_id);
 
-      return count(*) > 0 from dual where exists ( select 1 from
-	(select 
-           k2.keyword_id
-         from 
-           cr_keywords k1, cr_keywords k2
-         where
-           k1.keyword_id = is_assigned__keyword_id
-         and 
-           k2.tree_sortkey <= k1.tree_sortkey
-         and 
-           k1.tree_sortkey like (k2.tree_sortkey || ''%'')) t, 
-        cr_item_keyword_map m
-      where
-	t.keyword_id = m.keyword_id
-      and
-	m.item_id = is_assigned__item_id);
+      return count(*) > 0
+      where exists (select 1
+                    from (select k2.keyword_id
+                          from cr_keywords k1, cr_keywords k2
+                          where k1.keyword_id = is_assigned__keyword_id
+                            and k1.tree_sortkey between k2.tree_sortkey and tree_right(k2.tree_sortkey)) t, 
+                      cr_item_keyword_map m
+                    where t.keyword_id = m.keyword_id
+                      and m.item_id = is_assigned__item_id);
 
   end if;  
 
@@ -291,21 +282,12 @@
 --                order by 
 --                  tree_level desc 
 
-  for v_rec in select 
-                 heading 
-               from (
-                  select 
-                    k2.heading, tree_level(k2.tree_sortkey) as tree_level
-                  from 
-                    cr_keywords k1, cr_keywords k2
-                  where
-                    k1.keyword_id = get_path__keyword_id
-                  and 
-                    k2.tree_sortkey <= k1.tree_sortkey
-                  and 
-                    k1.tree_sortkey like (k2.tree_sortkey || ''%'')) k
-                order by 
-                  tree_level desc 
+  for v_rec in select heading 
+               from (select k2.heading, tree_level(k2.tree_sortkey) as tree_level
+                     from cr_keywords k1, cr_keywords k2
+                     where k1.keyword_id = get_path__keyword_id
+                       and k1.tree_sortkey between k2.tree_sortkey and tree_right(k2.tree_sortkey)) k
+                order by tree_level desc 
   LOOP
       v_heading := v_rec.heading;
       v_is_found := ''t'';
