Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

really simple search for mongomapper

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 hunt.gemspec
Octocat-spinner-32 specs.watchr
README.rdoc

Hunt

Insanely stupid and basic indexed search for MongoMapper. Probably pointless, but something I am playing around with on side projects.

Usage

Declare the plugin.

class Note
  include MongoMapper::Document
  plugin Hunt

  key :title, String
  key :body, String
  key :tags, Array
  timestamps!

  searches :title, :body, :tags
end

This creates a key named searches that is a Hash. Title, body, and tags get mashed together before save into a unique array of stemmed words and stored in searches.default.

You can index the terms individually or with any other combination of keys.

Note.ensure_index :'searches.default' # or ...
Note.ensure_index [[:user_id, Mongo::Ascending], [:'searches.default', Mongo::Ascending]]

You also get a search class method that returns a scope.

# Returns Plucky::Query (MM Scope), no query actually fired
Note.search('mongodb')

# Gets everything matching mongodb
Note.search('mongodb').all

# Gets first page of everything matching mongodb
Note.search('mongodb').paginate(:page => 1)

# Counts everything matching mongodb
Note.search('mongodb').count

# Matches everything with any of the terms
Note.search('mongodb is awesome')

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 John Nunemaker. See LICENSE for details.

Something went wrong with that request. Please try again.