From: john Date: Sat, 18 Jan 2003 15:55:14 +0000 (+0000) Subject: deindex content when you delete it. X-Git-Tag: BEFORE_MERGE_1_1~296 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=964c2f1a80c6a4c89565ef1412ffa277913cd18a;p=mir.git deindex content when you delete it. uses a new utility method which de-index based off of id, not based off an entity --- diff --git a/source/mircoders/search/IndexUtil.java b/source/mircoders/search/IndexUtil.java index 3389ebd0..a61f5c33 100755 --- a/source/mircoders/search/IndexUtil.java +++ b/source/mircoders/search/IndexUtil.java @@ -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); + } + } + } + } } diff --git a/source/mircoders/servlet/ServletModuleContent.java b/source/mircoders/servlet/ServletModuleContent.java index 3822b641..af9de0c5 100755 --- a/source/mircoders/servlet/ServletModuleContent.java +++ b/source/mircoders/servlet/ServletModuleContent.java @@ -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 {