Class: PG::FTS::Index::MOMO

Inherits:
Object
  • Object
show all
Includes:
PG::FTS::Index, Naming, TSVector
Defined in:
lib/pg/fts/index/momo.rb

Overview

many documents, one link, many links, one source

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, *fields, document: nil, link: nil, key: nil, foreign_key: nil, forlink_key: nil, catalog: nil, as: nil) ⇒ MOMO

rubocop:disable Metrics/ParameterLists, Metrics/CyclomaticComplexity



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pg/fts/index/momo.rb', line 14

def initialize(table, *fields,
               document: nil, link: nil,
               key: nil, foreign_key: nil, forlink_key: nil,
               catalog: nil,
               as: nil)
  @table = table
  @fields = fields
  @catalog = catalog || PG::FTS.catalog
  @document = document || fail(ArgumentError, ':document required')
  @link = link || fail(ArgumentError, ':link required')
  @key = key || :id
  @foreign_key = foreign_key || :"#{table}_id"
  @forlink_key = forlink_key || :"#{link}_id"
  @name = as
end

Instance Attribute Details

#catalogObject (readonly)

Returns the value of attribute catalog.



3
4
5
# File 'lib/pg/fts/index/momo.rb', line 3

def catalog
  @catalog
end

#documentObject (readonly)

Returns the value of attribute document.



3
4
5
# File 'lib/pg/fts/index/momo.rb', line 3

def document
  @document
end

#fieldsObject (readonly)

Returns the value of attribute fields.



3
4
5
# File 'lib/pg/fts/index/momo.rb', line 3

def fields
  @fields
end

#foreign_keyObject (readonly)

Returns the value of attribute foreign_key.



3
4
5
# File 'lib/pg/fts/index/momo.rb', line 3

def foreign_key
  @foreign_key
end

Returns the value of attribute forlink_key.



3
4
5
# File 'lib/pg/fts/index/momo.rb', line 3

def forlink_key
  @forlink_key
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/pg/fts/index/momo.rb', line 3

def key
  @key
end

Returns the value of attribute link.



3
4
5
# File 'lib/pg/fts/index/momo.rb', line 3

def link
  @link
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/pg/fts/index/momo.rb', line 3

def name
  @name
end

#tableObject (readonly) Also known as: source

Returns the value of attribute table.



3
4
5
# File 'lib/pg/fts/index/momo.rb', line 3

def table
  @table
end

Instance Method Details

#build_queryObject

rubocop:enable Metrics/ParameterLists, Metrics/CyclomaticComplexity



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pg/fts/index/momo.rb', line 31

def build_query
  "  INSERT INTO \"\#{PG::FTS.table}\" (\n    \"document_id\",\n    \"document_table\",\n    \"source_id\",\n    \"source_table\",\n    \"tsv\")\n  SELECT \"\#{document}\".\"\#{key}\",\n         '\#{document}',\n         \"\#{source}\".\"\#{key}\",\n         '\#{source}',\n         \#{ts_vector(source)}\n  FROM \"\#{document}\", \"\#{source}\", \"\#{link}\"\n  WHERE \"\#{document}\".\"\#{forlink_key}\" = \"\#{link}\".\"\#{key}\"\n    AND \"\#{link}\".\"\#{foreign_key}\" = \"\#{source}\".\"\#{key}\";\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_delete_procedureObject



285
286
287
288
289
290
291
292
293
294
295
# File 'lib/pg/fts/index/momo.rb', line 285

def on_document_delete_procedure
  "  CREATE FUNCTION \"\#{on_document_delete_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_document_delete_query.gsub(/^/, '    ')}\n      RETURN OLD;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_delete_queryObject



273
274
275
276
277
278
279
280
281
282
283
# File 'lib/pg/fts/index/momo.rb', line 273

def on_document_delete_query
  "  DELETE FROM \"\#{PG::FTS.table}\"\n        USING \"\#{link}\"\n  WHERE \"\#{link}\".\"\#{key}\" = OLD.\"\#{forlink_key}\"\n    AND \"\#{PG::FTS.table}\".\"source_id\" = \"\#{link}\".\"\#{foreign_key}\"\n    AND \"\#{PG::FTS.table}\".\"source_table\" = '\#{source}'\n    AND \"\#{PG::FTS.table}\".\"document_id\" = OLD.\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"document_table\" = '\#{document}';\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_delete_triggerObject



