Gem Version Build Status Maintainability Test Coverage Join the chat at https://gitter.im/querylicious/Lobby

Querylicious is an opinionated and repository agnostic search query parser and reducer.


Add this line to your application's Gemfile:

gem 'querylicious'

And then execute:


Or install it yourself with:

gem install querylicious


Querylicious parses GitHub-style search queries, and let's you specify an reducer to generate the result. The reducer is a callable object such as an proc. Here is an simple example where the repository is an array of strings:

repository = %w[Garnet Amethyst Pearl Steven]

reducer = lambda do |array, m|
  m.phrase do |phrase|
    array.select { |item| item.upcase.include?(phrase.upcase) }

  m.not_phrase do |phrase|
    array.reject { |item| item.upcase.include?(phrase.upcase) }

  m.default { arr }

query_reducer = Querylicious::QueryReducer.new(reducer)

query_reducer.call(repository, 'am')         #=> ["Amethyst"]
query_reducer.call(repository, 'NOT Steven') #=> ["Garnet", "Amethyst", "Pearl"]

phrase is the basic search type intended for free text search or similar. But querylicious also supports defining property search with many possible modifiers.

# The query "stars:n" searches for when `stars` is the value n
m.key 'stars' do |array, stars|
  # ...

# You can use `dry-types` type-definitions if you wish to handle different
# types differently. The parser can return the following types:
# `[String, Integer, Date, DateTime, Range]`

# The query "stars:1" searches for when `stars` is an integer `1`
m.key 'stars', type: Querylicious::Types::Integer do |array, stars|
  # ...

# The query "stars:1..10" searches for when `stars` is a range `1..10`
m.key 'stars', type: Querylicious::Types::Range do |array, stars|
  # ...

# Properties also support operators different from the default equals;
# possilble operators are: `%i[eql not_eql gt gteq lt lteq]`

# The query "stars:>1" searches for when `stars` is greater than `1`
m.key 'stars', op: :gt do |array, stars|
  # ...

You can use any type of backing repository, as long as it's reducable. Here is an example using Sequel:

class Article < Sequel::Model; end

reducer = lambda do |dataset, m|
  m.phrase do |phrase|
    dataset.grep(%i[name body], "%#{phrase}%", case_insensitive: true)

  m.key :published do |published|
    dataset.where(published: published)

  m.default { dataset }

query_reducer = Querylicious::QueryReducer.new(reducer)

articles = query_reducer.call(Article, 'foo published:true').all

You can curry the call to the query reducer to avoid passing the repository each time:

article_search = query_reducer.curry.call(Article)

articles = article_search.call('foo published:true').all


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in the VERSION file, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.


Bug reports and pull requests are welcome on GitHub at huyderman/querylicious. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.


The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Querylicious project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.


Thanks to the talented Alex Daily (@[email protected] or @[email protected]) for creating the awesome logo!