search_do 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'activerecord'
4
+
5
+ group :dev do
6
+ gem 'rails', ENV['RAILS']
7
+ gem 'sqlite3'
8
+ gem 'will_paginate'
9
+ gem 'rdoc'
10
+ gem 'rake'
11
+ gem 'rspec', '~>1'
12
+ gem 'jeweler'
13
+ end
@@ -0,0 +1,44 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (2.3.14)
5
+ actionpack (= 2.3.14)
6
+ actionpack (2.3.14)
7
+ activesupport (= 2.3.14)
8
+ rack (~> 1.1.0)
9
+ activerecord (2.3.14)
10
+ activesupport (= 2.3.14)
11
+ activeresource (2.3.14)
12
+ activesupport (= 2.3.14)
13
+ activesupport (2.3.14)
14
+ git (1.2.5)
15
+ jeweler (1.6.4)
16
+ bundler (~> 1.0)
17
+ git (>= 1.2.5)
18
+ rake
19
+ rack (1.1.0)
20
+ rails (2.3.14)
21
+ actionmailer (= 2.3.14)
22
+ actionpack (= 2.3.14)
23
+ activerecord (= 2.3.14)
24
+ activeresource (= 2.3.14)
25
+ activesupport (= 2.3.14)
26
+ rake (>= 0.8.3)
27
+ rake (0.9.2.2)
28
+ rdoc (3.8)
29
+ rspec (1.3.1)
30
+ sqlite3 (1.3.5)
31
+ will_paginate (2.3.16)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ activerecord
38
+ jeweler
39
+ rails
40
+ rake
41
+ rdoc
42
+ rspec (~> 1)
43
+ sqlite3
44
+ will_paginate
@@ -13,8 +13,12 @@ A working Hyper Estraier instance, setup instructions:
13
13
 
14
14
 
15
15
  == Install
