[index] make adapter a class variable to ease overwriting

authorKatia Saurfelt <katia.saurfelt@logilab.fr>
changeset8373e7642394
branchdefault
phasepublic
hiddenno
parent revision#7cd0a3525b6f Added tag 0.7.4, centos/0.7.4-1, debian/0.7.4-1 for changeset 905b137c2778
child revision#4c5b5c6e7b22 [pkg] prepare 0.7.5
files modified by this revision
cubicweb_elasticsearch/entities.py
# HG changeset patch
# User Katia Saurfelt <katia.saurfelt@logilab.fr>
# Date 1553436815 -3600
# Sun Mar 24 15:13:35 2019 +0100
# Node ID 8373e7642394d15723f76b1a0f4756e5dea024af
# Parent 7cd0a3525b6f3ca772b34cdd565883bdbb91e7f6
[index] make adapter a class variable to ease overwriting

diff --git a/cubicweb_elasticsearch/entities.py b/cubicweb_elasticsearch/entities.py
@@ -48,10 +48,11 @@
1      __registry__ = 'es'
2 
3 
4  class Indexer(EsRegistry):
5      __regid__ = 'indexer'
6 +    adapter = 'IFullTextIndexSerializable'
7      settings = {
8          'settings': {
9              'analysis': {
10                  'analyzer': {
11                      'default': {'filter': ['standard',
@@ -91,11 +92,11 @@
12      def es_index(self, entity, params=None):
13          es_cnx = self.get_connection()
14          if es_cnx is None or not self.index_name:
15              self.error('no connection to ES (not configured) skip ES indexing')
16              return
17 -        serializable = entity.cw_adapt_to('IFullTextIndexSerializable')
18 +        serializable = entity.cw_adapt_to(self.adapter)
19          json = serializable.serialize()
20          if not json:
21              return
22          es_cnx.index(index=self.index_name, id=serializable.es_id,
23                       doc_type=serializable.es_doc_type, body=json,
@@ -104,11 +105,11 @@
24      def es_delete(self, entity):
25          es_cnx = self.get_connection()
26          if es_cnx is None or not self.index_name:
27              self.error('no connection to ES (not configured) skip ES deletion')
28              return
29 -        serializable = entity.cw_adapt_to('IFullTextIndexSerializable')
30 +        serializable = entity.cw_adapt_to(self.adapter)
31          es_cnx.delete(index=self.index_name, id=serializable.es_id,
32                        doc_type=serializable.es_doc_type)
33 
34 
35  class IFullTextIndexSerializable(view.EntityAdapter):