|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +namespace :better_together do # rubocop:todo Metrics/BlockLength |
| 4 | + namespace :search do # rubocop:todo Metrics/BlockLength |
| 5 | + desc 'Reindex all searchable models in Elasticsearch' |
| 6 | + task reindex_all: :environment do |
| 7 | + puts 'Reindexing all searchable models...' |
| 8 | + |
| 9 | + # Reindex Pages (includes template blocks and rich text blocks) |
| 10 | + puts 'Reindexing Pages...' |
| 11 | + BetterTogether::Page.elastic_import(force: true) |
| 12 | + puts "✓ Reindexed #{BetterTogether::Page.count} pages" |
| 13 | + |
| 14 | + # Add other searchable models here as needed |
| 15 | + # BetterTogether::OtherModel.elastic_import(force: true) |
| 16 | + |
| 17 | + puts 'Reindexing complete!' |
| 18 | + end |
| 19 | + |
| 20 | + desc 'Reindex Pages with their template blocks and rich text blocks' |
| 21 | + task reindex_pages: :environment do |
| 22 | + puts 'Reindexing Pages with template blocks and rich text blocks...' |
| 23 | + BetterTogether::Page.elastic_import(force: true) |
| 24 | + puts "✓ Reindexed #{BetterTogether::Page.count} pages" |
| 25 | + end |
| 26 | + |
| 27 | + desc 'Refresh Elasticsearch indices' |
| 28 | + task refresh: :environment do |
| 29 | + puts 'Refreshing Elasticsearch indices...' |
| 30 | + BetterTogether::Page.refresh_elastic_index! |
| 31 | + puts '✓ Indices refreshed' |
| 32 | + end |
| 33 | + |
| 34 | + desc 'Delete and recreate Elasticsearch indices' |
| 35 | + task recreate_indices: :environment do |
| 36 | + puts 'WARNING: This will delete all existing search indices and recreate them.' |
| 37 | + puts 'Press Ctrl+C to cancel, or Enter to continue...' |
| 38 | + $stdin.gets |
| 39 | + |
| 40 | + puts 'Deleting existing indices...' |
| 41 | + BetterTogether::Page.delete_elastic_index! |
| 42 | + puts '✓ Indices deleted' |
| 43 | + |
| 44 | + puts 'Creating new indices...' |
| 45 | + BetterTogether::Page.create_elastic_index! |
| 46 | + puts '✓ Indices created' |
| 47 | + |
| 48 | + puts 'Reindexing all data...' |
| 49 | + BetterTogether::Page.elastic_import(force: true) |
| 50 | + puts "✓ Reindexed #{BetterTogether::Page.count} pages" |
| 51 | + |
| 52 | + puts 'Index recreation complete!' |
| 53 | + end |
| 54 | + end |
| 55 | +end |
0 commit comments