discourse-import_scripts/goss-search.rb

68 lines
2.2 KiB
Ruby
Raw Normal View History

# Federated Computer, Inc.
# David Sainty <saint@federated.computer> 2024 A.D.
# Gossamer Threads to Discourse -- Search By Topic Title
# v0.1 Initial
require 'concurrent-ruby'
require File.expand_path("../../../../config/environment", __FILE__)
class GossamerForumsSearch
def search_topic_by_title(search_string)
puts "Searching for topics with title containing: '#{search_string}'"
# Search for topics with titles containing the search string
matching_topics = Topic.where('title LIKE ?', "%#{search_string}%")
# Print information about each matching topic
matching_topics.each do |topic|
puts "----------------------------------------"
puts "ID: #{topic.id}"
puts "Title: #{topic.title}"
puts "Created At: #{topic.created_at}"
puts "Updated At: #{topic.updated_at}"
puts "Category ID: #{topic.category_id}"
puts "Views: #{topic.views}"
puts "Posts Count: #{topic.posts_count}"
puts "Last Posted At: #{topic.last_posted_at}"
puts "Bumped At: #{topic.bumped_at}"
puts "Last Post User ID: #{topic.last_post_user_id}"
puts "----------------------------------------"
2024-08-29 13:24:36 +00:00
# Fetch and display all posts for the topic
topic.posts.each do |post|
puts " Post ID: #{post.id}"
puts " User ID: #{post.user_id}"
puts " Created At: #{post.created_at}"
puts " Updated At: #{post.updated_at}"
puts " Post Number: #{post.post_number}"
puts " Cooked: #{post.cooked.truncate(80)}" # Limit the display of post content to 100 characters
puts " Raw: #{post.raw.truncate(80)}" # Limit the display of raw post content to 100 characters
puts " ----------------------------------------"
end
end
if matching_topics.empty?
puts "No topics found with title containing: '#{search_string}'"
end
end
def perform_search
puts "Search beginning!"
search_topic_by_title("No father is more proud")
puts "Search complete!"
end
end
# Main execution
if ARGV.length != 1
puts "Usage: #{$0} SEARCH_STRING"
exit 1
end
search_string = ARGV[0]
# search_topic_by_title(search_string)
# GossamerForumsSearch.new.perform_search
GossamerForumsSearch.new.search_topic_by_title(search_string)