Created
September 8, 2012 17:26
-
-
Save ls-lukebowerman/3677557 to your computer and use it in GitHub Desktop.
Middleman/IndexTank content loading script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'indextank' | |
api_client = IndexTank::Client.new 'http://:[email protected]' | |
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