mysql_simple_fulltext 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,7 +4,11 @@ MysqlSimpleFulltext lets you make simple MySQL fulltext searches a simple way wi
4
4
 
5
5
  == Getting started
6
6
 
7
- Currently publishing the gem.
7
+ gem install mysql_simple_fulltext
8
+
9
+ In your Gemfile
10
+
11
+ gem "mysql_simple_fulltext"
8
12
 
9
13
  == In your model
10
14
 
@@ -1,8 +1,8 @@
1
1
  Description:
2
- Explain the generator
2
+ Generate MySQL FUlltext index migration
3
3
 
4
4
  Example:
5
- rails generate migration Thing
5
+ rails generate mysql_simple_fulltext:migration Thing
6
6
 
7
7
  This will create:
8
- what/will/it/create
8
+ db/migrate/create_things_fulltext_index.rb
@@ -1,3 +1,3 @@
1
1
  module MysqlSimpleFulltext
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,7 +2,7 @@ class PostsController < ApplicationController
2
2
  # GET /posts
3
3
  # GET /posts.json
4
4
  def index
5
- @posts = Post.fulltext_search "toto"
5
+ @posts = Post.fulltext_search params[:search]
6
6
 
7
7
  respond_to do |format|
8
8
  format.html # index.html.erb
@@ -2656,3 +2656,110 @@ Mysql2::Error: You have an error in your SQL syntax; check the manual that corre
2656
2656
  Fixture Insert (3.8ms) INSERT INTO `posts` (`title`, `content`, `created_at`, `updated_at`, `id`) VALUES ('Pellentesque consequat', 'Pellentesque consequat ipsum et turpis placerat non molestie arcu consequat. Maecenas non iaculis tellus. Aenean ac urna sit amet urna blandit malesuada. Duis placerat faucibus metus quis tristique. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent condimentum, augue sit amet rutrum feugiat, nunc risus vehicula felis, id hendrerit tortor justo at ligula. Ut tempus lorem ac urna vehicula blandit. Nullam tincidunt magna non massa ullamcorper hendrerit.', '2012-02-19 21:30:59', '2012-02-19 21:30:59', 973100822)
2657
2657
   (0.5ms) COMMIT
2658
2658
   (0.3ms) SET FOREIGN_KEY_CHECKS = 1
2659
+
2660
+
2661
+ Started GET "/" for 127.0.0.1 at 2012-03-01 21:49:36 +0100
2662
+ Processing by PostsController#index as HTML
2663
+ Post Load (189.6ms) SELECT *, MATCH (title,content) AGAINST (NULL) AS fulltext_score FROM posts WHERE MATCH (title,content) AGAINST (NULL) ORDER BY fulltext_score ASC
2664
+ Rendered posts/index.html.erb within layouts/application (60.9ms)
2665
+ Completed 200 OK in 892ms (Views: 404.7ms | ActiveRecord: 189.6ms)
2666
+
2667
+
2668
+ Started GET "/assets/posts.css?body=1" for 127.0.0.1 at 2012-03-01 21:49:38 +0100
2669
+ Served asset /posts.css - 304 Not Modified (6ms)
2670
+
2671
+
2672
+ Started GET "/assets/scaffold.css?body=1" for 127.0.0.1 at 2012-03-01 21:49:38 +0100
2673
+ Served asset /scaffold.css - 304 Not Modified (26ms)
2674
+
2675
+
2676
+ Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:38 +0100
2677
+ Served asset /jquery_ujs.js - 304 Not Modified (21ms)
2678
+
2679
+
2680
+ Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:38 +0100
2681
+ Served asset /application.js - 304 Not Modified (33ms)
2682
+
2683
+
2684
+ Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-03-01 21:49:38 +0100
2685
+ Served asset /application.css - 304 Not Modified (34ms)
2686
+
2687
+
2688
+ Started GET "/assets/posts.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:38 +0100
2689
+ Served asset /posts.js - 304 Not Modified (7ms)
2690
+
2691
+
2692
+ Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:38 +0100
2693
+ Served asset /jquery.js - 304 Not Modified (26ms)
2694
+
2695
+
2696
+ Started GET "/posts?utf8=%E2%9C%93&search=ofze" for 127.0.0.1 at 2012-03-01 21:49:42 +0100
2697
+ Processing by PostsController#index as HTML
2698
+ Parameters: {"utf8"=>"✓", "search"=>"ofze"}
2699
+ Post Load (213.9ms) SELECT *, MATCH (title,content) AGAINST ('ofze') AS fulltext_score FROM posts WHERE MATCH (title,content) AGAINST ('ofze') ORDER BY fulltext_score ASC
2700
+ Rendered posts/index.html.erb within layouts/application (61.7ms)
2701
+ Completed 200 OK in 308ms (Views: 90.8ms | ActiveRecord: 213.9ms)
2702
+
2703
+
2704
+ Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-03-01 21:49:43 +0100
2705
+ Served asset /application.css - 304 Not Modified (3ms)
2706
+
2707
+
2708
+ Started GET "/assets/posts.css?body=1" for 127.0.0.1 at 2012-03-01 21:49:43 +0100
2709
+ Served asset /posts.css - 304 Not Modified (1ms)
2710
+
2711
+
2712
+ Started GET "/assets/scaffold.css?body=1" for 127.0.0.1 at 2012-03-01 21:49:43 +0100
2713
+ Served asset /scaffold.css - 304 Not Modified (15ms)
2714
+
2715
+
2716
+ Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:43 +0100
2717
+ Served asset /jquery.js - 304 Not Modified (3ms)
2718
+
2719
+
2720
+ Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:43 +0100
2721
+ Served asset /jquery_ujs.js - 304 Not Modified (1ms)
2722
+
2723
+
2724
+ Started GET "/assets/posts.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:43 +0100
2725
+ Served asset /posts.js - 304 Not Modified (0ms)
2726
+
2727
+
2728
+ Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:43 +0100
2729
+ Served asset /application.js - 304 Not Modified (7ms)
2730
+
2731
+
2732
+ Started GET "/posts?utf8=%E2%9C%93&search=ofzeefze" for 127.0.0.1 at 2012-03-01 21:49:46 +0100
2733
+ Processing by PostsController#index as HTML
2734
+ Parameters: {"utf8"=>"✓", "search"=>"ofzeefze"}
2735
+ Post Load (1.0ms) SELECT *, MATCH (title,content) AGAINST ('ofzeefze') AS fulltext_score FROM posts WHERE MATCH (title,content) AGAINST ('ofzeefze') ORDER BY fulltext_score ASC
2736
+ Rendered posts/index.html.erb within layouts/application (5.7ms)
2737
+ Completed 200 OK in 45ms (Views: 41.3ms | ActiveRecord: 1.0ms)
2738
+
2739
+
2740
+ Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-03-01 21:49:46 +0100
2741
+ Served asset /application.css - 304 Not Modified (2ms)
2742
+
2743
+
2744
+ Started GET "/assets/posts.css?body=1" for 127.0.0.1 at 2012-03-01 21:49:46 +0100
2745
+ Served asset /posts.css - 304 Not Modified (1ms)
2746
+
2747
+
2748
+ Started GET "/assets/scaffold.css?body=1" for 127.0.0.1 at 2012-03-01 21:49:46 +0100
2749
+ Served asset /scaffold.css - 304 Not Modified (0ms)
2750
+
2751
+
2752
+ Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:47 +0100
2753
+ Served asset /jquery.js - 304 Not Modified (9ms)
2754
+
2755
+
2756
+ Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:47 +0100
2757
+ Served asset /jquery_ujs.js - 304 Not Modified (1ms)
2758
+
2759
+
2760
+ Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:47 +0100
2761
+ Served asset /application.js - 304 Not Modified (14ms)
2762
+
2763
+
2764
+ Started GET "/assets/posts.js?body=1" for 127.0.0.1 at 2012-03-01 21:49:47 +0100
2765
+ Served asset /posts.js - 304 Not Modified (0ms)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_simple_fulltext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &76062440 !ruby/object:Gem::Requirement
16
+ requirement: &72600750 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76062440
24
+ version_requirements: *72600750
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mysql2
27
- requirement: &76062210 !ruby/object:Gem::Requirement
27
+ requirement: &72600510 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *76062210
35
+ version_requirements: *72600510
36
36
  description: MysqlSimpleFulltext lets you make simple MySQL fulltext searches a simple
37
37
  way without writing SQL queries in your ActiveRecord.
38
38
  email:
@@ -45,11 +45,8 @@ files:
45
45
  - lib/tasks/mysql_simple_fulltext_tasks.rake
46
46
  - lib/generators/mysql_simple_fulltext/USAGE
47
47
  - lib/generators/mysql_simple_fulltext/migration_generator.rb
48
- - lib/generators/mysql_simple_fulltext/migration_generator.rb~
49
- - lib/generators/mysql_simple_fulltext/templates/migration.rb~
50
48
  - lib/generators/mysql_simple_fulltext/templates/migration.rb
51
49
  - lib/mysql_simple_fulltext/version.rb
52
- - lib/mysql_simple_fulltext.rb~
53
50
  - MIT-LICENSE
54
51
  - Rakefile
55
52
  - README.rdoc
@@ -103,13 +100,11 @@ files:
103
100
  - test/dummy/app/assets/stylesheets/scaffold.css
104
101
  - test/dummy/app/assets/javascripts/posts.js
105
102
  - test/dummy/app/assets/javascripts/application.js
106
- - test/dummy/app/controllers/posts_controller.rb~
107
103
  - test/dummy/app/controllers/posts_controller.rb
108
104
  - test/dummy/app/controllers/application_controller.rb
109
105
  - test/dummy/app/helpers/application_helper.rb
110
106
  - test/dummy/app/helpers/posts_helper.rb
111
107
  - test/dummy/app/models/post.rb
112
- - test/dummy/app/models/post.rb~
113
108
  - test/dummy/public/favicon.ico
114
109
  - test/dummy/public/500.html
115
110
  - test/dummy/public/422.html
@@ -142,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
137
  version: '0'
143
138
  requirements: []
144
139
  rubyforge_project:
145
- rubygems_version: 1.8.15
140
+ rubygems_version: 1.8.17
146
141
  signing_key:
147
142
  specification_version: 3
148
143
  summary: MysqlSimpleFulltext
@@ -197,13 +192,11 @@ test_files:
197
192
  - test/dummy/app/assets/stylesheets/scaffold.css
198
193
  - test/dummy/app/assets/javascripts/posts.js
199
194
  - test/dummy/app/assets/javascripts/application.js
200
- - test/dummy/app/controllers/posts_controller.rb~
201
195
  - test/dummy/app/controllers/posts_controller.rb
202
196
  - test/dummy/app/controllers/application_controller.rb
203
197
  - test/dummy/app/helpers/application_helper.rb
204
198
  - test/dummy/app/helpers/posts_helper.rb
205
199
  - test/dummy/app/models/post.rb
206
- - test/dummy/app/models/post.rb~
207
200
  - test/dummy/public/favicon.ico
208
201
  - test/dummy/public/500.html
209
202
  - test/dummy/public/422.html
@@ -1,28 +0,0 @@
1
- require 'rails/generators/migration'
2
-
3
- module MysqlSimpleFulltext
4
- class MigrationGenerator < Rails::Generators::NamedBase
5
- include Rails::Generators::Migration
6
-
7
- source_root File.expand_path('../templates', __FILE__)
8
-
9
- def create_migration_file
10
- puts self.methods
11
- migration_template "migration.rb", "db/migrate/create_#{file_name}_fulltext_index.rb"
12
- end
13
-
14
- def fulltext_fields
15
- eval(name).fulltext_config.fields
16
- end
17
-
18
- # Define the next_migration_number method (necessary for the migration_template method to work)
19
- def self.next_migration_number(dirname)
20
- if ActiveRecord::Base.timestamped_migrations
21
- sleep 1 # make sure each time we get a different timestamp
22
- Time.new.utc.strftime("%Y%m%d%H%M%S")
23
- else
24
- "%.3d" % (current_migration_number(dirname) + 1)
25
- end
26
- end
27
- end
28
- end
@@ -1,11 +0,0 @@
1
- class <%= migration_class_name %> < ActiveRecord::Migration
2
- def self.up
3
- execute 'ALTER TABLE <%= plural_name %> ENGINE = MyISAM'
4
- execute 'CREATE FULLTEXT INDEX fulltext_<%= plural_name %> ON <%= plural_name %> (<%= fulltext_fields.join(',') %>)'
5
- end
6
-
7
- def self.down
8
- execute 'ALTER TABLE <%= plural_name %> ENGINE = InnoDB'
9
- execute 'DROP INDEX fulltext_<%= plural_name %> ON <%= plural_name %>'
10
- end
11
- end
@@ -1,27 +0,0 @@
1
- module MysqlSimpleFulltext
2
- def search_with_simple_fulltext fields
3
- @config = Config.new fields
4
-
5
- extend InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def fulltext_search query
10
- find_by_sql [ "SELECT *, MATCH (" + @config.fields.join(',') + ") AGAINST (?) AS fulltext_score FROM #{table_name} WHERE MATCH (" + @config.fields.join(',') + ") AGAINST (?)", query, query ]
11
- end
12
-
13
- def fulltext_config
14
- @config
15
- end
16
- end
17
-
18
- class Config
19
- attr_accessor :fields
20
-
21
- def initialize(fields)
22
- self.fields= fields
23
- end
24
- end
25
- end
26
-
27
- ActiveRecord::Base.extend MysqlSimpleFulltext
@@ -1,83 +0,0 @@
1
- class PostsController < ApplicationController
2
- # GET /posts
3
- # GET /posts.json
4
- def index
5
- @posts = Post.fulltext_search
6
-
7
- respond_to do |format|
8
- format.html # index.html.erb
9
- format.json { render json: @posts }
10
- end
11
- end
12
-
13
- # GET /posts/1
14
- # GET /posts/1.json
15
- def show
16
- @post = Post.find(params[:id])
17
-
18
- respond_to do |format|
19
- format.html # show.html.erb
20
- format.json { render json: @post }
21
- end
22
- end
23
-
24
- # GET /posts/new
25
- # GET /posts/new.json
26
- def new
27
- @post = Post.new
28
-
29
- respond_to do |format|
30
- format.html # new.html.erb
31
- format.json { render json: @post }
32
- end
33
- end
34
-
35
- # GET /posts/1/edit
36
- def edit
37
- @post = Post.find(params[:id])
38
- end
39
-
40
- # POST /posts
41
- # POST /posts.json
42
- def create
43
- @post = Post.new(params[:post])
44
-
45
- respond_to do |format|
46
- if @post.save
47
- format.html { redirect_to @post, notice: 'Post was successfully created.' }
48
- format.json { render json: @post, status: :created, location: @post }
49
- else
50
- format.html { render action: "new" }
51
- format.json { render json: @post.errors, status: :unprocessable_entity }
52
- end
53
- end
54
- end
55
-
56
- # PUT /posts/1
57
- # PUT /posts/1.json
58
- def update
59
- @post = Post.find(params[:id])
60
-
61
- respond_to do |format|
62
- if @post.update_attributes(params[:post])
63
- format.html { redirect_to @post, notice: 'Post was successfully updated.' }
64
- format.json { head :no_content }
65
- else
66
- format.html { render action: "edit" }
67
- format.json { render json: @post.errors, status: :unprocessable_entity }
68
- end
69
- end
70
- end
71
-
72
- # DELETE /posts/1
73
- # DELETE /posts/1.json
74
- def destroy
75
- @post = Post.find(params[:id])
76
- @post.destroy
77
-
78
- respond_to do |format|
79
- format.html { redirect_to posts_url }
80
- format.json { head :no_content }
81
- end
82
- end
83
- end
@@ -1,3 +0,0 @@
1
- class Post < ActiveRecord::Base
2
- search_with_simple_fulltext [:title, :content]
3
- end