<commit_before>Mongoid Fulltext Search [![Build Status](https://secure.travis-ci.org/artsy/mongoid_fulltext.png)](http://travis-ci.org/artsy/mongoid_fulltext)
=======================

Full-text search using n-gram matching for the Mongoid ODM. Tested on MongoDB 1.6 and above, but
probably works on earlier versions as well.

MongoDB currently has no native full-text search capabilities, so this gem is a good fit for cases
where you want something a little less than a full-blown indexing service like Solr. mongoid_fulltext
lets you do a fuzzy string search across relatively short strings, which makes it good for populating
autocomplete boxes based on the display names of your Rails models but not appropriate for, say,
indexing hundreds of thousands of HTML documents.

Install
--------------

Version 0.6.0 or newer of this gem requires Ruby 1.9.3 and Mongoid 3.0. 
Use version 0.5.x for Mongoid 2.4.x and Ruby 1.8.7, 1.9.2 or 1.9.3.

For Ruby 1.8.7 and/or Mongoid 2.x use [mongoid_fulltext 0.5.x](https://github.com/artsy/mongoid_fulltext/tree/0.5-stable).

``` ruby
gem 'mongoid_fulltext'
```

Some examples:
--------------

Suppose you have an `Artist` model and want to index each artist's name:

``` ruby
class Artist
  include Mongoid::Document
  include Mongoid::FullTextSearch

  field :first_name
  field :last_name

  def name
    [first_name, last_name].join(' ')
  end

  fulltext_search_in :name
end
```

The `fulltext_search_in` directive will index the full name of the artist, so now
you can call:<commit_msg>Updated README with Mongoid compat versions.<commit_after>Mongoid Fulltext Search [![Build Status](https://secure.travis-ci.org/artsy/mongoid_fulltext.png)](http://travis-ci.org/artsy/mongoid_fulltext)
=======================

Full-text search using n-gram matching for the Mongoid ODM. Tested on MongoDB 1.6 and above, but
probably works on earlier versions as well.

MongoDB currently has no native full-text search capabilities, so this gem is a good fit for cases
where you want something a little less than a full-blown indexing service like Solr. mongoid_fulltext
lets you do a fuzzy string search across relatively short strings, which makes it good for populating
autocomplete boxes based on the display names of your Rails models but not appropriate for, say,
indexing hundreds of thousands of HTML documents.

Install
--------------

Version 0.6.1 or newer of this gem requires Ruby 1.9.3 and works with Mongoid 3.x.
Use version 0.5.x for Mongoid 2.4.x and Ruby 1.8.7, 1.9.2 or 1.9.3.

For Ruby 1.8.7 and/or Mongoid 2.x use [mongoid_fulltext 0.5.x](https://github.com/artsy/mongoid_fulltext/tree/0.5-stable).

``` ruby
gem 'mongoid_fulltext'
```

Some examples:
--------------

Suppose you have an `Artist` model and want to index each artist's name:

``` ruby
class Artist
  include Mongoid::Document
  include Mongoid::FullTextSearch

  field :first_name
  field :last_name

  def name
    [first_name, last_name].join(' ')
  end

  fulltext_search_in :name
end
```

The `fulltext_search_in` directive will index the full name of the artist, so now
you can call:
{'fraction_non_alphanumeric': 0.10975217251367879, 'fraction_numerical': 0.019633086578693275, 'mean_word_length': 3.9177215189873418, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '2904138', 'n_tokens_mistral': 1003, 'n_tokens_neox': 936, 'n_words': 382}