Skip to content

Instantly share code, notes, and snippets.

@nz
nz / http.rb
Last active October 27, 2021 11:09
Wrapper to RestClient for RESTful JSON APIs, like ElasticSearch. TODO: rebuild with Faraday.
# A light wrapper around RestClient which centralizes a few things for us:
#
# - Light accessors for the method option.
# - JSON by default. If we need others in the future, maybe submodularize.
# - Plug Rails.logger into RestClient.
# - Rather strict one-second open/data timeout. Perhaps to be tweaked.
require 'rest_client'
require 'yajl'
@nz
nz / solr-3.6.0-kuromoji-schema.xml
Created April 20, 2012 11:25
Solr 3.6.0 schema.xml with Kuromoji analysis for text_jp
<?xml version="1.0" encoding="UTF-8"?>
<schema name="sunspot" version="1.0">
<types>
<!-- Scalar field types -->
<fieldType name="boolean" class="solr.BoolField" omitNorms="true"/>
<fieldType name="date" class="solr.DateField" omitNorms="true"/>
<fieldType name="rand" class="solr.RandomSortField" omitNorms="true"/>
<fieldType name="sdouble" class="solr.SortableDoubleField" omitNorms="true"/>
@nz
nz / 1-sunspot-schema-plus-ngram.xml
Created April 9, 2012 15:25
Add NGram analysis to Sunspot
<?xml version="1.0"?>
<schema>
<types>
<fieldType name="text" class="solr.TextField" omitNorms="false">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
@nz
nz / websolr.md
Created April 8, 2012 01:52
Websolr Heroku Devcenter

Websolr is a managed search service provided by Onemorecloud and powered by Apache Solr. The Websolr add-on allows you to use the high performance functionality of Solr in your application today.

Install the Add-on

:::term
$ heroku addons:add websolr

Choosing a Solr Client

The Apache Solr search server presents an API, and there are a number of open source clients to choose from. We recommend Sunspot, although you may already be using another. We provide more general client configuration at the end of this document.

<?xml version="1.0" encoding="UTF-8" ?>
<schema>
<types>
<fieldType name="string" class="solr.StrField" />
</types>
<fields>
<field name="id" type="string" indexed="true" stored="true"/>
</fields>
<uniqueKey>id</uniqueKey>
</schema>
@nz
nz / resize EC2 instance.rb
Created March 19, 2012 21:04
Resize an EC2 instance with EBS root
require 'fog'
current_id = 'i-abcdef'
new_flavor = 'm1.large'
ec2 = Fog::Compute.new(provider: 'AWS')
source = ec2.servers.get(current_id)
dest = ec2.servers.create(
# specify the new instance size
@nz
nz / configuring tire for bonsai.md
Last active October 1, 2015 18:58
Configuring Tire to work with Bonsai

1. Configure Tire to use the Bonsai ElasticSearch Heroku add-on

gem 'tire'

config/initializers/bonsai.rb

ENV['ELASTICSEARCH_URL'] = ENV['BONSAI_URL']
@nz
nz / bonsai.md
Last active July 3, 2018 22:51
Bonsai.io - The ElasticSearch add-on for Heroku

Bonsai offers a Heroku add-on for ElasticSearch.

ElasticSearch is the latest generation search engine built on the powerful Lucene library. Its API is freshly designed around modern RESTful JSON conventions, making it easy to learn and understand. ElasticSearch will automatically index your JSON data with sensible defaults, which means that you can get started without writing a single line of configuration. ElasticSearch is the perfect place to start for anyone new to full-text search engine concepts, or for anyone who is looking for more clarity and less ceremony in their search engine.

The ElasticSearch internals are designed from the ground up with data distribution in mind. This means you get greater scalability, performance and reliability in a cloud hosted environment. An ElasticSearch index can automatically shard your data, to scale to the largest indexes and support high volumes of write traffic. All of our

retry_count = 1
begin
# any code that invokes an update to Solr
record.solr_index!
rescue RSolr::Error::Http
sleep 0.01 # wait 10ms
retry if (retry_count -= 1) >= 0
end
@nz
nz / what I have tried.md
Created February 23, 2012 16:42
Setting a mapping for all types in an index, where types are unknown

Question: is it possible to set a mapping for all types in an index?

I am attempting to apply a default _ttl to all types in an index, without knowing the various types in advance.

The docs show plenty of examples where a mapping is given for a specific type. But there is no indication of how to

What I've tried

Attempt 1: key with _all