335
336
337
338
339
340
341
342
# File 'lib/pg/fts/index/momo.rb', line 335

def on_document_delete_trigger
  "  CREATE TRIGGER \"\#{on_document_delete_trigger_name}\"\n  AFTER DELETE ON \"\#{document}\"\n  FOR EACH ROW\n  EXECUTE PROCEDURE \"\#{on_document_delete_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_insert_procedureObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/pg/fts/index/momo.rb', line 208

def on_document_insert_procedure
  "  CREATE FUNCTION \"\#{on_document_insert_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      IF NEW.\"\#{forlink_key}\" IS NULL THEN\n        RETURN NEW;\n      END IF;\n      \#{on_document_insert_query.gsub(/^/, '    ')}\n      RETURN NEW;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_insert_queryObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/pg/fts/index/momo.rb', line 188

def on_document_insert_query
  "  INSERT INTO \"\#{PG::FTS.table}\" (\n    \"document_id\",\n    \"document_table\",\n    \"source_id\",\n    \"source_table\",\n    \"tsv\")\n  SELECT\n    NEW.\"\#{key}\",\n    '\#{document}',\n    \"\#{source}\".\"\#{key}\",\n    '\#{source}',\n    \#{ts_vector(source)}\n  FROM \"\#{source}\", \"\#{link}\"\n  WHERE \"\#{source}\".\"\#{key}\" = \"\#{link}\".\"\#{foreign_key}\"\n    AND \"\#{link}\".\"\#{key}\" = NEW.\"\#{forlink_key}\";\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_insert_triggerObject



317
318
319
320
321
322
323
324
# File 'lib/pg/fts/index/momo.rb', line 317

def on_document_insert_trigger
  "  CREATE TRIGGER \"\#{on_document_insert_trigger_name}\"\n  AFTER INSERT ON \"\#{document}\"\n  FOR EACH ROW\n  EXECUTE PROCEDURE \"\#{on_document_insert_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_truncate_procedureObject



305
306
307
308
309
310
311
312
313
314
315
# File 'lib/pg/fts/index/momo.rb', line 305

def on_document_truncate_procedure
  "  CREATE FUNCTION \"\#{on_document_truncate_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_document_truncate_query.gsub(/^/, '    ')}\n      RETURN NULL;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_truncate_queryObject



297
298
299
300
301
302
303
# File 'lib/pg/fts/index/momo.rb', line 297

def on_document_truncate_query
  "  DELETE FROM \"\#{PG::FTS.table}\"\n  WHERE \"\#{PG::FTS.table}\".\"source_table\" = '\#{source}'\n    AND \"\#{PG::FTS.table}\".\"document_table\" = '\#{document}';\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_truncate_triggerObject



344
345
346
347
348
349
350
351
# File 'lib/pg/fts/index/momo.rb', line 344

def on_document_truncate_trigger
  "  CREATE TRIGGER \"\#{on_document_truncate_trigger_name}\"\n  AFTER TRUNCATE ON \"\#{document}\"\n  FOR EACH STATEMENT\n  EXECUTE PROCEDURE \"\#{on_document_truncate_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_update_procedureObject



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/pg/fts/index/momo.rb', line 243

def on_document_update_procedure
  "  CREATE FUNCTION \"\#{on_document_update_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      IF NEW.\"\#{forlink_key}\" IS NULL AND OLD.\"\#{forlink_key}\" IS NULL THEN\n        RETURN NEW;\n      END IF;\n      IF NEW.\"\#{forlink_key}\" IS NULL THEN\n        \#{on_document_delete_query.gsub(/^/, '      ')}\n        RETURN NEW;\n      END IF;\n      IF OLD.\"\#{forlink_key}\" IS NULL THEN\n        \#{on_document_insert_query.gsub(/^/, '      ')}\n        RETURN NEW;\n      END IF;\n      \#{on_document_update_query.gsub(/^/, '    ')}\n      IF NOT FOUND THEN\n          \#{on_document_insert_query.gsub(/^/, '      ')}\n        IF NOT FOUND THEN\n          \#{on_document_delete_query.gsub(/^/, '      ')}\n        END IF;\n        RETURN NEW;\n      END IF;\n      RETURN NEW;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_update_queryObject



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/pg/fts/index/momo.rb', line 223

