Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/radar/searcher
Fun experiment in parsing search query strings (like Pivotal Tracker does)
https://github.com/radar/searcher
Last synced: 14 days ago
JSON representation
Fun experiment in parsing search query strings (like Pivotal Tracker does)
- Host: GitHub
- URL: https://github.com/radar/searcher
- Owner: radar
- License: mit
- Created: 2010-10-03T03:13:25.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2023-03-31T14:09:12.000Z (over 1 year ago)
- Last Synced: 2024-10-09T23:08:22.453Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 36.1 KB
- Stars: 25
- Watchers: 3
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
README
# Searcher
Searcher is a pure SQL implementation which lets you find by pre-defined labels, as well as wildcard matching queries. It should be used as a lo-fi precursor to a proper full-text search platform, such as the built-in one to PostgreSQL.
The idea of this gem came from Joost Schuur.
This gem is used in Chapter 10 of Rails 3 in Action and was crafted specifically for it. YMMV.
## Installation
This gem is only compatible with versions of Active Record that are greater than or equal to 3.0. You *are* using Active Record 3, right?
Add this gem to your _Gemfile_ (You *are* using Bundler, right?):
gem 'searcher'
## UsageTo define labels for your field, use the `searcher` method inside your model like this:
class Ticket < ActiveRecord::Base
has_and_belongs_to_many :tags
searcher do
label :tag, :from => :tags, :field => "name"
label :state, :from => :state, :field => "name"
end
end
To query for these labels, use the `search` class method on your model:Ticket.search("tag:v3.0.0 state:open")
Boom! There's all your tickets that have the tag v3.0.0 and are marked (state-wise) as being open.
## CaveatsCurrently Searcher works only with `has_and_belongs_to_many` and `belongs_to` associations, as that is all that is needed in the book.