Giter Club home page Giter Club logo

liquor's Introduction

Liquor

A clumsy filtering library, loosely based on lucene.

This library is still a work in progress and may be buggy as a old house infested with termites.

Usage

First you must define a search spec, luckily it's just a plain old map

my_search_spec = %{
  # Whitelists can be a map containing the name of each 'allowed' field.
  whitelist: %{
    "_" => true, # "_" is a special key for strings with no key
    "derp" => nil, # this field will be rejected
    "body" => true, # this field will be allowed,
    "kind" => :message_kind, # the field will be renamed to `message_kind` and accepted
    "date" => :date,
  },
  # transforms tell liquor how to convert the whitelisted fields
  transform: %{
    _: {:type, :string}, # a special handler for keywords
    body: {:type, :string}, # uses Ecto.Type.cast(:string)
    message_kind: {:mod, MessageKindEnum}, # works with Ecto.Type modules
    date: {:type, :date}, # dates, datetimes and time have special transforms
  },
  # filter tells liquor how to handle the transformed values when adding it to the query
  filter: %{
    _: {:apply, MyFilter, :filter_keyword, []}, # an apply can be used, here it's being used for the keywords
    body: {:type, :string}, # treats the value as a string, this gives access to wildcards
    message_kind: {:type, :atom}, #
    date: {:type, :date}, # date, datetime and time are subject to special handling
  },
}

messages =
  Message
  |> Liquor.apply_search("date:year:2018 body:'Hello '*", my_search_spec)
  |> Repo.all()

TODO

Introduce a DSL, or at least some helper functions for building the search_spec

liquor's People

Contributors

icedragon200 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.