def on_document_update_query
  "  UPDATE \"\#{PG::FTS.table}\"\n  SET\n    \"tsv\" = (\#{ts_vector(source)}),\n    \"source_table\" = '\#{source}',\n    \"source_id\" = \"\#{source}\".\"\#{key}\"\n  FROM \"\#{source}\" AS \"OLD_\#{source}\", \"\#{source}\",\n        \"\#{link}\" AS \"OLD_\#{link}\", \"\#{link}\"\n  WHERE \"OLD_\#{source}\".\"\#{key}\" = \"OLD_\#{link}\".\"\#{foreign_key}\"\n    AND \"OLD_\#{link}\".\"\#{key}\" = OLD.\"\#{forlink_key}\"\n    AND \"\#{source}\".\"\#{key}\" = \"\#{link}\".\"\#{foreign_key}\"\n    AND \"\#{link}\".\"\#{key}\" = NEW.\"\#{forlink_key}\"\n    AND \"\#{PG::FTS.table}\".\"source_id\" = \"OLD_\#{link}\".\"\#{foreign_key}\"\n    AND \"\#{PG::FTS.table}\".\"source_table\" = '\#{source}'\n    AND \"\#{PG::FTS.table}\".\"document_id\" = OLD.\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"document_table\" = '\#{document}';\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_document_update_triggerObject



326
327
328
329
330
331
332
333
# File 'lib/pg/fts/index/momo.rb', line 326

def on_document_update_trigger
  "  CREATE TRIGGER \"\#{on_document_update_trigger_name}\"\n  AFTER UPDATE ON \"\#{document}\"\n  FOR EACH ROW\n  EXECUTE PROCEDURE \"\#{on_document_update_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')


436
437
438
439
440
441
442
443
444
445
446
# File 'lib/pg/fts/index/momo.rb', line 436

def on_link_delete_procedure
  "  CREATE FUNCTION \"\#{on_link_delete_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_link_delete_query.gsub(/^/, '    ')}\n      RETURN OLD;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')


423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/pg/fts/index/momo.rb', line 423

def on_link_delete_query
  "  DELETE FROM \"\#{PG::FTS.table}\"\n        USING \"\#{link}\", \"\#{document}\", \"\#{source}\"\n  WHERE OLD.\"\#{key}\" = \"\#{document}\".\"\#{forlink_key}\"\n    AND OLD.\"\#{foreign_key}\" = \"\#{source}\".\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"source_id\" = \"\#{source}\".\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"source_table\" = '\#{source}'\n    AND \"\#{PG::FTS.table}\".\"document_id\" = \"\#{document}\".\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"document_table\" = '\#{document}';\n  SQL\nend\n".gsub(/^ {4}/, '')


486
487
488
489
490
491
492
493
# File 'lib/pg/fts/index/momo.rb', line 486

def on_link_delete_trigger
  "  CREATE TRIGGER \"\#{on_link_delete_trigger_name}\"\n  AFTER DELETE ON \"\#{link}\"\n  FOR EACH ROW\n  EXECUTE PROCEDURE \"\#{on_link_delete_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')


373
374
375
376
377
378
379
380
381
382
383
# File 'lib/pg/fts/index/momo.rb', line 373

def on_link_insert_procedure
  "  CREATE FUNCTION \"\#{on_link_insert_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_link_insert_query.gsub(/^/, '    ')}\n      RETURN NEW;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')


353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/pg/fts/index/momo.rb', line 353

def on_link_insert_query
  "  INSERT INTO \"\#{PG::FTS.table}\" (\n    \"document_id\",\n    \"document_table\",\n    \"source_id\",\n    \"source_table\",\n    \"tsv\")\n  SELECT\n    \"\#{document}\".\"\#{key}\",\n    '\#{document}',\n    \"\#{source}\".\"\#{key}\",\n    '\#{source}',\n    \#{ts_vector(source)}\n  FROM \"\#{document}\", \"\#{source}\"\n  WHERE \"\#{document}\".\"\#{forlink_key}\" = NEW.\"\#{key}\"\n    AND \"\#{source}\".\"\#{key}\" = NEW.\"\#{foreign_key}\";\n  SQL\nend\n".gsub(/^ {4}/, '')


468
469
470
471
472
473
474
475
# File 'lib/pg/fts/index/momo.rb', line 468

