--- a/src/ldt/ldt/ldt_utils/contentindexer.py Mon Jul 23 17:05:53 2012 +0200
+++ b/src/ldt/ldt/ldt_utils/contentindexer.py Mon Jul 30 19:46:40 2012 +0200
@@ -4,7 +4,6 @@
from ldt.ldt_utils.models import Segment, Content, Project
from ldt.ldt_utils.utils import reduce_text_node
from ldt.ldt_utils.stat import update_stat_project
-import ldt.indexation
import lxml.etree
import urllib #@UnresolvedImport
# import ldt.utils.log
@@ -15,9 +14,8 @@
class LdtIndexer(object):
- def __init__(self, writer, decoupage_blackList=settings.DECOUPAGE_BLACKLIST):
+ def __init__(self, decoupage_blackList=settings.DECOUPAGE_BLACKLIST):
self.__decoupage_blacklist = decoupage_blackList
- self.__writer = writer
@Property
def decoupage_blacklist(): #@NoSelf
@@ -36,12 +34,6 @@
return locals()
- @Property
- def writer(): #@NoSelf
- def fget(self):
- return self.__writer
- return locals()
-
def index_all(self):
raise NotImplemented
@@ -109,28 +101,11 @@
seg.polemics = seg.get_polemic(polemics)
seg.save()
- ldt.indexation.add_document([
- ("type_doc", "annotation", False, "NOT_ANALYZED"),
- ("iri_id", content.iri_id, True, "NOT_ANALYZED"),
- ("project_id", ldt_id, True, "NOT_ANALYZED"),
- ("ensemble_id", ensembleId, True, "NO"),
- ("decoupage_id", decoupId, True, "NO"),
- ("element_id", elementId, True, "NO"),
- ("tags", tags, True, "ANALYZED"),
- ("title", title, True, "ANALYZED"),
- ("abstract", abstract, True, "ANALYZED"),
- ("all", " ".join([tags, title, abstract]), True, "ANALYZED"),
- ("begin", str(start_ts), True, "NOT_ANALYZED"),
- ("duration", str(duration), True, "NOT_ANALYZED"),
- ("author", author, True, "ANALYZED"),
- ], self.writer)
-
-
class ContentIndexer(LdtIndexer):
- def __init__(self, contentList, writer, decoupage_blackList=settings.DECOUPAGE_BLACKLIST, callback=None):
- super(ContentIndexer, self).__init__(writer, decoupage_blackList)
+ def __init__(self, contentList, decoupage_blackList=settings.DECOUPAGE_BLACKLIST, callback=None):
+ super(ContentIndexer, self).__init__(decoupage_blackList)
self.__contentList = contentList
self.__callback = callback
@@ -140,27 +115,23 @@
self.__callback(i,content)
self.index_content(content)
- def index_content(self, content):
-
+ def index_content(self, content):
url = content.iri_url()
filepath = urllib.urlopen(url)
doc = lxml.etree.parse(filepath) #@UndefinedVariable
- ldt.indexation.delete_document("iri_id", content.iri_id, self.writer)
Segment.objects.filter(iri_id=content.iri_id).delete() #@UndefinedVariable
res = doc.xpath("/iri/body/ensembles/ensemble")
for ensemble in res:
self.index_ensemble(ensemble, content)
-
- self.writer.commit()
-
+
class ProjectIndexer(LdtIndexer):
- def __init__(self, projectList, writer, decoupage_blackList=settings.DECOUPAGE_BLACKLIST, callback=None):
- super(ProjectIndexer, self).__init__(writer, decoupage_blackList)
+ def __init__(self, projectList, decoupage_blackList=settings.DECOUPAGE_BLACKLIST, callback=None):
+ super(ProjectIndexer, self).__init__(decoupage_blackList)
self.__projectList = projectList
self.__callback = callback
@@ -176,7 +147,6 @@
# pocketfilms.utils.log.debug("Indexing project : "+str(project.iri_id))
doc = lxml.etree.fromstring(project.ldt_encoded) #@UndefinedVariable
- ldt.indexation.delete_document("project_id", project.ldt_id, self.writer)
Segment.objects.filter(project_obj__ldt_id=project.ldt_id).delete() #@UndefinedVariable
res = doc.xpath("/iri/annotations/content")
@@ -191,22 +161,15 @@
for ensemble in content.getchildren():
self.index_ensemble(ensemble, content_obj, project)
-
- self.writer.commit()
@receiver(post_save, sender=Project)
def index_project(sender, **kwargs):
if settings.AUTO_INDEX_AFTER_SAVE:
instance = kwargs['instance']
- writer = ldt.indexation.get_writer()
- try:
- if instance.state != 2:
- ldt.indexation.delete_document("project_id", instance.ldt_id, writer)
- Segment.objects.filter(project_obj__ldt_id=instance.ldt_id).delete() #@UndefinedVariable
- update_stat_project(instance)
- else:
- projectIndexer = ProjectIndexer([instance], writer)
- projectIndexer.index_all()
- update_stat_project(instance)
- finally:
- writer.close()
+ if instance.state != 2:
+ Segment.objects.filter(project_obj__ldt_id=instance.ldt_id).delete() #@UndefinedVariable
+ update_stat_project(instance)
+ else:
+ projectIndexer = ProjectIndexer([instance])
+ projectIndexer.index_all()
+ update_stat_project(instance)