pose 1.2.4 → 1.2.5
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.
- data/README.md +13 -14
- data/lib/generators/pose/install/install_generator.rb +56 -0
- data/lib/generators/{templates/add_migration.rb → pose/install/templates/install_migration.rb} +0 -0
- data/lib/generators/pose/remove/remove_generator.rb +56 -0
- data/lib/generators/{templates → pose/remove/templates}/remove_migration.rb +0 -0
- data/lib/pose/version.rb +1 -1
- metadata +5 -9
- data/lib/generators/pose_generator.rb +0 -19
- data/lib/generators/remove_pose_generator.rb +0 -19
- data/lib/rails/generators/pose/pose_generator.rb +0 -21
- data/lib/rails/generators/pose/remove_pose_generator.rb +0 -21
- data/lib/rails/generators/templates/add_migration.rb +0 -24
- data/lib/rails/generators/templates/remove_migration.rb +0 -25
data/README.md
CHANGED
@@ -11,9 +11,9 @@ Pose ("Polymorphic Search") allows fulltext search for ActiveRecord objects in
|
|
11
11
|
* The search is very fast, doing only simple queries over fully indexed columns.
|
12
12
|
|
13
13
|
|
14
|
-
|
14
|
+
## Installation
|
15
15
|
|
16
|
-
|
16
|
+
### Set up the gem.
|
17
17
|
|
18
18
|
Add the gem to your Gemfile and run `bundle install`
|
19
19
|
|
@@ -21,7 +21,7 @@ Add the gem to your Gemfile and run `bundle install`
|
|
21
21
|
gem 'pose'
|
22
22
|
```
|
23
23
|
|
24
|
-
|
24
|
+
### Create the database tables for pose.
|
25
25
|
|
26
26
|
```bash
|
27
27
|
$ rails generate pose:install
|
@@ -34,7 +34,7 @@ Pose creates two tables in your database. These tables are automatically populat
|
|
34
34
|
* _pose_assignments_: lists which word occurs in which document.
|
35
35
|
|
36
36
|
|
37
|
-
|
37
|
+
### Make your ActiveRecord models searchable
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
class MyClass < ActiveRecord::Base
|
@@ -60,7 +60,7 @@ not only data from this object, but also data from related objects, class names,
|
|
60
60
|
Now that this class is posified, any `create`, `update`, or `delete` operation on any instance of this class will update the search index automatically.
|
61
61
|
|
62
62
|
|
63
|
-
|
63
|
+
### Index existing records in your database
|
64
64
|
|
65
65
|
Data that existed in your database before adding Pose isn't automatically included in the search index.
|
66
66
|
You have to index those records manually once. Future updates will happen automatically.
|
@@ -70,7 +70,7 @@ To index all entries of `MyClass`, run `rake pose:reindex_all[MyClass]` on the c
|
|
70
70
|
At this point, you are all set up. Let's perform a search!
|
71
71
|
|
72
72
|
|
73
|
-
|
73
|
+
## Searching
|
74
74
|
|
75
75
|
To search, simply call Pose's `search` method, and tell it the search query as well as in which classes it should search.
|
76
76
|
|
@@ -135,13 +135,13 @@ result = Pose.search 'foo', MyClass, where: [ public: true, ['user_id <> ?', @cu
|
|
135
135
|
```
|
136
136
|
|
137
137
|
|
138
|
-
|
138
|
+
## Maintenance
|
139
139
|
|
140
140
|
Besides an accasional search index cleanup, Pose is relatively maintenance free.
|
141
141
|
The search index is automatically updated when objects are created, updated, or deleted.
|
142
142
|
|
143
143
|
|
144
|
-
|
144
|
+
### Optimizing the search index
|
145
145
|
|
146
146
|
For performance reasons, the search index keeps all the words that were ever used around, in order to try to reuse them as much as possible.
|
147
147
|
After deleting or changing a large number of objects, you can shrink the memory consumption of Pose's search index by
|
@@ -152,7 +152,7 @@ $ rake pose:index:vacuum
|
|
152
152
|
```
|
153
153
|
|
154
154
|
|
155
|
-
|
155
|
+
### Recreating the search index from scratch
|
156
156
|
To index existing data in your database, or after loading additional data outside of ActiveRecord into your database,
|
157
157
|
you should recreate the search index from scratch.
|
158
158
|
|
@@ -172,7 +172,7 @@ rails generate pose:remove
|
|
172
172
|
Also don't forget to remove the `posify` block from your models as well as the gem entry from your Gemfile.
|
173
173
|
|
174
174
|
|
175
|
-
|
175
|
+
## Use Pose in your tests
|
176
176
|
|
177
177
|
By default, Pose doesn't run in Rails' `test` environment. This is to not slow down tests due to constant updating of the search index when objects are created.
|
178
178
|
If you want to test your models search functionality, you need to enable searching in tests:
|
@@ -184,14 +184,13 @@ Pose::CONFIGURATION[:search_in_tests] = true
|
|
184
184
|
Please don't forget to set this value to `false` when you are done, or your remaining tests will be slow. A good place to enable/disable this flag is in before/after blocks of your test cases.
|
185
185
|
|
186
186
|
|
187
|
-
|
187
|
+
## Development
|
188
188
|
|
189
189
|
If you find a bug, have a question, or a better idea, please open an issue on the
|
190
190
|
<a href="https://github.com/kevgo/pose/issues">Pose issue tracker</a>.
|
191
191
|
Or, clone the repository, make your changes, and submit a pull request.
|
192
192
|
|
193
|
-
|
194
|
-
## Run the unit tests for the Pose Gem
|
193
|
+
### Run the unit tests for the Pose Gem
|
195
194
|
|
196
195
|
Pose uses Postgresql for tests, since it is the most strict database.
|
197
196
|
To run tests, first, create a test database.
|
@@ -207,7 +206,7 @@ $ rake spec
|
|
207
206
|
```
|
208
207
|
|
209
208
|
|
210
|
-
|
209
|
+
### Road Map
|
211
210
|
|
212
211
|
* add `join` to search parameters
|
213
212
|
* pagination of search results
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module Pose
|
5
|
+
module Generators
|
6
|
+
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
10
|
+
|
11
|
+
def create_migration_file
|
12
|
+
say ''
|
13
|
+
say ' Creating database migration for the Pose tables.'
|
14
|
+
say ''
|
15
|
+
migration_template 'install_migration.rb', 'db/migrate/install_pose.rb'
|
16
|
+
say ''
|
17
|
+
end
|
18
|
+
|
19
|
+
def installation_instructions
|
20
|
+
say ''
|
21
|
+
say ' All done! You need to do two things now:'
|
22
|
+
say ''
|
23
|
+
say ' 1. Run the database migration'
|
24
|
+
say ''
|
25
|
+
say ' rake db:migrate', Thor::Shell::Color::BOLD
|
26
|
+
say ''
|
27
|
+
say ''
|
28
|
+
say ' 2. Add a posify block to all your models.'
|
29
|
+
say ' Here is an example:'
|
30
|
+
say ''
|
31
|
+
say ' class MyClass < ActiveRecord::Base'
|
32
|
+
say ' ...'
|
33
|
+
say ''
|
34
|
+
say ' posify do', Thor::Shell::Color::BOLD
|
35
|
+
say ' # return searchable text as a string here', Thor::Shell::Color::BOLD
|
36
|
+
say ' end', Thor::Shell::Color::BOLD
|
37
|
+
say ''
|
38
|
+
say ' ...'
|
39
|
+
say ' end'
|
40
|
+
say ''
|
41
|
+
say ''
|
42
|
+
say ' Happy searching! :)'
|
43
|
+
say ''
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# Helper method for creating the migration.
|
50
|
+
def self.next_migration_number(path)
|
51
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/lib/generators/{templates/add_migration.rb → pose/install/templates/install_migration.rb}
RENAMED
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module Pose
|
5
|
+
module Generators
|
6
|
+
|
7
|
+
class RemoveGenerator < Rails::Generators::Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
10
|
+
|
11
|
+
def create_migration_file
|
12
|
+
say ''
|
13
|
+
say ' Creating database migration to remove the Pose tables.'
|
14
|
+
say ''
|
15
|
+
migration_template 'remove_migration.rb', 'db/migrate/remove_pose.rb'
|
16
|
+
say ''
|
17
|
+
end
|
18
|
+
|
19
|
+
def installation_instructions
|
20
|
+
say ''
|
21
|
+
say ' All done! You need to do two things now:'
|
22
|
+
say ''
|
23
|
+
say ' 1. Run the database migration to remove the tables from your database.'
|
24
|
+
say ''
|
25
|
+
say ' rake db:migrate', Thor::Shell::Color::BOLD
|
26
|
+
say ''
|
27
|
+
say ''
|
28
|
+
say ' 2. Remove the posify block from all your models.'
|
29
|
+
say ' Here is how it looks like:'
|
30
|
+
say ''
|
31
|
+
say ' class MyClass < ActiveRecord::Base'
|
32
|
+
say ' ...'
|
33
|
+
say ''
|
34
|
+
say ' posify do', Thor::Shell::Color::BOLD
|
35
|
+
say ' ...', Thor::Shell::Color::BOLD
|
36
|
+
say ' end', Thor::Shell::Color::BOLD
|
37
|
+
say ''
|
38
|
+
say ' ...'
|
39
|
+
say ' end'
|
40
|
+
say ''
|
41
|
+
say ''
|
42
|
+
say ' Have an excellent day! :)'
|
43
|
+
say ''
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# Helper method for creating the migration.
|
50
|
+
def self.next_migration_number(path)
|
51
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
File without changes
|
data/lib/pose/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -197,10 +197,10 @@ files:
|
|
197
197
|
- doc/PoseMigrations.html
|
198
198
|
- doc/PoseWord.html
|
199
199
|
- doc/top-level-namespace.html
|
200
|
-
- lib/generators/
|
201
|
-
- lib/generators/
|
202
|
-
- lib/generators/
|
203
|
-
- lib/generators/templates/remove_migration.rb
|
200
|
+
- lib/generators/pose/install/install_generator.rb
|
201
|
+
- lib/generators/pose/install/templates/install_migration.rb
|
202
|
+
- lib/generators/pose/remove/remove_generator.rb
|
203
|
+
- lib/generators/pose/remove/templates/remove_migration.rb
|
204
204
|
- lib/pose/activerecord_base_additions.rb
|
205
205
|
- lib/pose/internal_helpers.rb
|
206
206
|
- lib/pose/model_additions.rb
|
@@ -210,10 +210,6 @@ files:
|
|
210
210
|
- lib/pose/static_api.rb
|
211
211
|
- lib/pose/version.rb
|
212
212
|
- lib/pose.rb
|
213
|
-
- lib/rails/generators/pose/pose_generator.rb
|
214
|
-
- lib/rails/generators/pose/remove_pose_generator.rb
|
215
|
-
- lib/rails/generators/templates/add_migration.rb
|
216
|
-
- lib/rails/generators/templates/remove_migration.rb
|
217
213
|
- lib/tasks/pose_tasks.rake
|
218
214
|
- MIT-LICENSE
|
219
215
|
- Rakefile
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/migration'
|
3
|
-
|
4
|
-
module Pose
|
5
|
-
|
6
|
-
class InstallGenerator < Rails::Generators::Base
|
7
|
-
include Rails::Generators::Migration
|
8
|
-
source_root File.expand_path('../templates', __FILE__)
|
9
|
-
|
10
|
-
def create_migration_file
|
11
|
-
migration_template 'add_migration.rb', 'db/migrate/add_pose.rb'
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.next_migration_number(path)
|
15
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/migration'
|
3
|
-
|
4
|
-
module Pose
|
5
|
-
|
6
|
-
class RemoveGenerator < Rails::Generators::Base
|
7
|
-
include Rails::Generators::Migration
|
8
|
-
source_root File.expand_path('../templates', __FILE__)
|
9
|
-
|
10
|
-
def create_migration_file
|
11
|
-
migration_template 'remove_migration.rb', 'db/migrate/remove_pose.rb'
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.next_migration_number(path)
|
15
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/migration'
|
3
|
-
|
4
|
-
module Pose
|
5
|
-
module Generators
|
6
|
-
|
7
|
-
class InstallGenerator < Rails::Generators::Base
|
8
|
-
include Rails::Generators::Migration
|
9
|
-
source_root File.expand_path('../templates', __FILE__)
|
10
|
-
|
11
|
-
def create_migration_file
|
12
|
-
migration_template 'add_migration.rb', 'db/migrate/add_pose.rb'
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.next_migration_number(path)
|
16
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/migration'
|
3
|
-
|
4
|
-
module Pose
|
5
|
-
module Generators
|
6
|
-
|
7
|
-
class RemoveGenerator < Rails::Generators::Base
|
8
|
-
include Rails::Generators::Migration
|
9
|
-
source_root File.expand_path('../templates', __FILE__)
|
10
|
-
|
11
|
-
def create_migration_file
|
12
|
-
migration_template 'remove_migration.rb', 'db/migrate/remove_pose.rb'
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.next_migration_number(path)
|
16
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class AddPoseTables < ActiveRecord::Migration
|
2
|
-
|
3
|
-
def self.up
|
4
|
-
create_table "pose_assignments" do |t|
|
5
|
-
t.integer "pose_word_id", null: false
|
6
|
-
t.integer "posable_id", null: false
|
7
|
-
t.string "posable_type", limit: 40, null: false
|
8
|
-
end
|
9
|
-
|
10
|
-
add_index "pose_assignments", :pose_word_id
|
11
|
-
add_index "pose_assignments", :posable_id
|
12
|
-
|
13
|
-
create_table "pose_words" do |t|
|
14
|
-
t.string "text", limit: 80, null: false
|
15
|
-
end
|
16
|
-
|
17
|
-
add_index "pose_words", :text
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.down
|
21
|
-
drop_table 'pose_assignments'
|
22
|
-
drop_table 'pose_words'
|
23
|
-
end
|
24
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class AddPoseTables < ActiveRecord::Migration
|
2
|
-
|
3
|
-
def self.up
|
4
|
-
drop_table 'pose_assignments'
|
5
|
-
drop_table 'pose_words'
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.down
|
9
|
-
create_table "pose_assignments" do |t|
|
10
|
-
t.integer "pose_word_id", null: false
|
11
|
-
t.integer "posable_id", null: false
|
12
|
-
t.string "posable_type", limit: 40, null: false
|
13
|
-
end
|
14
|
-
|
15
|
-
add_index "pose_assignments", :pose_word_id
|
16
|
-
add_index "pose_assignments", :posable_id
|
17
|
-
|
18
|
-
create_table "pose_words" do |t|
|
19
|
-
t.string "text", limit: 80, null: false
|
20
|
-
end
|
21
|
-
|
22
|
-
add_index "pose_words", :text
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|