Commits

Alessandro Molina committed f25b64f

Remove references to archive and clear indexed articles on delete

Comments (0)

Files changed (5)

smallpress/controllers/root.py

         return redirect(self.mount_point+'/manage')
 
     @expose('genshi:smallpress.templates.index')
-    @validate(dict(what=UnicodeString(not_empty=True)), error_handler=index)
-    def search(self, what=None):
+    @validate(dict(text=UnicodeString(not_empty=True)), error_handler=index)
+    def search(self, text=None):
         articles = []
 
         index_path = config.get('smallpress_whoosh_index', '/tmp/smallpress_whoosh')
         ix = whoosh.index.open_dir(index_path)
         with ix.searcher() as searcher:
-            query = Or([Term("content", what),
-                        Term("title", what),
-                        Term("description", what)])
+            query = Or([Term("content", text),
+                        Term("title", text),
+                        Term("description", text)])
             found = searcher.search(query)
             if len(found):
                 articles = Article.get_published().filter(Article.uid.in_([e['uid'] for e in found])).all()

smallpress/model/models.py

     description = Column(Unicode(150), nullable=False, default=u'Empty article, edit or delete this')
     content = Column(Unicode(32000), nullable=False, default=u'')
 
-    def refresh_whoosh(self, update=False):
+    def refresh_whoosh(self, action=0):
         index_path = config.get('smallpress_whoosh_index', '/tmp/smallpress_whoosh')
         ix = whoosh.index.open_dir(index_path)
         writer = ix.writer()
-        if not update:
+
+        if action == 1:
             writer.add_document(uid=unicode(self.uid), title=self.title,
                                 content=self.content,
                                 description=self.description)
+        elif action == -1:
+            writer.delete_by_term('uid', unicode(self.uid))
         else:
             writer.update_document(uid=unicode(self.uid), title=self.title,
                                    content=self.content,
 
     @staticmethod
     def after_update(mapper, connection, obj):
-        obj.refresh_whoosh(True)
+        obj.refresh_whoosh(0)
 
     @staticmethod
     def after_insert(mapper, connection, obj):
-        obj.refresh_whoosh(False)
+        obj.refresh_whoosh(1)
 
     @staticmethod
     def before_delete(mapper, connection, obj):
+        obj.refresh_whoosh(-1)
+
         from smallpress.model import Tagging
         DBSession.query(Tagging).filter(Tagging.taggable_type == 'Article')\
                                 .filter(Tagging.taggable_id == obj.uid).delete()

smallpress/partials.py

 
 @expose('genshi:smallpress.templates.search')
 def search():
-    return dict(form=search_form, action=plug_url('smallpress', '/search'))
+    return dict(form=search_form, action=plug_url('smallpress', '/search'))

smallpress/templates/article.html

     <div id="smallpress_rightbar">
         ${h.call_partial('smallpress.partials:search')}
         ${h.call_partial('smallpress.partials:tagcloud')}
-        <div id="smallpress_history">
-            <h3>Archive</h3>
-        </div>
     </div>
     <div id="smallpress_articles_box">
         <div>${h.call_partial('smallpress.partials:article_preview', article=article)}</div>

smallpress/templates/index.html

     <div id="smallpress_rightbar">
         ${h.call_partial('smallpress.partials:search')}
         ${h.call_partial('smallpress.partials:tagcloud', tags=tags)}
-        <div id="smallpress_history">
-            <h3>Archive</h3>
-        </div>
     </div>
     <div id="smallpress_articles_box">
         <div py:if="request.identity and 'smallpress' in request.identity['groups']">