Skip to content

Instantly share code, notes, and snippets.

Oliver Nightingale olivernn

  • Cape Town
View GitHub Profile
View gist:d391654b68f9ad0b145590a21c0714ed
require 'delegate'
class Series < SimpleDelegator
def self.of(*xs)
def mean
@mean ||= sum / size.to_f
olivernn / lunr.js
Created Jul 6, 2015
View lunr.js
* lunr - - A bit like Solr, but much smaller and not as bright - 0.5.10-issue162
* Copyright (C) 2015 Oliver Nightingale
* MIT Licensed
* @license
olivernn /
Created Jun 8, 2013
Getting started with lunr

Getting Started with Lunr

There are two ways to use lunr to index some documents, The simplest way is to just build the index client side each time the page is loaded. search.js shows an example of this.

If your data is relatively static it might be more efficient to generate the index server side and then load this on each page load, your can see an example of generating the index in node in builder.js.

You can load a serialised index like this:

var idx = lunr.Index.load(JSON.parse(json_string))
olivernn / lunr.contraction_filter.js
Created Jan 19, 2016
Better handling of English contractions in lunr.
View lunr.contraction_filter.js
lunr.contractionTrimmer = function (token) {
return token.replace(/('ve|n't|'d|'ll|'ve|'s|'re)$/, "")
lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'contractionTrimmer')
var englishContractions = function (idx) {
idx.pipeline.after(lunr.trimmer, lunr.contractionTrimmer)
olivernn / set_test.rb
Last active Apr 5, 2017
Ruby Set#include? strangeness
View set_test.rb
require 'minitest/autorun'
require 'set'
class Foo
def initialize(s)
@s = s
def ==(other)
@s == other
View idx.json
olivernn / output
Created Oct 21, 2016
RubyWat Implicit String Concatenation
View output
[[:string_literal, [:string_content, [:@tstring_content, "abc", [1, 1]]]]]]
'a' 'b' 'c'
[:string_literal, [:string_content, [:@tstring_content, "a", [1, 1]]]],
[:string_literal, [:string_content, [:@tstring_content, "b", [1, 5]]]]],
View gist:1129339
<script src="" type="text/javascript" charset="utf-8"></script>
<style type="text/css" media="screen">
body {
background-color: black;
color: white;
font-family: helvetica;
#display {
olivernn /
Created Jan 25, 2016
Lunr full text search on facets for faceted search

So many of your fields look like tags or facets, e.g. sector or market, so you full text search might not be the best way to search on these.

Instead if you had full text search on the tags themselves, e.g. full text search on all the possible values for sector or market, and then, with the resuts of this tag lookup, go and find companies that have this tag. The facted search, lookup by tags (or groups of tags) isn't really lunr's forte, but you could certainly use it for full text search of the tags.

var idx = lunr(function () {
View colors.html
var randInRange = function (min, max) {
var range = max - min
return min + (Math.random() * range)
var HSL = function (h, s, l) {
this.h = h, this.s = s, this.l = l
You can’t perform that action at this time.