Skip to content

Instantly share code, notes, and snippets.

@ls-lukebowerman
Created September 8, 2012 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ls-lukebowerman/3677557 to your computer and use it in GitHub Desktop.
Save ls-lukebowerman/3677557 to your computer and use it in GitHub Desktop.
Middleman/IndexTank content loading script
require 'rubygems'
require 'indextank'
api_client = IndexTank::Client.new 'http://:YOURKEY@YOURURL.api.indexden.com'
help_index = api_client.indexes 'help'
require 'json'
# Build fresh sitemap.json
# `middleman build -g help/sitemap.json`
json = File.read('build/help/sitemap.json')
# Delete and recreate index
help_index.delete()
help_index.add(:public_search => true)
pages = JSON.parse(json)
docs = []
pages.each do |page|
# puts "Pushing - #{page['title']} (#{page['url']})"
docs << { :docid => page['url'], :fields => { :title => page['title'], :description => page['description'], :text => page['content'] }}
end
puts "Inserted #{docs.size} documents into index"
help_index.batch_insert(docs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment