# HG changeset patch
# User Arthur Lutz <arthur.lutz@logilab.fr>
# Date 1472142139 -7200
#      Thu Aug 25 18:22:19 2016 +0200
# Node ID bf904074747b5d0df79b2824e5d13277a286242c
# Parent  848960dc68c1797b393a229937caf3ca33b5294a
[hooks] use indexer from registration, also index types in CUSTOM_TYPES

diff --git a/hooks.py b/hooks.py
--- a/hooks.py
+++ b/hooks.py
@@ -24,13 +24,14 @@
 
 from cubicweb.server import hook
 from cubicweb.predicates import score_entity
-from cubes.elasticsearch.es import indexable_types, fulltext_indexable_rql, get_connection
+from cubes.elasticsearch.es import indexable_types, fulltext_indexable_rql, CUSTOM_ATTRIBUTES
 
 log = logging.getLogger(__name__)
 
 
 def entity_indexable(entity):
-    return entity.cw_etype in indexable_types(entity._cw.vreg.schema)
+    return entity.cw_etype in indexable_types(entity._cw.vreg.schema) or \
+        entity.cw_etype in CUSTOM_ATTRIBUTES
 
 
 class ContentUpdateIndexES(hook.Hook):
@@ -45,7 +46,8 @@
     def __call__(self):
         if self.entity.cw_etype == 'File':
             return  # FIXME hack!
-        es = get_connection(self._cw.vreg.config)
+        indexer = self.entity._cw.vreg['es'].select('indexer', self.entity._cw)
+        es = indexer.get_connection()
         if es:
             rql = fulltext_indexable_rql(self.entity.cw_etype,
                                          self.entity._cw.vreg.schema,