Skip to content

Commit b6e9f27

Browse files
committed
feat: add search tasks for Elasticsearch reindexing and management
1 parent 3c18c82 commit b6e9f27

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

lib/tasks/generate.rake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,50 @@ namespace :better_together do # rubocop:todo Metrics/BlockLength
1212
BetterTogether::NavigationBuilder.build(clear: true)
1313
end
1414

15+
desc 'Reset navigation areas only (preserves pages)'
16+
task reset_navigation: :environment do
17+
BetterTogether::NavigationBuilder.reset_navigation_areas
18+
end
19+
20+
desc 'Reset specific navigation area (usage: rake better_together:generate:reset_navigation_area[platform-header])'
21+
task :reset_navigation_area, [:slug] => :environment do |_t, args|
22+
if args[:slug].blank?
23+
puts 'Error: Please provide a navigation area slug'
24+
puts 'Available slugs: platform-header, platform-host, better-together, platform-footer'
25+
puts 'Usage: rake better_together:generate:reset_navigation_area[platform-header]'
26+
exit 1
27+
end
28+
29+
BetterTogether::NavigationBuilder.reset_navigation_area(args[:slug])
30+
end
31+
32+
desc 'List all navigation areas and items'
33+
task list_navigation: :environment do
34+
puts "\nNavigation Areas:"
35+
puts '=' * 80
36+
37+
BetterTogether::NavigationArea.i18n.order(:slug).each do |area|
38+
puts "\nArea: #{area.name}"
39+
puts " Slug: #{area.slug}"
40+
puts " Visible: #{area.visible}"
41+
puts " Protected: #{area.protected}"
42+
puts " Items: #{area.navigation_items.count}"
43+
44+
next unless area.navigation_items.any?
45+
46+
puts ' Navigation Items:'
47+
area.navigation_items.where(parent_id: nil).order(:position).each do |item|
48+
puts " - #{item.title} (#{item.item_type})"
49+
next unless item.children.any?
50+
51+
item.children.order(:position).each do |child|
52+
puts " └─ #{child.title} (#{child.item_type})"
53+
end
54+
end
55+
end
56+
puts "\n#{'=' * 80}"
57+
end
58+
1559
desc 'Generate setup wizard and step definitions'
1660
task setup_wizard: :environment do
1761
BetterTogether::SetupWizardBuilder.build(clear: true)

lib/tasks/search.rake

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)