Skip to content

Instantly share code, notes, and snippets.

@mitchellhenke
Created May 14, 2015 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchellhenke/f2331a1c35c6869b0629 to your computer and use it in GitHub Desktop.
Save mitchellhenke/f2331a1c35c6869b0629 to your computer and use it in GitHub Desktop.
defmodule User do
use Ecto.Model
schema "users" do
field :username, :string
end
def search(query, search_term, limit = 0.3) do
from(u in query,
where: fragment("similarity(?, ?) > ?", u.username, ^search_term, ^limit),
order_by: fragment("similarity(?, ?) DESC", u.username, ^search_term))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment