# HG changeset patch # User Katia Saurfelt <katia.saurfelt@logilab.fr> # Date 1489072463 -3600 # Thu Mar 09 16:14:23 2017 +0100 # Node ID 372faf22c1e38586c044fa17c05c5e1e0687640e # Parent 4223ea3c88ceed601f4d62e03a85314fb87cccfa implement a IFullTextIndexSerializable for File diff --git a/entities.py b/entities.py --- a/entities.py +++ b/entities.py @@ -19,7 +19,7 @@ import collections -from cubicweb import view +from cubicweb import view, neg_role from cubicweb.predicates import is_instance from cubicweb.appobject import AppObject @@ -109,3 +109,20 @@ data['parent'] = entity.entry_of[0] """ pass + + +class File(IFullTextIndexSerializable): + __select__ = IFullTextIndexSerializable.__select__ & is_instance('File') + + def serialize(self, complete=False): + """this could be a generic implementation of fulltext_containers indexation, but for + + now we can not return more than one parent json which is fine + for Files + """ + for rschema, role in self._cw.vreg.schema['File'].fulltext_containers(): + for parent in self.entity.related( + rschema.type, role=neg_role(role)).entities(): + return parent.cw_adapt_to( + 'IFullTextIndexSerializable').serialize(complete) + return {} diff --git a/hooks.py b/hooks.py --- a/hooks.py +++ b/hooks.py @@ -43,8 +43,6 @@ category = 'es' def __call__(self): - if self.entity.cw_etype == 'File': - return # FIXME hack! IndexEsOperation.get_instance(self._cw).add_data(self.entity) @@ -60,8 +58,6 @@ for entity in (self._cw.entity_from_eid(self.eidfrom), self._cw.entity_from_eid(self.eidto)): cw_etype = entity.cw_etype - if cw_etype == 'File': - return # FIXME hack! if (cw_etype in indexable_types(entity._cw.vreg.schema) or cw_etype in CUSTOM_ATTRIBUTES): IndexEsOperation.get_instance(self._cw).add_data(entity)