class Bunto::RelatedPosts

Attributes

lsi[RW]
post[R]
site[R]

Public Class Methods

new(post) click to toggle source
# File lib/bunto/related_posts.rb, line 9
def initialize(post)
  @post = post
  @site = post.site
  Bunto::External.require_with_graceful_fail("classifier-reborn") if site.lsi
end

Public Instance Methods

build() click to toggle source
# File lib/bunto/related_posts.rb, line 15
def build
  return [] unless site.posts.docs.size > 1

  if site.lsi
    build_index
    lsi_related_posts
  else
    most_recent_posts
  end
end
build_index() click to toggle source
# File lib/bunto/related_posts.rb, line 26
def build_index
  self.class.lsi ||= begin
    lsi = ClassifierReborn::LSI.new(:auto_rebuild => false)
    Bunto.logger.info("Populating LSI...")

    site.posts.docs.each do |x|
      lsi.add_item(x)
    end

    Bunto.logger.info("Rebuilding index...")
    lsi.build_index
    Bunto.logger.info("")
    lsi
  end
end
most_recent_posts() click to toggle source
# File lib/bunto/related_posts.rb, line 46
def most_recent_posts
  @most_recent_posts ||= (site.posts.docs.reverse - [post]).first(10)
end