deindex content when you delete it.
authorjohn <john>
Sat, 18 Jan 2003 15:55:14 +0000 (15:55 +0000)
committerjohn <john>
Sat, 18 Jan 2003 15:55:14 +0000 (15:55 +0000)
uses a new utility method which de-index based off of id, not based off
an entity

source/mircoders/search/IndexUtil.java
source/mircoders/servlet/ServletModuleContent.java

index 3389ebd..a61f5c3 100755 (executable)
@@ -59,4 +59,25 @@ public class IndexUtil {
       }
     }
   }
+  public static void unindexID (String id,String index) throws IOException{
+    IndexReader indexReader = null;
+    try{
+      indexReader = IndexReader.open(index);
+      indexReader.delete(new Term("id",id));
+      indexReader.close();
+    }
+    catch(Exception e){
+      if (indexReader != null){
+       indexReader.close();
+      }
+    }
+    finally { 
+      if (indexReader != null){
+       FSDirectory theIndexDir=FSDirectory.getDirectory(index,false);
+       if (IndexReader.isLocked(theIndexDir)){
+         IndexReader.unlock(theIndexDir);
+       }
+      }
+    }
+  }
 }
index 3822b64..af9de0c 100755 (executable)
@@ -39,6 +39,7 @@ import javax.servlet.*;
 import javax.servlet.http.*;
 
 import org.apache.struts.util.MessageResources;
+import org.apache.lucene.index.*;
 
 import freemarker.template.*;
 
@@ -57,12 +58,13 @@ import mircoders.storage.*;
 import mircoders.module.*;
 import mircoders.entity.*;
 import mircoders.localizer.*;
+import mircoders.search.IndexUtil;
 
 /*
  *  ServletModuleContent -
  *  deliver html for the article admin form.
  *
- * @version $Id: ServletModuleContent.java,v 1.30 2002/12/28 03:14:42 mh Exp $
+ * @version $Id: ServletModuleContent.java,v 1.31 2003/01/18 15:55:14 john Exp $
  * @author rk, mir-coders
  *
  */
@@ -233,11 +235,19 @@ public class ServletModuleContent extends ServletModule
           DatabaseContentToTopics.getInstance().deleteByContentId(idParam);
           //delete rows in the comment-table
           DatabaseComment.getInstance().deleteByContentId(idParam);
+         //delete from lucene index, if any
+         String index=MirConfig.getProp("IndexPath");
+         if (IndexReader.indexExists(index)){
+           IndexUtil.unindexID(idParam,index);
+         }
+         
         } catch (ModuleException e) {
           throw new ServletModuleException(e.toString());
         } catch (StorageObjectException e) {
           throw new ServletModuleException(e.toString());
-        }
+        } catch (IOException e) {
+         throw new ServletModuleException(e.toString());
+       }
         list(req,res);
       }
       else {