Skip to content

Instantly share code, notes, and snippets.

# Full Term Searching
index = SearchIndex.new
index.add(0, "some more examples")
index.search("exam")
=> returns nothing
index.search("examples")
=> returns Document 0
# Normalized Terms
index = SearchIndex.new
index.add(0, "this is a capitalized EXAMPLE")
index.add(1, "here is a lower case example")
index.add(2, "and one More example")
index.search("example")
=> returns Document 0, 1 and 2
# Scoring of Documents for a Query
index = SearchIndex.new
index.add(0, "some more examples")
index.add(1, "Examples are great for examples of examples")
index.search("examples")
=> returns Document 1 with score 1.0, Document 0 with score 0.5
# Highlighting
index = SearchIndex.new
index.add(0, "I like movies based on cats")
index.add(1, "I like comics based on dogs")
index.add(2, "I like books based on fish")
index.search("cats")
=> returns Documents 0 with highlight ‘... based on *cats*’
# Typo Handling
index = SearchIndex.new
index.add(0, "some more examples")
index.search("xamples")
=> returns Document 0
# Multiple Fields per Document
index = SearchIndex.new
index.add(0, {name: "Example name", price: 5.00})
index.search("example")
=> returns Document 0: {name: "Example name", price: 5.00}
# Value Based Filtering
index = SearchIndex.new
index.add(0, {name: "Example name", price: 5.00})
index.search("example", filter: {price: 1.00})
=> returns nothing
index.search("example", filter: {price: 5.00})
=> returns Document 0
@tehsven
tehsven / fix_dup_key_error.patch
Last active November 21, 2019 20:50
Fix dup key error when creating second playlist
From 1cf5b84243e36b207f04ca939cce8b5a42f1a426 Mon Sep 17 00:00:00 2001
From: tehsven <tehsven@gmail.com>
Date: Thu, 21 Nov 2019 12:45:01 -0800
Subject: [PATCH] Fix dup key error when creating second playlist
The passport-local-mongoose plugin creates uniqueness constraints
on a 'username' field for whatever model it's plugged in to.
It was being plugged in to all the models like Artist, Playlist,
and Song instead of just the User model.