def on_link_insert_trigger
  "  CREATE TRIGGER \"\#{on_link_insert_trigger_name}\"\n  AFTER INSERT ON \"\#{link}\"\n  FOR EACH ROW\n  EXECUTE PROCEDURE \"\#{on_link_insert_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')


456
457
458
459
460
461
462
463
464
465
466
# File 'lib/pg/fts/index/momo.rb', line 456

def on_link_truncate_procedure
  "  CREATE FUNCTION \"\#{on_link_truncate_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_link_truncate_query.gsub(/^/, '    ')}\n      RETURN NULL;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')


448
449
450
451
452
453
454
# File 'lib/pg/fts/index/momo.rb', line 448

def on_link_truncate_query
  "  DELETE FROM \"\#{PG::FTS.table}\"\n  WHERE \"\#{PG::FTS.table}\".\"source_table\" = '\#{source}'\n    AND \"\#{PG::FTS.table}\".\"document_table\" = '\#{document}';\n  SQL\nend\n".gsub(/^ {4}/, '')


495
496
497
498
499
500
501
502
# File 'lib/pg/fts/index/momo.rb', line 495

def on_link_truncate_trigger
  "  CREATE TRIGGER \"\#{on_link_truncate_trigger_name}\"\n  AFTER TRUNCATE ON \"\#{link}\"\n  FOR EACH STATEMENT\n  EXECUTE PROCEDURE \"\#{on_link_truncate_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')


404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/pg/fts/index/momo.rb', line 404

def on_link_update_procedure
  "  CREATE FUNCTION \"\#{on_link_update_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_link_update_query.gsub(/^/, '    ')}\n      IF NOT FOUND THEN\n        \#{on_link_insert_query.gsub(/^/, '      ')}\n        IF NOT FOUND THEN\n          \#{on_link_delete_query.gsub(/^/, '        ')}\n        END IF;\n        RETURN NEW;\n      END IF;\n      RETURN NEW;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')


385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/pg/fts/index/momo.rb', line 385

def on_link_update_query
  "  UPDATE \"\#{PG::FTS.table}\"\n  SET\n    \"tsv\" = (\#{ts_vector(source)}),\n    \"document_table\" = '\#{document}',\n    \"document_id\" = \"\#{document}\".\"\#{key}\",\n    \"source_table\" = '\#{source}',\n    \"source_id\" = NEW.\"\#{foreign_key}\"\n  FROM \"\#{document}\", \"\#{link}\", \"\#{source}\"\n  WHERE \"\#{document}\".\"\#{forlink_key}\" = OLD.\"\#{key}\"\n    AND NEW.\"\#{foreign_key}\" = \"\#{source}\".\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"source_id\" = OLD.\"\#{foreign_key}\"\n    AND \"\#{PG::FTS.table}\".\"source_table\" = '\#{source}'\n    AND \"\#{PG::FTS.table}\".\"document_id\" = \"\#{document}\".\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"document_table\" = '\#{document}';\n  SQL\nend\n".gsub(/^ {4}/, '')


477
478
479
480
481
482
483
484
# File 'lib/pg/fts/index/momo.rb', line 477

def on_link_update_trigger
  "  CREATE TRIGGER \"\#{on_link_update_trigger_name}\"\n  AFTER UPDATE ON \"\#{link}\"\n  FOR EACH ROW\n  EXECUTE PROCEDURE \"\#{on_link_update_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_delete_procedureObject



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/pg/fts/index/momo.rb', line 120

def on_source_delete_procedure
  "  CREATE FUNCTION \"\#{on_source_delete_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_source_delete_query.gsub(/^/, '    ')}\n      RETURN OLD;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_delete_queryObject



111
112
113
114
115
116
117
118
# File 'lib/pg/fts/index/momo.rb', line 111

def on_source_delete_query
  "  DELETE FROM \"\#{PG::FTS.table}\"\n  WHERE \"\#{PG::FTS.table}\".\"source_id\" = OLD.\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"source_table\" = '\#{source}'\n    AND \"\#{PG::FTS.table}\".\"document_table\" = '\#{document}';\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_delete_triggerObject



170
171
172
173
174
175
176
177
# File 'lib/pg/fts/index/momo.rb', line 170

def on_source_delete_trigger
  "  CREATE TRIGGER \"\#{on_source_delete_trigger_name}\"\n  AFTER DELETE ON \"\#{source}\"\n  FOR EACH ROW\n  EXECUTE PROCEDURE \"\#{on_source_delete_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_insert_procedureObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/pg/fts/index/momo.rb', line 70

def on_source_insert_procedure
  "  CREATE FUNCTION \"\#{on_source_insert_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_source_insert_query.gsub(/^/, '    ')}\n      RETURN NEW;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_insert_queryObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pg/fts/index/momo.rb', line 50

def on_source_insert_query
  "  INSERT INTO \"\#{PG::FTS.table}\" (\n    \"document_id\",\n    \"document_table\",\n    \"source_id\",\n    \"source_table\",\n    \"tsv\")\n  SELECT\n    \"\#{document}\".\"\#{key}\",\n    '\#{document}',\n    NEW.\"\#{key}\",\n    '\#{source}',\n    \#{ts_vector}\n  FROM \"\#{document}\", \"\#{link}\"\n  WHERE \"\#{document}\".\"\#{forlink_key}\" = \"\#{link}\".\"\#{key}\"\n    AND \"\#{link}\".\"\#{foreign_key}\" = NEW.\"\#{key}\";\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_insert_triggerObject



152
153
154
155
156
157
158
159
# File 'lib/pg/fts/index/momo.rb', line 152

def on_source_insert_trigger
  "  CREATE TRIGGER \"\#{on_source_insert_trigger_name}\"\n  AFTER INSERT ON \"\#{source}\"\n  FOR EACH ROW\n  EXECUTE PROCEDURE \"\#{on_source_insert_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_truncate_procedureObject



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/pg/fts/index/momo.rb', line 140

def on_source_truncate_procedure
  "  CREATE FUNCTION \"\#{on_source_truncate_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_source_truncate_query.gsub(/^/, '    ')}\n      RETURN NULL;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_truncate_queryObject



132
133
134
135
136
137
138
# File 'lib/pg/fts/index/momo.rb', line 132

def on_source_truncate_query
  "  DELETE FROM \"\#{PG::FTS.table}\"\n  WHERE \"\#{PG::FTS.table}\".\"source_table\" = '\#{source}'\n    AND \"\#{PG::FTS.table}\".\"document_table\" = '\#{document}';\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_truncate_triggerObject



179
180
181
182
183
184
185
186
# File 'lib/pg/fts/index/momo.rb', line 179

def on_source_truncate_trigger
  "  CREATE TRIGGER \"\#{on_source_truncate_trigger_name}\"\n  AFTER TRUNCATE ON \"\#{source}\"\n  FOR EACH STATEMENT\n  EXECUTE PROCEDURE \"\#{on_source_truncate_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_update_procedureObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pg/fts/index/momo.rb', line 99

def on_source_update_procedure
  "  CREATE FUNCTION \"\#{on_source_update_procedure_name}\"()\n  RETURNS TRIGGER AS $$\n    BEGIN\n      \#{on_source_update_query.gsub(/^/, '    ')}\n      RETURN NEW;\n    END;\n  $$ LANGUAGE plpgsql;\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_update_queryObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pg/fts/index/momo.rb', line 82

def on_source_update_query
  "  UPDATE \"\#{PG::FTS.table}\"\n  SET\n    \"tsv\" = (\#{ts_vector}),\n    \"document_table\" = '\#{document}',\n    \"document_id\" = \"\#{document}\".\"\#{key}\"\n  FROM \"\#{document}\", \"\#{link}\"\n  WHERE \"\#{document}\".\"\#{forlink_key}\" = \"\#{link}\".\"\#{key}\"\n    AND \"\#{link}\".\"\#{foreign_key}\" = NEW.\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"source_id\" = OLD.\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"source_table\" = '\#{source}'\n    AND \"\#{PG::FTS.table}\".\"document_id\" = \"\#{document}\".\"\#{key}\"\n    AND \"\#{PG::FTS.table}\".\"document_table\" = '\#{document}';\n  SQL\nend\n".gsub(/^ {4}/, '')

#on_source_update_triggerObject



161
162
163
164
165
166
167
168
# File 'lib/pg/fts/index/momo.rb', line 161

def on_source_update_trigger
  "  CREATE TRIGGER \"\#{on_source_update_trigger_name}\"\n  AFTER UPDATE ON \"\#{source}\"\n  FOR EACH ROW\n  EXECUTE PROCEDURE \"\#{on_source_update_procedure_name}\"();\n  SQL\nend\n".gsub(/^ {4}/, '')