71 repo = session.repo |
71 repo = session.repo |
72 cursor = session.pool['system'] |
72 cursor = session.pool['system'] |
73 if not repo.system_source.dbhelper.has_fti_table(cursor): |
73 if not repo.system_source.dbhelper.has_fti_table(cursor): |
74 print 'no text index table' |
74 print 'no text index table' |
75 dbhelper.init_fti(cursor) |
75 dbhelper.init_fti(cursor) |
76 repo.config.disabled_hooks_categories.add('metadata') |
|
77 repo.config.disabled_hooks_categories.add('integrity') |
|
78 repo.system_source.do_fti = True # ensure full-text indexation is activated |
76 repo.system_source.do_fti = True # ensure full-text indexation is activated |
79 etypes = set() |
77 etypes = set() |
80 for eschema in schema.entities(): |
78 for eschema in schema.entities(): |
81 if eschema.final: |
79 if eschema.final: |
82 continue |
80 continue |
88 print 'Reindexing entities of type %s' % \ |
86 print 'Reindexing entities of type %s' % \ |
89 ', '.join(sorted(str(e) for e in etypes)) |
87 ', '.join(sorted(str(e) for e in etypes)) |
90 if withpb: |
88 if withpb: |
91 pb = ProgressBar(len(etypes) + 1) |
89 pb = ProgressBar(len(etypes) + 1) |
92 # first monkey patch Entity.check to disable validation |
90 # first monkey patch Entity.check to disable validation |
93 from cubicweb.entity import Entity |
|
94 _check = Entity.check |
|
95 Entity.check = lambda self, creation=False: True |
|
96 # clear fti table first |
91 # clear fti table first |
97 session.system_sql('DELETE FROM %s' % session.repo.system_source.dbhelper.fti_table) |
92 session.system_sql('DELETE FROM %s' % session.repo.system_source.dbhelper.fti_table) |
98 if withpb: |
93 if withpb: |
99 pb.update() |
94 pb.update() |
100 # reindex entities by generating rql queries which set all indexable |
95 # reindex entities by generating rql queries which set all indexable |
101 # attribute to their current value |
96 # attribute to their current value |
102 source = repo.system_source |
97 source = repo.system_source |
103 for eschema in etypes: |
98 for eschema in etypes: |
104 for entity in session.execute('Any X WHERE X is %s' % eschema).entities(): |
99 for entity in session.execute('Any X WHERE X is %s' % eschema).entities(): |
105 source.fti_unindex_entity(session, entity.eid) |
|
106 source.fti_index_entity(session, entity) |
100 source.fti_index_entity(session, entity) |
107 if withpb: |
101 if withpb: |
108 pb.update() |
102 pb.update() |
109 # restore Entity.check |
|
110 Entity.check = _check |
|
111 repo.config.disabled_hooks_categories.remove('metadata') |
|
112 repo.config.disabled_hooks_categories.remove('integrity') |
|
113 |
103 |
114 |
104 |
115 def check_schema(schema, session, eids, fix=1): |
105 def check_schema(schema, session, eids, fix=1): |
116 """check serialized schema""" |
106 """check serialized schema""" |
117 print 'Checking serialized schema' |
107 print 'Checking serialized schema' |