Refactor Post#related_posts to build the index in a different method

This commit is contained in:
Parker Moore 2013-04-26 20:05:52 +02:00
parent ffa93c22f1
commit 09c1c01d07
1 changed files with 14 additions and 10 deletions

View File

@ -229,16 +229,7 @@ module Jekyll
return [] unless posts.size > 1
if self.site.lsi
self.class.lsi ||= begin
puts "Starting the classifier..."
lsi = Classifier::LSI.new(:auto_rebuild => false)
$stdout.print(" Populating LSI... ");$stdout.flush
posts.each { |x| $stdout.print(".");$stdout.flush;lsi.add_item(x) }
$stdout.print("\n Rebuilding LSI index... ")
lsi.build_index
puts ""
lsi
end
build_index
related = self.class.lsi.find_related(self.content, 11)
related - [self]
@ -247,6 +238,19 @@ module Jekyll
end
end
def build_index
self.class.lsi ||= begin
puts "Starting the classifier..."
lsi = Classifier::LSI.new(:auto_rebuild => false)
$stdout.print(" Populating LSI... "); $stdout.flush
posts.each { |x| $stdout.print("."); $stdout.flush; lsi.add_item(x) }
$stdout.print("\n Rebuilding LSI index... ")
lsi.build_index
puts ""
lsi
end
end
# Add any necessary layouts to this post.
#
# layouts - A Hash of {"name" => "layout"}.