Project

pursuit

0.0
The project is in a healthy, maintained state
Advanced key-based searching for ActiveRecord objects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Dependencies

Development

~> 2.0
~> 13.0
~> 3.8
~> 0.77.0
~> 1.4
~> 0.9.20

Runtime

>= 5.2.0, < 6.2.0
>= 5.2.0, < 6.2.0
 Project Readme

Pursuit

Advanced key-based searching for ActiveRecord objects.

Installation

You can install Pursuit using the following command:

$ gem install pursuit

Or, by adding the following to your Gemfile:

gem 'pursuit'

Usage

You can use the convenient DSL syntax to declare which attributes and relationships are searchable:

class Product < ActiveRecord::Base
  searchable do |o|
    o.relation :variations, :title, :stock_status

    # Attributes can be used for both keyed and unkeyed searching by default, but you can pass either `keyed: false` or
    # `unkeyed: false` to restrict when the attribute is searched.
    o.attribute :title
    o.attribute :description
    o.attribute :rating, unkeyed: false

    # You can shorten the search keyword by passing the desired search term first, and then the real attribute name
    # as the second argument.
    #  => "category*=shirts"
    o.attribute :category, :category_id

    # It's also possible to query entirely custom Arel nodes by passing a block which returns the Arel node to query.
    # You could use this to query a person's full name by concatenating their first and last name columns, for example.
    o.attribute :title_length, unkeyed: false do
      Arel::Nodes::NamedFunction.new('LENGTH', [
        arel_table[:title]
      ])
    end
  end
end

This creates a .search method on your record class which accepts a single query argument:

Product.search('plain shirt rating>=3')

Development

After checking out the repo, run bundle exec rake spec to run the tests.

To install this gem onto your machine, run bundle exec rake install.