Refactor Post#related_posts to build the index in a different method
This commit is contained in:
parent
ffa93c22f1
commit
09c1c01d07
|
|
@ -229,16 +229,7 @@ module Jekyll
|
||||||
return [] unless posts.size > 1
|
return [] unless posts.size > 1
|
||||||
|
|
||||||
if self.site.lsi
|
if self.site.lsi
|
||||||
self.class.lsi ||= begin
|
build_index
|
||||||
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
|
|
||||||
|
|
||||||
related = self.class.lsi.find_related(self.content, 11)
|
related = self.class.lsi.find_related(self.content, 11)
|
||||||
related - [self]
|
related - [self]
|
||||||
|
|
@ -247,6 +238,19 @@ module Jekyll
|
||||||
end
|
end
|
||||||
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.
|
# Add any necessary layouts to this post.
|
||||||
#
|
#
|
||||||
# layouts - A Hash of {"name" => "layout"}.
|
# layouts - A Hash of {"name" => "layout"}.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue