pollyanna 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +51 -7
- data/VERSION +1 -1
- data/pollyanna.gemspec +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,12 +1,56 @@
|
|
1
|
-
= Pollyanna - very simple search
|
1
|
+
= Pollyanna - very simple search for your ActiveRecord models
|
2
2
|
|
3
|
-
|
3
|
+
Pollyanna adds a very simple full text search to your ActiveRecord models.
|
4
|
+
Before saving, searchable models copy strings relevant to the search into a text column.
|
5
|
+
Pollyanna finds results for a query using LIKE patterns in SQL.
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
We found Pollyanna very useful for search-as-you-type boxes.
|
8
|
+
|
9
|
+
== Example
|
10
|
+
|
11
|
+
class Movie < ActiveRecord::Base
|
12
|
+
include Pollyanna::Searchable
|
13
|
+
|
14
|
+
def search_text
|
15
|
+
"#{title} #{year} #{director}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class MoviesController
|
21
|
+
|
22
|
+
def index
|
23
|
+
@movies = Movie.search(params[:query])
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
== Making a model searchable
|
29
|
+
|
30
|
+
1. Add a text column "search_text" to a model
|
31
|
+
2. Have the model include <tt>Pollyanna::Searchable</tt>
|
32
|
+
3. Overwrite <tt>search_text</tt> to define which text is indexed upon saving
|
33
|
+
4. <tt>Model.search("query goes here")</tt> now gives you a scope for the results of your query. Blank queries return everything.
|
34
|
+
|
35
|
+
== Searching other columns
|
36
|
+
|
37
|
+
If you want to search a column other than <tt>search_text</tt>, you may say <tt>Movie.search(query, :by => "other_column")</tt>.
|
38
|
+
|
39
|
+
== How queries are matched
|
40
|
+
|
41
|
+
- Pollyanna matches partial words, so "oo" matches "foo".
|
42
|
+
- Multiple words in a query are AND-ed automatically.
|
43
|
+
|
44
|
+
== Installation
|
45
|
+
|
46
|
+
Add the following to your <tt>Initializer.run</tt> block in your <tt>environment.rb</tt>:
|
47
|
+
config.gem 'pollyanna', :source => 'http://gemcutter.org'
|
48
|
+
Then do a
|
49
|
+
sudo rake gems:install
|
50
|
+
|
51
|
+
Alternatively, use
|
52
|
+
sudo gem sources -a http://gemcutter.org
|
53
|
+
sudo gem install pollyanna
|
10
54
|
|
11
55
|
== Credits
|
12
56
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
data/pollyanna.gemspec
CHANGED