16
- * script/plugin install git://github.com/grosser/search_do.git
17
- * install will_paginate to use "paginate_by_fulltext_search" (Instruction: http://github.com/mislav/will_paginate/wikis/installation)
16
+ As Rails plugin(recommended <-> rake tasks/cap recipes):
17
+ rails plugin install git://github.com/grosser/search_do.git
18
+ Or as Gem:
19
+ sudo gem install searh_do
20
+
21
+ install will_paginate to use "paginate_by_fulltext_search" (Instruction: http://github.com/mislav/will_paginate/wikis/installation)
18
22
 
19
23
 
20
24
  == Usage
@@ -57,6 +61,10 @@ A working Hyper Estraier instance, setup instructions:
57
61
  - Built in P2P clustering of index servers
58
62
 
59
63
 
64
+ == TODO
65
+ - make specs work with RSpec 2
66
+
67
+
60
68
  == Origin
61
69
  Original is written by scoop see
62
70
  * http://github.com/scoop/acts_as_searchable/tree/master
data/Rakefile CHANGED
@@ -1,23 +1,14 @@
1
- require 'rake/rdoctask'
2
- require 'spec'
1
+ require 'rdoc/task'
3
2
 
4
- desc 'Default: run specs_all.'
5
- task :default => :spec_all
6
-
7
- require 'spec/rake/spectask'
8
- Spec::Rake::SpecTask.new {|t| t.spec_opts = ['--color']}
3
+ task :spec do
4
+ sh "bundle exec spec spec"
5
+ end
9
6
 
10
- desc "Run specs both AR-latest and AR-2.0.x"
11
- task :spec_all do
12
- ar20xs = (::Gem.source_index.find_name("activerecord", "<2.1") & \
13
- ::Gem.source_index.find_name("activerecord", ">=2.0"))
14
- if ar20xs.empty?
15
- Rake::Task[:spec].invoke
16
- else
17
- ar20 = ar20xs.sort_by(&:version).last
18
- system("rake spec")
19
- system("rake spec AR=#{ar20.version}")
20
- end
7
+ task :default do
8
+ sh "RAILS=2.3.14 && (bundle || bundle install) && bundle exec rake spec"
9
+ sh "RAILS=3.0.12 && (bundle || bundle install) && bundle exec rake spec"
10
+ sh "RAILS=3.1.3 && (bundle || bundle install) && bundle exec rake spec"
11
+ sh "git checkout Gemfile.lock"
21
12
  end
22
13
 
23
14
  desc 'Generate documentation for the acts_as_searchable plugin.'
@@ -38,7 +29,7 @@ begin
38
29
  gem.summary = "AR: Hyperestraier integration"
39
30
  gem.email = "moronatural@gmail.com"
40
31
  gem.homepage = "http://github.com/grosser/#{project_name}"
41
- gem.authors = ["MOROHASHI Kyosuke"]
32
+ gem.authors = ["MOROHASHI Kyosuke", "Michael Grosser"]
42
33
  end
43
34
 
44
35
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -118,7 +118,7 @@ module SearchDo
118
118
 
119
119
  cattr_accessor :search_indexer, :search_backend
120
120
 
121
- self.search_indexer = returning(SearchDo::Indexer.new(self, configurations)) do |idx|
121
+ self.search_indexer = SearchDo::Indexer.new(self, configurations).tap do |idx|
122
122
  idx.searchable_fields = options[:searchable_fields] || [ :body ]
123
123
  idx.attributes_to_store = options[:attributes] || {}
124
124
  idx.if_changed = options[:if_changed] || []
@@ -173,7 +173,7 @@ module SearchDo
173
173
 
174
174
  ids_and_raw = matched_ids_and_raw(query, options)
175
175
  ids = ids_and_raw.map{|id,raw| id}
176
-
176
+
177
177
  results = find_by_ids_scope(ids, find_options)
178
178
  add_snippets(results,ids_and_raw) unless query.blank?
179
179
  results
@@ -187,7 +187,7 @@ module SearchDo
187
187
  options[:offset]=(page.to_i-1)*per_page
188
188
  options.delete(:page)#acts_as cannot read this...
189
189
  options.delete(:per_page)#acts_as cannot read this...
190
-
190
+
191
191
  #find results
192
192
  pager.replace fulltext_search(query,options)
193
193
 
@@ -216,7 +216,7 @@ module SearchDo
216
216
  def matched_ids_and_raw(query = "", options = {})
217
217
  search_backend.search_all_ids_and_raw(query, options)
218
218
  end
219
-
219
+
220
220
  def matched_ids(query = "", options = {})
221
221
  matched_ids_and_raw(query,options).map{|id,raw|id}
222
222
  end
@@ -241,7 +241,7 @@ module SearchDo
241
241
  end
242
242
 
243
243
  private
244
-
244
+
245
245
  def add_snippets(results,ids_and_raw)
246
246
  results.each do |result|
247
247
  raw = ids_and_raw.assoc(result.id)[1]
@@ -262,10 +262,10 @@ module SearchDo
262
262
  require 'action_controller'
263
263
  ::ActionController::Base.helpers.strip_tags(text)
264
264
  end
265
-
265
+
266
266
  def connect_backend(active_record_config) #:nodoc:
267
- backend_config = active_record_config[RAILS_ENV]['search'] || \
268
- active_record_config[RAILS_ENV]['estraier'] || {}
267
+ backend_config = active_record_config[Rails.env]['search'] || \
268
+ active_record_config[Rails.env]['estraier'] || {}
269
269
  self.search_backend = Backends.connect(self, backend_config)
270
270
  end
271
271
 
@@ -277,7 +277,7 @@ module SearchDo
277
277
  end
278
278
  apply_ids_order_to(ids,results)
279
279
  end
280
-
280
+
281
281
  def apply_ids_order_to(ids,results)
282
282
  #replace id with found item
283
283
  results.each {|item| ids[ids.index(item.id)] = item}
@@ -327,4 +327,4 @@ module SearchDo
327
327
  end
328
328
  end
329
329
 
330
- ActiveRecord::Base.send :include, SearchDo
330
+ ActiveRecord::Base.send :include, SearchDo
@@ -197,7 +197,7 @@ module SearchDo
197
197
  end
198
198
 
199
199
  def calculate_node_name(config)
200
- node_prefix = config['node_prefix'] || config['node'] || RAILS_ENV
200
+ node_prefix = config['node_prefix'] || config['node'] || Rails.env
201
201
  "#{node_prefix}_#{@ar_class.table_name}"
202
202
  end
203
203
 
@@ -1,15 +1,20 @@
1
- require 'search_do/dirty_tracking/self_made'
2
- require 'search_do/dirty_tracking/bridge'
3
-
4
1
  module SearchDo
5
2
  module DirtyTracking
6
- def self.included(base)
7
- mod = if defined?(ActiveRecord::Dirty) && base.included_modules.include?(ActiveRecord::Dirty)
8
- DirtyTracking::Bridge
9
- else
10
- DirtyTracking::SelfMade
11
- end
12
- base.send(:include, mod)
3
+ def need_update_index?(attr_name = nil)
4
+ return false unless changed?
5
+ cs = changed_attributes.keys
6
+ if attr_name
7
+ cs.include?(attr_name)
8
+ else
9
+ search_indexer.observing_fields.any?{|t| cs.include?(t) }
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def clear_changed_attributes
16
+ changed_attributes.clear
13
17
  end
14
18
  end
15
19
  end
20
+
@@ -936,7 +936,7 @@ module EstraierPure
936
936
  sock.printf("%s\r\n", line)
937
937
  end
938
938
  end
939
- sock.printf("Content-Length: %d\r\n", reqbody.length) if reqbody
939
+ sock.printf("Content-Length: %d\r\n", reqbody.bytesize) if reqbody
940
940
  sock.printf("\r\n")
941
941
  sock.write(reqbody) if reqbody
942
942
  line = sock.gets.chomp
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "search_do"
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["MOROHASHI Kyosuke", "Michael Grosser"]
12
+ s.date = "2011-12-24"
13
+ s.email = "moronatural@gmail.com"
14
+ s.extra_rdoc_files = [
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ "CHANGELOG",
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "MIT-LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "TESTING",
25
+ "VERSION",
26
+ "examples/he_search.rb",
27
+ "examples/person.rb",
28
+ "init.rb",
29
+ "lib/estraier_admin.rb",
30
+ "lib/search_do.rb",
31
+ "lib/search_do/backends.rb",
32
+ "lib/search_do/backends/hyper_estraier.rb",
33
+ "lib/search_do/backends/hyper_estraier/estraier_pure_extention.rb",
34
+ "lib/search_do/dirty_tracking.rb",
35
+ "lib/search_do/indexer.rb",
36
+ "lib/search_do/utils.rb",
37
+ "lib/vendor/estraierpure.rb",
38
+ "lib/vendor/overview",
39
+ "recipes/mode_maintenance.rb",
40
+ "search_do.gemspec",
41
+ "spec/backends/hyper_estraier_spec.rb",
42
+ "spec/backends/result_document_spec.rb",
43
+ "spec/dirty_tracking/bridge_spec.rb",
44
+ "spec/estraier_admin_spec.rb",
45
+ "spec/fixtures/stories.yml",
46
+ "spec/indexer_spec.rb",
47
+ "spec/search_do_spec.rb",
48
+ "spec/setup_test_model.rb",
49
+ "spec/spec_helper.rb",
50
+ "tasks/acts_as_searchable_tasks.rake"
51
+ ]
52
+ s.homepage = "http://github.com/grosser/search_do"
53
+ s.require_paths = ["lib"]
54
+ s.rubygems_version = "1.8.10"
55
+ s.summary = "AR: Hyperestraier integration"
56
+
57
+ if s.respond_to? :specification_version then
58
+ s.specification_version = 3
59
+
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<activerecord>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<activerecord>, [">= 0"])
67
+ end
68
+ end
69
+
@@ -1,35 +1,18 @@
1
1
  # ---- requirements
2
2
  $KCODE = 'u' #activate regex unicode
3
- require 'rubygems'
4
3
  require 'spec'
5
4
  $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
6
5
 
7
-
8
- # ---- bugfix
9
- #`exit?': undefined method `run?' for Test::Unit:Module (NoMethodError)
10
- #can be solved with require test/unit but this will result in extra test-output
11
- unless defined? Test::Unit
12
- module Test
13
- module Unit
14
- def self.run?
15
- true
16
- end
17
- end
18
- end
19
- end
20
-
21
-
22
- # ---- load active record
23
- #gem 'activerecord', '2.0.2'
24
- if ENV["AR"]
25
- gem 'activerecord', ENV["AR"]
26
- $stderr.puts("Using ActiveRecord #{ENV["AR"]}")
27
- end
28
6
  require 'active_record'
29
7
 
30
8
  require File.expand_path("../init", File.dirname(__FILE__))
31
9
 
32
- RAILS_ENV = "test"
10
+ module Rails
11
+ def self.env
12
+ 'test'
13
+ end
14
+ end
15
+
33
16
  ActiveRecord::Base.configurations = {"test" => {
34
17
  :adapter => "sqlite3",
35
18
  :database => ":memory:",
metadata CHANGED
@@ -1,18 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_do
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - MOROHASHI Kyosuke
14
+ - Michael Grosser
8
15
  autorequire:
9
16
  bindir: bin
10
17
  cert_chain: []
11
18
 
12
- date: 2009-12-24 00:00:00 +01:00
13
- default_executable:
14
- dependencies: []
15
-
19
+ date: 2011-12-24 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ requirement: *id001
32
+ prerelease: false
33
+ type: :runtime
34
+ name: activerecord
16
35
  description:
17
36
  email: moronatural@gmail.com
18
37
  executables: []
@@ -23,6 +42,8 @@ extra_rdoc_files:
23
42
  - README.rdoc
24
43
  files:
25
44
  - CHANGELOG
45
+ - Gemfile
46
+ - Gemfile.lock
26
47
  - MIT-LICENSE
27
48
  - README.rdoc
28
49
  - Rakefile
@@ -37,13 +58,12 @@ files:
37
58
  - lib/search_do/backends/hyper_estraier.rb
38
59
  - lib/search_do/backends/hyper_estraier/estraier_pure_extention.rb
39
60
  - lib/search_do/dirty_tracking.rb
40
- - lib/search_do/dirty_tracking/bridge.rb
41
- - lib/search_do/dirty_tracking/self_made.rb
42
61
  - lib/search_do/indexer.rb
43
62
  - lib/search_do/utils.rb
44
63
  - lib/vendor/estraierpure.rb
45
64
  - lib/vendor/overview
46
65
  - recipes/mode_maintenance.rb
66
+ - search_do.gemspec
47
67
  - spec/backends/hyper_estraier_spec.rb
48
68
  - spec/backends/result_document_spec.rb
49
69
  - spec/dirty_tracking/bridge_spec.rb
@@ -54,42 +74,38 @@ files:
54
74
  - spec/setup_test_model.rb
55
75
  - spec/spec_helper.rb
56
76
  - tasks/acts_as_searchable_tasks.rake
57
- has_rdoc: true
58
77
  homepage: http://github.com/grosser/search_do
59
78
  licenses: []
60
79
 
61
80
  post_install_message:
62
- rdoc_options:
63
- - --charset=UTF-8
81
+ rdoc_options: []
82
+
64
83
  require_paths:
65
84
  - lib
66
85
  required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
67
87
  requirements:
68
88
  - - ">="
69
89
  - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
70
93
  version: "0"
71
- version:
72
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
73
96
  requirements:
74
97
  - - ">="
75
98
  - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
76
102
  version: "0"
77
- version:
78
103
  requirements: []
79
104
 
80
105
  rubyforge_project:
81
- rubygems_version: 1.3.5
106
+ rubygems_version: 1.8.10
82
107
  signing_key:
83
108
  specification_version: 3
84
109
  summary: "AR: Hyperestraier integration"
85
- test_files:
86
- - spec/spec_helper.rb
87
- - spec/backends/result_document_spec.rb
88
- - spec/backends/hyper_estraier_spec.rb
89
- - spec/indexer_spec.rb
90
- - spec/setup_test_model.rb
91
- - spec/estraier_admin_spec.rb
92
- - spec/search_do_spec.rb
93
- - spec/dirty_tracking/bridge_spec.rb
94
- - examples/person.rb
95
- - examples/he_search.rb
110
+ test_files: []
111
+
@@ -1,22 +0,0 @@
1
- module SearchDo
2
- module DirtyTracking
3
- module Bridge
4
-
5
- def need_update_index?(attr_name = nil)
6
- return false unless changed?
7
- cs = changed_attributes.keys
8
- if attr_name
9
- cs.include?(attr_name)
10
- else
11
- search_indexer.observing_fields.any?{|t| cs.include?(t) }
12
- end
13
- end
14
-
15
- private
16
- def clear_changed_attributes
17
- changed_attributes.clear
18
- end
19
- end
20
- end
21
- end
22
-
@@ -1,36 +0,0 @@
1
-
2
- module SearchDo
3
- module DirtyTracking
4
- module SelfMade
5
- def self.included(base)
6
- base.class_eval do
7
- attr_accessor :changed_attributes
8
-
9
- search_indexer.observing_fields.each do |attr_name|
10
- define_method("#{attr_name}=") do |value|
11
- write_changed_attribute attr_name, value
12
- end
13
- end
14
- end
15
- end
16
-
17
- # If called with no parameters, gets whether the current model has changed and needs to updated in the index.
18
- # If called with a single parameter, gets whether the parameter has changed.
19
- def need_update_index?(attr_name = nil)
20
- changed_attributes and (attr_name.nil? ?
21
- (not changed_attributes.length.zero?) : (changed_attributes.include?(attr_name.to_s)) )
22
- end
23
-
24
- private
25
- def clear_changed_attributes #:nodoc:
26
- self.changed_attributes = []
27
- end
28
-
29
- def write_changed_attribute(attr_name, attr_value) #:nodoc:
30
- (self.changed_attributes ||= []) << attr_name.to_s unless self.need_update_index?(attr_name) or self.send(attr_name) == attr_value
31
- write_attribute(attr_name.to_s, attr_value)
32
- end
33
- end
34
- end
35
- end
36
-