Commit fec81ccc authored by Katia Saurfelt's avatar Katia Saurfelt
Browse files

WIP [index] take account of fulltext relations while reindexing entities

parent 9e14ba160e9c
......@@ -22,6 +22,7 @@ import logging
from elasticsearch.exceptions import ConnectionError
from urllib3.exceptions import ProtocolError
from cubicweb import neg_role
from cubicweb.server import hook
from cubicweb.predicates import score_entity
from cubes.elasticsearch.es import indexable_types, fulltext_indexable_rql, CUSTOM_ATTRIBUTES
......@@ -35,15 +36,17 @@ def entity_indexable(entity):
class ContentUpdateIndexES(hook.Hook):
"""detect content change and updates ES indexing"""
"""detect content change and updates ES indexing
"""
__regid__ = 'elasticsearch.contentupdatetoes'
__select__ = hook.Hook.__select__ & score_entity(entity_indexable)
events = ('after_update_entity', 'after_add_entity')
category = 'es'
skip_etypes = ('File', )
def __call__(self):
if self.entity.cw_etype == 'File':
if self.entity.cw_etype in self.skip_etypes:
return # FIXME hack!
IndexEsOperation.get_instance(self._cw).add_data(self.entity)
......@@ -54,16 +57,23 @@ class RelationsUpdateIndexES(hook.Hook):
__regid__ = 'elasticsearch.relationsupdatetoes'
events = ('after_add_relation', 'before_delete_relation')
category = 'es'
skip_etypes = ('File', )
def __call__(self):
# XXX add a selector for object and subject
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':
for rschema, _role in self._cw.vreg.schema[cw_etype].fulltext_containers():
rtype = rschema.type
if rtype == self.rtype:
for _related in entity.related(rtype, role=neg_role(_role)).entities():
IndexEsOperation.get_instance(self._cw).add_data(_related)
continue
if cw_etype in self.skip_etypes:
return # FIXME hack!
if (cw_etype in indexable_types(entity._cw.vreg.schema) or
cw_etype in CUSTOM_ATTRIBUTES):
cw_etype in CUSTOM_ATTRIBUTES):
IndexEsOperation.get_instance(self._cw).add_data(entity)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment