repertoire-faceting 0.5.5 → 0.6.0

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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/FAQ +23 -17
  3. data/INSTALL +52 -84
  4. data/LICENSE +1 -1
  5. data/README +213 -34
  6. data/TODO +20 -7
  7. data/ext/Makefile +24 -14
  8. data/ext/README.faceting +51 -0
  9. data/ext/bytea/bytea.sql +173 -0
  10. data/ext/bytea/faceting_bytea.control +6 -0
  11. data/ext/common/util.sql +35 -0
  12. data/ext/faceting--0.6.0.sql +251 -0
  13. data/ext/faceting_bytea--0.6.0.sql +207 -0
  14. data/ext/faceting_varbit--0.6.0.sql +198 -0
  15. data/ext/signature/faceting.control +6 -0
  16. data/ext/signature/signature.c +740 -0
  17. data/ext/{signature.o → signature/signature.o} +0 -0
  18. data/ext/{signature.so → signature/signature.so} +0 -0
  19. data/ext/signature/signature.sql +217 -0
  20. data/ext/varbit/faceting_varbit.control +7 -0
  21. data/ext/varbit/varbit.sql +164 -0
  22. data/{public → lib/assets}/images/repertoire-faceting/proportional_symbol.png +0 -0
  23. data/{public → lib/assets}/images/repertoire-faceting/spinner_sm.gif +0 -0
  24. data/{public → lib/assets}/javascripts/rep.faceting/context.js +2 -2
  25. data/{public → lib/assets}/javascripts/rep.faceting/ext/earth_facet.js +2 -4
  26. data/{public → lib/assets}/javascripts/rep.faceting/facet.js +1 -1
  27. data/{public → lib/assets}/javascripts/rep.faceting/facet_widget.js +3 -8
  28. data/{public → lib/assets}/javascripts/rep.faceting/nested_facet.js +1 -1
  29. data/{public → lib/assets}/javascripts/rep.faceting/results.js +1 -1
  30. data/{public → lib/assets}/javascripts/rep.faceting.js +5 -1
  31. data/{public → lib/assets}/javascripts/rep.protovis-facets.js +3 -3
  32. data/lib/assets/javascripts/rep.widgets/events.js +51 -0
  33. data/lib/assets/javascripts/rep.widgets/global.js +50 -0
  34. data/lib/assets/javascripts/rep.widgets/model.js +159 -0
  35. data/lib/assets/javascripts/rep.widgets/widget.js +213 -0
  36. data/lib/assets/javascripts/rep.widgets.js +14 -0
  37. data/{public → lib/assets}/stylesheets/rep.faceting.css +1 -1
  38. data/lib/repertoire-faceting/adapters/postgresql_adapter.rb +107 -48
  39. data/lib/repertoire-faceting/facets/abstract_facet.rb +43 -27
  40. data/lib/repertoire-faceting/facets/basic_facet.rb +23 -22
  41. data/lib/repertoire-faceting/facets/nested_facet.rb +50 -27
  42. data/lib/repertoire-faceting/model.rb +101 -65
  43. data/lib/repertoire-faceting/rails/engine.rb +8 -0
  44. data/lib/repertoire-faceting/rails/postgresql_adapter.rb +0 -1
  45. data/lib/repertoire-faceting/rails/relation.rb +0 -1
  46. data/lib/repertoire-faceting/railtie.rb +0 -1
  47. data/lib/repertoire-faceting/relation/calculations.rb +7 -2
  48. data/lib/repertoire-faceting/relation/query_methods.rb +17 -4
  49. data/lib/repertoire-faceting/routing.rb +2 -5
  50. data/lib/repertoire-faceting/tasks/all.rake +5 -4
  51. data/lib/repertoire-faceting/tasks/client.rake +2 -5
  52. data/lib/repertoire-faceting/version.rb +1 -1
  53. data/lib/repertoire-faceting.rb +2 -4
  54. data/{public → vendor/assets}/javascripts/google-earth-extensions.js +0 -0
  55. data/{public → vendor/assets}/javascripts/protovis.js +0 -0
  56. metadata +78 -78
  57. data/ext/README.signature +0 -33
  58. data/ext/signature.c +0 -740
  59. data/ext/signature.sql +0 -342
  60. data/ext/signature.sql.IN +0 -342
  61. data/ext/uninstall_signature.sql +0 -4
  62. data/ext/uninstall_signature.sql.IN +0 -4
  63. data/lib/repertoire-faceting/adapters/abstract_adapter.rb +0 -18
  64. data/lib/repertoire-faceting/relation/spawn_methods.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b37dce6950784df35020d3362c8824672bf3d53
4
- data.tar.gz: 2f2cf88eeb90f133e2f4c92029939824e8d9d761
3
+ metadata.gz: 9e727bb33feffd5e77e77263ecc16f74666ab1d5
4
+ data.tar.gz: 087228d40ae3e1faa88de3d285ba4350d81f1411
5
5
  SHA512:
6
- metadata.gz: 2cfb4a8f2e0bea97e2e4318f3a8ba348cb9ce4cb761442351372682cf1eea8e4d0d6365aa88166187192e71a0e9233e041de514426a3a6de55203d431e4224c2
7
- data.tar.gz: dcb0eaf02b7e5604e2b489ee6c551c7da1a783764178825c84d75f9de33d158853700953731b2c9a69a86246087179b56fcb1795ff00a31197d7a5e58eb444f1
6
+ metadata.gz: e8df6396c41f96dba9822c2f694e79f42e108651c53b9fa49f5bb1032769f7edc8006ee0d5c53f93c1fc5a6612ed3ece7b3380372554ed0f5e61567ac7f47944
7
+ data.tar.gz: f3a3b38089d75cc360aa2f99119eeb4955a9c69eeba5e4fc94878523dbed0dc853852df17fa51a2ef6e7f0301aad875a6b2bdf1ac0365e92c31372efe52c978e
data/FAQ CHANGED
@@ -2,12 +2,23 @@
2
2
 
3
3
  == General questions
4
4
 
5
- *Q* Can I use Rails 3 migrations with Repertoire Faceting?
5
+ *Q* Can I use Rails migrations with Repertoire Faceting?
6
6
 
7
7
  *A* In general, yes. However, Rails' developers recommend you use the database's native dump format rather than schema.rb. Put the following line in environment.rb:
8
8
 
9
9
  config.active_record.schema_format = :sql
10
10
 
11
+ You can also use migrations to install the API in your database. A simple example:
12
+
13
+ def self.change
14
+ reversible do |dir
15
+ dir.up { execute('CREATE EXTENSION faceting') }
16
+ dir.down { execute('DROP EXTENSION faceting CASCADE') }
17
+ end
18
+ end
19
+
20
+ In cases where you do not have superuser access to the deployment host (e.g. Heroku) and so cannot run "rake db:faceting:extensions:install", you can get use the connection's "faceting_api_sql" method to load the API by hand. See the repertoire-faceting-example application's migrations for a concrete example.
21
+
11
22
 
12
23
  == About facet indexing and the signature SQL type
13
24
 
@@ -18,7 +29,7 @@
18
29
 
19
30
  *Q* My facets are empty.
20
31
 
21
- *A* Make sure the facet indices aren't empty. Running '<model>.update_indexed_facets([])' from the console will drop them all.
32
+ *A* Make sure the facet indices aren't empty. Running '<Model>.index_facets([])' from the Rails console will drop them all.
22
33
 
23
34
 
24
35
  *Q* Can I facet over multiple models?
@@ -28,31 +39,26 @@
28
39
 
29
40
  *Q* Why a new native PostgreSQL type?
30
41
 
31
- *A* As of PostgreSQL 8.4, there is no support for population counts in either blobs or bitstrings. Neither of these built-in types provides both the bitset and I/O functions required for faceting.
42
+ *A* As of PostgreSQL 9.3, we have a binding for the Repertoire in-database faceting functions, based on VARBIT strings. However, it is many times slower than using the C-language signature type.
32
43
 
33
44
 
34
45
  == About the ajax faceting widgets
35
46
 
36
47
 
37
- *Q* Rails 3 is sending JSON data in a format that my javascript widgets don't understand.
48
+ *Q* Rails is sending JSON data in a format that my javascript widgets don't understand.
38
49
 
39
50
  *A* Put the following line in config/application.rb:
40
51
 
41
52
  config.active_record.include_root_in_json = false
42
53
 
43
54
 
44
- *Q* A web page from the default Rails app refuses to load the faceting widgets.
45
-
46
- *A* Repertoire Faceting widgets are based on JQuery, which is incompatible with Prototype. You should remove prototype.js and rails.js from the javascripts directory, and delete the <%= javascript_include_tag :defaults %> line from application.html.erb.
47
-
48
-
49
55
  *Q* How do I send page-specific data (for example, a search field) to the webservice with the facet widgets' data?
50
56
 
51
57
  *A* If you provide a function to the facet_context plugin, it will merge the params you return before dispatching to the webservice, e.g.
52
58
 
