<commit_before># QuickSearch

A quick search concern for ActiveRecord and Mongoid models.

## Installation

Add this line to your application's Gemfile:

    gem 'quick-search'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install quick-search

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it ( http://github.com/elementar/quick-search/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request<commit_msg>Updated documentation<commit_after># QuickSearch

A quick search concern for ActiveRecord and Mongoid models.

## Installation

Add this line to your application's Gemfile:

    gem 'quick-search'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install quick-search

## Usage

`quick-search` ships with an `ActiveRecord` and a `Mongoid` adapter. Feel free to submit
a pull request for your favorite adapter.

To start using it, just add `include QuickSearch` somewhere on the model class you need.
The class will be augmented with a `quick_search` method, which can be called directly on your
model class (i.e., `User.quick_search('<NAME>')`) or chained with your scopes or another conditions
(i.e., `User.where(active: true).quick_search('<NAME>')`.

### Restricting the fields available for quick searching

By default, `quick-search` will try to match the tokens you specify on all string fields on the model.
If that's undesirable, you can restrict the fields:

    class MyModel
      include QuickSearch

      quick_search_fields :name, :address
    end

### Searching on relations (ActiveRecord only)

When using `quick-search` on ActiveRecord models, you can specify associations in which to search. They will
be automatically joined.

    class User < ActiveRecord::Base
      include QuickSearch

      has_many :pets

      quick_search_fields :name, :address, pets: [:name, parents: [:name]]
    end

### Searching on subdocuments (Mongoid only)

Using the same technique used for querying ActiveRecord relations, you can search inside Mongoid subdocuments:


    class User
      include Mongoid::Document
      include QuickSearch

      embeds_many :pets

      quick_search_fields :name, :address, pets: [:name, parents: [:name]]
    end

The Mongoid adapter will not perform queries on `has_many` or `belongs_to` relations. PR are welcome.

## How it works

A simple query like this:

    User.quick_search '<NAME>'

Generates, in ActiveRecord, the equivalent of this:

    User.where('name like :n or email like :n', n: '%john%')
        .where('name like :n or email like :n', n: '%wayne%')

And for Mongoid, the equivalent of this:

    User.where('$or' => [{name: /john/}, {email: /john/}])
        .where('$or' => [{name: /wayne/}, {email: /wayne/}])

## Contributing

1. Fork it ( http://github.com/elementar/quick-search/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
{'fraction_non_alphanumeric': 0.09772088666874805, 'fraction_numerical': 0.0031220730565095223, 'mean_word_length': 3.774962742175857, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2157499', 'n_tokens_mistral': 951, 'n_tokens_neox': 908, 'n_words': 398}