Created
June 19, 2020 07:00
-
-
Save himkt/2303b91f212fea6278e353cba995bc2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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