discourse-import_scripts/goss-search.rb

56 lines
1.7 KiB
Ruby

# 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 "----------------------------------------"
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)