Class: TaggerJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/tagger_job.rb

Defined Under Namespace

Classes: WordsCollection

Instance Method Summary collapse

Instance Method Details

#perform(post) ⇒ Object


59
60
61
62
63
64
65
66
67
68
# File 'app/jobs/tagger_job.rb', line 59

def perform(post)
  text = post.title + ' ' + post.body

  # разбиваем текст на блоки по 300 слов, чтобы не занимать много памяти
  tags = text.split(/[^[:alnum:]]+/).in_groups_of(300, false).map do |words|
    match_tags(words.join(' '))
  end.flatten.uniq

  apply_tags(post, tags)
end