activerecord-search 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +23 -19
- data/activerecord-search.gemspec +1 -1
- data/lib/activerecord/search/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ff2752e5628305c3b0fa90597daa07c5d4ae703
|
|
4
|
+
data.tar.gz: 6105dd3dc5fcfd2dfc5133eef9eefc3aed36aba4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df000a180adcdd0645d478d45bdaba4c4857a3ffedcd1b42bd1bde69b2ba0fae6397d5e11b0e2a7a01742dc4045772be6c12d3854eeb4fe001e6310f931fcbdf
|
|
7
|
+
data.tar.gz: b760b7dc43af4a0c31fc078cc0d93349598759516f3a318e9b1c7909e8b09cd01f61015a01b244b3694e181c6763c2da65b0acc28b14d7e8dd01b3a84e88c121
|
data/README.md
CHANGED
|
@@ -27,7 +27,6 @@ Below is an example of the features offered by this plugin:
|
|
|
27
27
|
Use case:
|
|
28
28
|
|
|
29
29
|
A model named Post that contains 2 fields: `title:string` and `content:text`.
|
|
30
|
-
We want to search any posts that include `Ruby` in their content:
|
|
31
30
|
|
|
32
31
|
##### In `app/models/posts.rb`:
|
|
33
32
|
|
|
@@ -43,7 +42,15 @@ end
|
|
|
43
42
|
class PostsController < ApplicationController
|
|
44
43
|
|
|
45
44
|
def index
|
|
46
|
-
Post.search_post("Ruby")
|
|
45
|
+
Post.search_post("Ruby") # It uses the :search_field and :search_option values
|
|
46
|
+
Post.search_post("Ruby", :start_with) # It's possible to override the :search_option value
|
|
47
|
+
Post.search_post("Ruby", :start_with, [:name, :content]) # It's possible to override the :search_option and :search_field values
|
|
48
|
+
|
|
49
|
+
# Some helper method are available
|
|
50
|
+
Post.start_with("Ruby") # all record that start with 'Ruby'
|
|
51
|
+
Post.end_with("Ruby") # all record that end with 'Ruby'
|
|
52
|
+
Post.search_anywhere("Ruby") # all record that search anywhere with 'Ruby'
|
|
53
|
+
|
|
47
54
|
end
|
|
48
55
|
|
|
49
56
|
...
|
|
@@ -52,7 +59,7 @@ end
|
|
|
52
59
|
|
|
53
60
|
## More about the API
|
|
54
61
|
|
|
55
|
-
##### search_option method
|
|
62
|
+
##### search_option method (Call in model)
|
|
56
63
|
|
|
57
64
|
`search_option` method specifies where to search in the sentence. Available options:
|
|
58
65
|
|
|
@@ -60,20 +67,31 @@ end
|
|
|
60
67
|
- `:end_with` : the sentence ends with the pattern.
|
|
61
68
|
- `:anywhere` : search anywhere in the sentence. [DEFAULT OPTION]
|
|
62
69
|
|
|
70
|
+
##### search_field method (Call in model)
|
|
71
|
+
|
|
72
|
+
`search_field` method specifies which field is used for the search. It's possible to search in multiple fields by using the method `search_fields([])`:
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
class Post < ActiveRecord::Base
|
|
76
|
+
search_fields [:title, :content] # search on :title OR :content
|
|
77
|
+
end
|
|
78
|
+
```
|
|
79
|
+
|
|
63
80
|
##### search_MODEL method
|
|
64
81
|
|
|
65
|
-
A method :search_MODEL is auto-generated.
|
|
82
|
+
A method :search_MODEL is auto-generated. some examples:
|
|
66
83
|
|
|
67
84
|
- for a model Post a method `search_post` is generated.
|
|
68
85
|
- for a model Book a method `search_book` is generated.
|
|
69
86
|
|
|
70
|
-
The method can accept
|
|
87
|
+
The method can accept more arguments. Example:
|
|
71
88
|
|
|
72
89
|
```ruby
|
|
73
90
|
class PostsController < ApplicationController
|
|
74
91
|
|
|
75
92
|
def index
|
|
76
93
|
Post.search_post("Ruby", :start_with) # See search_option method section for more information
|
|
94
|
+
Post.search_post("Ruby", :start_with, [:name, :content]) # it's possible to override the search_field option
|
|
77
95
|
end
|
|
78
96
|
|
|
79
97
|
...
|
|
@@ -82,20 +100,6 @@ end
|
|
|
82
100
|
|
|
83
101
|
Append the model name to this method results from the following question: What is the probability that a `search` method already exists in the model?
|
|
84
102
|
|
|
85
|
-
In this example, the search-engine will search any posts that the content starts with `"Ruby"`.
|
|
86
|
-
|
|
87
|
-
##### search_field method
|
|
88
|
-
|
|
89
|
-
`search_field` method specifies which field is used for the search. It's possible to search in multiple fields by using the method `search_fields([])`:
|
|
90
|
-
|
|
91
|
-
```ruby
|
|
92
|
-
class Post < ActiveRecord::Base
|
|
93
|
-
search_fields [:title, :content]
|
|
94
|
-
end
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
In this example, the search-engine will search any posts that include `"Ruby"` in their content OR in their title.
|
|
98
|
-
|
|
99
103
|
## Development
|
|
100
104
|
|
|
101
105
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/activerecord-search.gemspec
CHANGED
|
@@ -7,7 +7,7 @@ require 'activerecord/base'
|
|
|
7
7
|
Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = "activerecord-search"
|
|
9
9
|
spec.version = Activerecord::Search::VERSION
|
|
10
|
-
spec.date =
|
|
10
|
+
spec.date = Time.now.strftime("%F")
|
|
11
11
|
spec.authors = ["Mehdi FARSI"]
|
|
12
12
|
spec.email = ["mehdifarsi.pro@gmail.com"]
|
|
13
13
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-search
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mehdi FARSI
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-10-
|
|
11
|
+
date: 2015-10-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|