Skip to content
Browse files

Register an handler that would add document to Solr engine when a

``ObjectInsert`` of ``Document`` is raised.
  • Loading branch information...
1 parent 608e5f4 commit 1878cf853809744f6cd034bb4e1cfac560ccc60e @teixas committed
Showing with 25 additions and 1 deletion.
  1. +9 −1 kotti_solr/__init__.py
  2. +16 −0 kotti_solr/events.py
View
10 kotti_solr/__init__.py
@@ -1,2 +1,10 @@
+from kotti.events import ObjectInsert
+from kotti.events import objectevent_listeners
+from kotti.resources import Document
+
+from kotti_solr.events import add_document_handler
+
+
def includeme(config):
- pass
+ objectevent_listeners[(ObjectInsert, Document)].append(
+ add_document_handler)
View
16 kotti_solr/events.py
@@ -0,0 +1,16 @@
+from sunburnt import SolrInterface
+from kotti.util import extract_from_settings
+
+
+def add_document_handler(event):
+ solr_url = extract_from_settings('kotti_solr.').get('solr_url')
+ si = SolrInterface(solr_url)
+ doc = event.object
+ si.add(dict(
+ id=u'%s-%s' % (doc.type, doc.id),
+ title=doc.title,
+ description=doc.description,
+ text=doc.body,
+ last_modified=doc.modification_date.isoformat(),
+ ))
+ si.optimize()

0 comments on commit 1878cf8

Please sign in to comment.
Something went wrong with that request. Please try again.