53
59
  $('#invoices').facet_context(function() {
54
- return {
55
- search: $("#search_field").val()
60
+ return {
61
+ search: $("#search_field").val()
56
62
  };
57
63
  });
58
64
 
@@ -64,7 +70,7 @@
64
70
  *Q* How do I make one-time, minor changes to the behaviour of a widget? For example, I want to add a control.
65
71
 
66
72
  *A* Use the inject option, which is part of the base functionality. Your injector function receives a reference to the widget's jquery element and to the widget javascript object. Use jquery to add your control's markup, then register an event handler to add its behaviour. For example, this injector adds a clear-all button in the title:
67
-
73
+
68
74
  $('#genre').facet({
69
75
  injectors: {
70
76
  '.title .controls' : function(self, data) { $(this).append('<span class="clear_control">[x]</span>'); }
@@ -104,10 +110,10 @@ In injectors and handlers, you have access to the complete faceting widget API (
104
110
  var hello_world = function($elem, options) {
105
111
  /* declare superclass */
106
112
  var self = repertoire.facet($elem, options);
107
-
113
+
108
114
  /* handlers */
109
- handler('.hello', function() {
110
- alert('hello, world!');
115
+ handler('.hello', function() {
116
+ alert('hello, world!');
111
117
  });
112
118
 
113
119
  /* injectors */
@@ -159,12 +165,12 @@ In injectors and handlers, you have access to the complete faceting widget API (
159
165
 
160
166
  *Q* What Javascript OOP convention is this?
161
167
 
162
- *A* It's based on section 5.4, "Functional Inheritance" of Douglas Crockford, "Javascript: The Good Parts."
168
+ *A* It's based on section 5.4, "Functional Inheritance" of Douglas Crockford, "Javascript: The Good Parts."
163
169
 
164
170
 
165
171
  *Q* Explain the naming conventions.
166
172
 
167
- *A* $foo is a jquery object, e.g. var $foo = $('.foo')
173
+ *A* $foo is a jquery object, e.g. var $foo = $('.foo')
168
174
  self is the object you're currently defining (as opposed to the one it inherits from, javascript's 'this', or its dom view)
169
175
 
170
176
 
data/INSTALL CHANGED
@@ -1,18 +1,17 @@
1
1
  === Installing Repertoire Faceting
2
2
 
3
- N.B. Repertoire Faceting requires Rails 3.0+, Ruby 1.9.2+, and JQuery 1.3.2+.
3
+ N.B. Repertoire Faceting requires Postgres 9.3+, Rails 3.2+, Ruby 2.0.0+, and JQuery 1.3.2+.
4
4
 
5
- == Short version.
5
+ == Short version.
6
6
 
7
- (You need a working Rails 3 app, with a model, controller, and a partial to show the model)
7
+ (You need a working Rails app, with a model, controller, and a partial to show the model)
8
8
 
9
9
  { in Gemfile }
10
10
  gem 'repertoire-faceting' // 1
11
11
 
12
12
  { install native bitset extensions }
13
13
  $ bundle install
14
- $ rake db:faceting:build { provide sudo your password }
15
- $ rake db:faceting:load
14
+ $ rake db:faceting:extensions:install { provide sudo your password }
16
15
 
17
16
  { in ./app/models/some_model.rb }
18
17
  class SomeModel
@@ -25,14 +24,14 @@ N.B. Repertoire Faceting requires Rails 3.0+, Ruby 1.9.2+, and JQuery 1.3.2+.
25
24
  include Repertoire::Faceting::Controller // 4
26
25
  def base; return SomeModel; end // 5
27
26
  end
28
-
27
+
29
28
  { in ./config/routes.rb }
30
29
  SomeApp::Application.routes.draw do
31
30
  faceting_for :some_model // 6
32
31
  end
33
-
32
+
34
33
  { in ./public/javascripts/application.js }
35
- //= require <rep.faceting> // 7
34
+ //= require rep.faceting // 7
36
35
 
37
36
  { in ./app/views/some_controller/index.html.erb }
38
37
  <script language="javascript">
@@ -49,65 +48,59 @@ N.B. Repertoire Faceting requires Rails 3.0+, Ruby 1.9.2+, and JQuery 1.3.2+.
49
48
 
50
49
  ... that's a complete faceted browser in only 13 new lines of code in your app!
51
50
 
52
- In production, you will want to compress the javascript facet widgets:
53
-
54
- { in ./config/environments/production.rb }
55
- config.repertoire_assets.compress = true
56
-
57
51
  Additionally, you may wish to index the facets. At the console or in a migration:
58
52
 
59
- SomeModel.update_indexed_facets([:some_column])
53
+ SomeModel.index_facets([:some_column])
60
54
 
61
- The faceting subsystem automatically detects available facet indices and uses
55
+ The faceting subsystem automatically detects available facet indices and uses
62
56
  them when appropriate.
63
57
 
64
58
 
65
59
  == Detailed version.
66
60
 
67
- Start with a working Rails 3 application with a PostgreSQL database.
61
+ Start with a working Rails application with a PostgreSQL database.
68
62
 
69
- * Require repertoire-faceting in Gemfile.
63
+ ** Note that the canonical resource for using Repertoire Faceting is the
64
+ Repertoire Faceting Example application. If you have questions, you are
65
+ best served by getting it running and exploring further there. **
70
66
 
71
- gem 'repertoire-faceting'
72
67
 
73
- * Make sure you use Rails version 3.0.2+, which adopted Arel 2.0.1. If necessary
74
- you can pull rails, arel, and rack from git.
68
+ * Require repertoire-faceting in Gemfile.
75
69
 
76
- gem 'rails', :git => 'git://github.com/rails/rails.git'
77
- gem 'arel', :git => 'git://github.com/rails/arel.git'
78
- gem "rack", :git => "git://github.com/rack/rack.git"
70
+ gem 'repertoire-faceting'
79
71
 
80
72
  * At the command line, bundle everything into your application:
81
73
 
82
74
  $ bundle install
83
75
 
84
- * From your application root, build and install the repertoire-faceting native
85
- extensions to PostgreSQL. These provide a bitwise signature type used to
76
+ * From your application root, build and install the repertoire-faceting native
77
+ extensions to PostgreSQL. These provide a bitwise signature type used to
86
78
  index and count facets.
87
79
 
88
- $ rake db:faceting:build { sudo will prompt you for your password }
80
+ $ rake db:faceting:extensions:install { sudo will prompt you for your password }
89
81
 
90
82
  * Load the extension into your local application database. This ensures the
91
83
  plpgsql language is installed, and loads (or re-loads) the new bitset signature
92
84
  type.
93
85
 
94
- $ createlang plpgsql -U<username> <database>
95
- $ rake db:faceting:load
96
-
86
+ $ psql -c "CREATE EXTENSION faceting;" -U<username> <database>
87
+
97
88
  Or, if you prefer to use migrations create one with the following contents:
98
-
99
- ....
100
- def self.up
101
- load_faceting # unload_faceting is the reverse
102
- end
89
+
90
+ def self.change
91
+ reversible do |dir
92
+ dir.up { execute('CREATE EXTENSION faceting') }
93
+ dir.down { execute('DROP EXTENSION faceting CASCADE') }
94
+ end
95
+ end
103
96
 
104
97
  Before proceeding, you can confirm the module is installed as follows.
105
98
 
106
- $ psql -c "SELECT count('101010101'::signature);" -U<username> <database>
99
+ $ psql -c "SELECT facet.count('101010101'::facet.signature);" -U<username> <database>
107
100
 
108
- * Install the faceting mixin in your Rails model and declare a facet on an
109
- existing database column. (See the README for complete configuration options
110
- for facets.)
101
+ * Install the faceting mixin in your Rails model and declare a facet on an
102
+ existing database column. (See the README for complete configuration options
103
+ for facets.)
111
104
 
112
105
  { ./app/models/painting.rb }
113
106
  class Painting
@@ -119,17 +112,17 @@ Start with a working Rails 3 application with a PostgreSQL database.
119
112
 
120
113
  $ rails c
121
114
  > Painting.count(:genre)
122
- => {"Impressionist"=>2, "Medieval"=>2}
115
+ => {"Impressionist"=>2, "Medieval"=>2}
123
116
  > Painting.refine(:genre => 'Impressionist')
124
- => [#<Painting id: 1, title: "Moonlight Shimmers", painter: "Monet", genre: "Impressionist">,
125
- #<Painting id: 2, title: "Nude Lunch in Garden", painter: "Manet", genre: "Impressionist">]
117
+ => [#<Painting id: 1, title: "Moonlight Shimmers", painter: "Monet", genre: "Impressionist">,
118
+ #<Painting id: 2, title: "Nude Lunch in Garden", painter: "Manet", genre: "Impressionist">]
126
119
 
127
120
  Or, with a base query as well:
128
121
 
129
122
  > Painting.where(["title like ?", 'Moon%']).count(:genre)
130
- => {"Impressionist"=>1}
123
+ => {"Impressionist"=>1}
131
124
 
132
- * Add faceting webservices to your controller and define base() to indicate which model to base queries on
125
+ * Add faceting webservices to your controller and define base() to indicate which model to base queries on
133
126
 
134
127
  { ./app/controllers/paintings_controller }
135
128
  class PaintingsController
@@ -141,7 +134,7 @@ Start with a working Rails 3 application with a PostgreSQL database.
141
134
  end
142
135
  end
143
136
 
144
- * Add faceting routes to your application.
137
+ * Add faceting routes to your application.
145
138
 
146
139
  { ./config/routes.rb }
147
140
 
@@ -158,23 +151,9 @@ Start with a working Rails 3 application with a PostgreSQL database.
158
151
  paintings_results /paintings/results(.:format) {:controller=>"paintings", :action=>"results"}
159
152
  ...
160
153
 
161
- * Load the javascript facet widgets in your main javascript file. The
162
- repertoire-assets subsystem will locate the widgets in your application's
163
- rubygems, and load them as appropriate.
164
-
165
- { ./public/javascripts/application.js }
166
- ...
167
- //= require <rep.faceting>
168
- ...
169
-
170
- N.B. Repertoire Faceting widgets are based on JQuery, which is incompatible
171
- with Prototype. If you have not already done so, you should remove
172
- prototype.js and rails.js from the javascripts directory, and delete the
173
- "<%= javascript_include_tag :defaults %>" line from application.html.erb.
174
-
175
- * Add facet count and result widgets to your HTML page. The facet context div
176
- collects widgets that affect the same query together. (For complete options,
177
- see the README )
154
+ * Add facet count and result widgets to your HTML page. The facet context div
155
+ collects widgets that affect the same query together. (For complete options,
156
+ see the README )
178
157
 
179
158
  { ./app/views/paintings/index.html.erb }
180
159
 
@@ -187,55 +166,44 @@ Start with a working Rails 3 application with a PostgreSQL database.
187
166
  </script>
188
167
  <div id='paintings'>
189
168
  <div id='genre' class='facet'></div>
190
- <div id='results'></div>
169
+ <div id='results'></div>
191
170
  </div>
192
-
193
- * If you don't already have one, create a partial for displaying your model in
171
+
172
+ * If you don't already have one, create a partial for displaying your model in
194
173
  results lists.
195
174
 
196
175
  { ./app/views/paintings/_painting.html.erb }
197
-
176
+
198
177
  <div class='painting' style='width:235px; margin-bottom:5px; padding:2px; border:dotted 1px;'>
199
178
  <div>Title: <%= painting.title %></div>
200
179
  <div>Painter: <%= painting.painter %></div>
201
180
  <div>Genre: <%= painting.genre %></div>
202
181
  </div>
203
182
 
204
- * [ Optional ] Configure the repertoire-assets module that loads the javascript
205
- faceting widgets to compress the widget code in production.
206
-
207
- { ./config/environments/production.rb }
208
-
209
- PaintingsApp::Application.configure do
210
- ...
211
- config.repertoire_assets.compress = true
212
- ...
213
- end
214
-
215
- * [ Optional ] Add bitset indexes to some facets on your model. The module will
216
- automatically use facet indexes when they are available. Facet indexes scale
217
- out of the box to over a million model items, and require no additional
183
+ * [ Optional ] Add bitset indexes to some facets on your model. The module will
184
+ automatically use facet indexes when they are available. Facet indexes scale
185
+ out of the box to over a million model items, and requires no additional
218
186
  configuration.
219
187
 
220
188
  $ rails generate migration AddFacetIndex
221
-
189
+
222
190
  { ./db/migrate/<your date>add_facet_index.rb }
223
191
  class AddFacetIndex < ActiveRecord::Migration
224
192
  def self.up
225
- Painting.update_indexed_facets([:genre])
193
+ Painting.index_facets([:genre])
226
194
  end
227
195
 
228
196
  def self.down
229
- Painting.update_indexed_facets
197
+ Painting.index_facets
230
198
  end
231
199
  end
232
200
 
233
- * [ Optional ] Periodically update indexes via a crontab task.
201
+ * [ Optional ] Periodically update indexes via a crontab task.
234
202
 
235
203
  { ./lib/tasks/update_facets.rake }
236
204
 
237
205
  task :reindex => :environment do
238
- Painting.update_indexed_facets
206
+ Painting.index_facets # NB this updates whatever indexes already exist
239
207
  end
240
208
 
241
209
  ... And then configure crontab to execute 'rake reindex' at appropriate intervals.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2012 MIT Hyperstudio
1
+ Copyright (c) 2008-2014 MIT Hyperstudio
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation