Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save himkt/2303b91f212fea6278e353cba995bc2b to your computer and use it in GitHub Desktop.
Save himkt/2303b91f212fea6278e353cba995bc2b to your computer and use it in GitHub Desktop.
BATCH_SIZE = 100
service = HashtagService.new
search_options = HashtagService::SEARCH_OPTIONS.merge(per_page: 20)
PopularQuery.order(uu: :desc).limit(100).each_slice(BATCH_SIZE).with_index(1) do |popular_queries, index|
puts "##{index} processing (#{Time.new})"
hashtags_list = popular_queries
.map { |popular_query| Tsukurepo2Hashtag.search_by_keyword(popular_query.canonical_keyword, search_options).search }
.then { |searches| Search::Utils.multi_search(searches) }
.map { |response| response.records.to_a }
popular_queries.zip(hashtags_list).each do |query, hashtags|
hashtags.each do |hashtag|
request = NaraBackend::Services::V1::ListHashtagSuggestionsRequest.new(keyword: query.canonical_keyword, hashtag_id: hashtag.id)
response = service.list_hashtag_suggestions(request, nil)
hashtag_names = response.suggested_hashtags.map { |suggestion| suggestion.hashtag.name }
puts "#{query.keyword}x#{hashtag.name}: #{hashtag_names.join(', ')}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment