Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-search.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-search.sql,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/acs-content-repository/sql/postgresql/content-search.sql	3 Feb 2005 00:18:10 -0000	1.7
+++ openacs-4/packages/acs-content-repository/sql/postgresql/content-search.sql	6 Sep 2006 14:46:03 -0000	1.8
@@ -81,11 +81,13 @@
 
 -- DaveB: We only want to index live_revisions 2002-09-26
 
+
+
 create function content_search__itrg ()
 returns opaque as '
 begin
-if (select live_revision from cr_items where item_id=new.item_id) = new.revision_id then	
-	perform search_observer__enqueue(new.revision_id,''INSERT'');
+if (select live_revision from cr_items where item_id=new.item_id) = new.revision_id and new.publish_date >= current_timestamp then
+        perform search_observer__enqueue(new.revision_id,''INSERT'');
     end if;
     return new;
 end;' language 'plpgsql';
@@ -97,17 +99,18 @@
     return old;
 end;' language 'plpgsql';
 
-create function content_search__utrg ()
+create or replace function content_search__utrg ()
 returns opaque as '
 declare
     v_live_revision integer;
 begin
     select into v_live_revision live_revision from
-	cr_items where item_id=old.item_id;
-    if old.revision_id=v_live_revision then
-	insert into search_observer_queue (
+        cr_items where item_id=old.item_id;
+    if old.revision_id=v_live_revision
+      and new.publish_date <= current_timestamp then
+        insert into search_observer_queue (
             object_id,
-	    event
+            event
         ) values (
 old.revision_id,
             ''UPDATE''
@@ -116,20 +119,22 @@
     return new;
 end;' language 'plpgsql';
 
-
 -- we need new triggers on cr_items to index when a live revision
 -- changes -DaveB 2002-09-26
 
 create function content_item_search__utrg ()
 returns opaque as '
 begin
-    if new.live_revision is not null and coalesce(old.live_revision,0) <> new.live_revision then
-	perform search_observer__enqueue(new.live_revision,''INSERT'');		
+    if new.live_revision is not null and coalesce(old.live_revision,0) <> new.live_revision and (select publish_date from cr_revisions where revision_id=new.live_revision) <= current_timestamp then
+        perform search_observer__enqueue(new.live_revision,''INSERT'');        
     end if;
 
     if old.live_revision is not null and old.live_revision <> coalesce(new.live_revision,0) then
-	perform search_observer__enqueue(old.live_revision,''DELETE'');
+        perform search_observer__enqueue(old.live_revision,''DELETE'');
     end if;
+    if new.publish_status = ''expired'' then
+        perform search_observer__enqueue(old.live_revision,''DELETE'');
+    end if;
 
     return new;
 end;' language 'plpgsql';
