freelancing-god-thinking-sphinx 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -89,13 +89,13 @@ module ThinkingSphinx
89
89
  args.each do |columns|
90
90
  fields << Field.new(FauxColumn.coerce(columns), options)
91
91
 
92
- if fields.last.sortable
92
+ if fields.last.sortable || fields.last.faceted
93
93
  attributes << Attribute.new(
94
94
  fields.last.columns.collect { |col| col.clone },
95
95
  options.merge(
96
96
  :type => :string,
97
97
  :as => fields.last.unique_name.to_s.concat("_sort").to_sym
98
- )
98
+ ).except(:facet)
99
99
  )
100
100
  end
101
101
  end
@@ -352,6 +352,23 @@ module ThinkingSphinx
352
352
  end
353
353
  end
354
354
 
355
+ def facets(*args)
356
+ options = args.extract_options!.merge! :group_function => :attr
357
+
358
+ options[:class].sphinx_facets.inject({}) do |hash, facet|
359
+ facet_result = {}
360
+ options[:group_by] = facet.attribute_name
361
+
362
+ results = search *(args + [options])
363
+ results.each_with_groupby_and_count do |result, group, count|
364
+ facet_result[facet.value(result, group)] = count
365
+ end
366
+ hash[facet.name] = facet_result
367
+
368
+ hash
369
+ end
370
+ end
371
+
355
372
  private
356
373
 
357
374
  # This method handles the common search functionality, and returns both
@@ -230,7 +230,8 @@ describe "ThinkingSphinx::ActiveRecord" do
230
230
 
231
231
  it "should allow associations to other STI models" do
232
232
  Child.sphinx_indexes.last.link!
233
- sql = Child.sphinx_indexes.last.to_sql.gsub('$start', '0').gsub('$end', '100')
233
+ sql = Child.sphinx_indexes.last.to_riddle_for_core(0, 0).sql_query
234
+ sql.gsub!('$start', '0').gsub!('$end', '100')
234
235
  lambda { Child.connection.execute(sql) }.should_not raise_error(ActiveRecord::StatementInvalid)
235
236
  end
236
237
  end
@@ -0,0 +1,9 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe String do
4
+ describe "to_crc32 instance method" do
5
+ it "should return an integer" do
6
+ 'to_crc32'.to_crc32.should be_a_kind_of(Integer)
7
+ end
8
+ end
9
+ end
@@ -1,12 +1,12 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
3
  describe ThinkingSphinx::Index do
4
- describe "to_sql method" do
4
+ describe "generated sql_query" do
5
5
  it "should include explicit groupings if requested" do
6
6
  @index = ThinkingSphinx::Index.new(Person)
7
7
 
8
8
  @index.groupings << "custom_sql"
9
- @index.to_sql.should match(/GROUP BY.+custom_sql/)
9
+ @index.to_riddle_for_core(0, 0).sql_query.should match(/GROUP BY.+custom_sql/)
10
10
  end
11
11
  end
12
12
 
@@ -0,0 +1,48 @@
1
+ require 'rake/rdoctask'
2
+ require 'rake/gempackagetask'
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
+ require 'thinking_sphinx'
6
+
7
+ desc 'Generate documentation'
8
+ Rake::RDocTask.new(:rdoc) do |rdoc|
9
+ rdoc.rdoc_dir = 'rdoc'
10
+ rdoc.title = 'Thinking Sphinx - ActiveRecord Sphinx Plugin'
11
+ rdoc.options << '--line-numbers' << '--inline-source'
12
+ rdoc.rdoc_files.include('README')
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
15
+
16
+ spec = Gem::Specification.new do |s|
17
+ s.name = "thinking-sphinx"
18
+ s.version = ThinkingSphinx::Version::String
19
+ s.summary = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
20
+ s.description = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
21
+ s.author = "Pat Allan"
22
+ s.email = "pat@freelancing-gods.com"
23
+ s.homepage = "http://ts.freelancing-gods.com"
24
+ s.has_rdoc = true
25
+ s.rdoc_options << "--title" << "Thinking Sphinx -- Rails/Merb Sphinx Plugin" <<
26
+ "--line-numbers"
27
+ s.rubyforge_project = "thinking-sphinx"
28
+ s.test_files = FileList["spec/**/*_spec.rb"]
29
+ s.files = FileList[
30
+ "lib/**/*.rb",
31
+ "LICENCE",
32
+ "README",
33
+ "tasks/**/*.rb",
34
+ "tasks/**/*.rake",
35
+ "vendor/**/*"
36
+ ]
37
+ end
38
+
39
+ Rake::GemPackageTask.new(spec) do |p|
40
+ p.gem_spec = spec
41
+ p.need_tar = true
42
+ p.need_zip = true
43
+ end
44
+
45
+ desc "Build gemspec file"
46
+ task :build do
47
+ File.open('thinking-sphinx.gemspec', 'w') { |f| f.write spec.to_ruby }
48
+ end
data/tasks/testing.rb ADDED
@@ -0,0 +1,86 @@
1
+ require 'rubygems'
2
+ require 'spec/rake/spectask'
3
+ require 'cucumber/rake/task'
4
+
5
+ desc "Run the specs under spec"
6
+ Spec::Rake::SpecTask.new do |t|
7
+ t.spec_files = FileList['spec/**/*_spec.rb']
8
+ t.spec_opts << "-c"
9
+ end
10
+
11
+ desc "Run all feature-set configurations"
12
+ task :features do |t|
13
+ puts "rake features:mysql"
14
+ system "rake features:mysql"
15
+ puts "rake features:postgresql"
16
+ system "rake features:postgresql"
17
+ end
18
+
19
+ namespace :features do
20
+ def add_task(name, description)
21
+ Cucumber::Rake::Task.new(name, description) do |t|
22
+ t.cucumber_opts = "--format pretty"
23
+ t.step_pattern = [
24
+ "features/support/env",
25
+ "features/support/db/#{name}",
26
+ "features/support/db/active_record",
27
+ "features/support/post_database",
28
+ "features/step_definitions/**.rb"
29
+ ]
30
+ end
31
+ end
32
+
33
+ add_task :mysql, "Run feature-set against MySQL"
34
+ add_task :postgresql, "Run feature-set against PostgreSQL"
35
+ end
36
+
37
+ desc "Generate RCov reports"
38
+ Spec::Rake::SpecTask.new(:rcov) do |t|
39
+ t.libs << 'lib'
40
+ t.spec_files = FileList['spec/**/*_spec.rb']
41
+ t.rcov = true
42
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems', '--exclude', 'riddle']
43
+ end
44
+
45
+ namespace :rcov do
46
+ def add_task(name, description)
47
+ Cucumber::Rake::Task.new(name, description) do |t|
48
+ t.cucumber_opts = "--format pretty"
49
+ t.step_pattern = [
50
+ "features/support/env",
51
+ "features/support/db/#{name}",
52
+ "features/support/db/active_record",
53
+ "features/support/post_database",
54
+ "features/step_definitions/**.rb"
55
+ ]
56
+ t.rcov = true
57
+ t.rcov_opts = [
58
+ '--exclude', 'spec',
59
+ '--exclude', 'gems',
60
+ '--exclude', 'riddle',
61
+ '--exclude', 'features'
62
+ ]
63
+ end
64
+ end
65
+
66
+ add_task :mysql, "Run feature-set against MySQL with rcov"
67
+ add_task :postgresql, "Run feature-set against PostgreSQL with rcov"
68
+ end
69
+
70
+ desc "Build cucumber.yml file"
71
+ task :cucumber_defaults do
72
+ default_requires = %w(
73
+ --require features/support/env.rb
74
+ --require features/support/db/mysql.rb
75
+ --require features/support/db/active_record.rb
76
+ --require features/support/post_database.rb
77
+ ).join(" ")
78
+
79
+ step_definitions = FileList["features/step_definitions/**.rb"].collect { |path|
80
+ "--require #{path}"
81
+ }.join(" ")
82
+
83
+ File.open('cucumber.yml', 'w') { |f|
84
+ f.write "default: \"#{default_requires} #{step_definitions}\""
85
+ }
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freelancing-god-thinking-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-08 00:00:00 -08:00
12
+ date: 2009-01-17 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -33,6 +33,7 @@ files:
33
33
  - lib/thinking_sphinx/attribute.rb
34
34
  - lib/thinking_sphinx/collection.rb
35
35
  - lib/thinking_sphinx/configuration.rb
36
+ - lib/thinking_sphinx/core/string.rb
36
37
  - lib/thinking_sphinx/deltas/datetime_delta.rb
37
38
  - lib/thinking_sphinx/deltas/default_delta.rb
38
39
  - lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb
@@ -49,6 +50,8 @@ files:
49
50
  - lib/thinking_sphinx.rb
50
51
  - LICENCE
51
52
  - README
53
+ - tasks/distribution.rb
54
+ - tasks/testing.rb
52
55
  - tasks/thinking_sphinx_tasks.rb
53
56
  - tasks/thinking_sphinx_tasks.rake
54
57
  - vendor/after_commit
@@ -99,6 +102,7 @@ files:
99
102
  - spec/unit/thinking_sphinx/attribute_spec.rb
100
103
  - spec/unit/thinking_sphinx/collection_spec.rb
101
104
  - spec/unit/thinking_sphinx/configuration_spec.rb
105
+ - spec/unit/thinking_sphinx/core/string_spec.rb
102
106
  - spec/unit/thinking_sphinx/field_spec.rb
103
107
  - spec/unit/thinking_sphinx/index/builder_spec.rb
104
108
  - spec/unit/thinking_sphinx/index/faux_column_spec.rb
@@ -142,6 +146,7 @@ test_files:
142
146
  - spec/unit/thinking_sphinx/attribute_spec.rb
143
147
  - spec/unit/thinking_sphinx/collection_spec.rb
144
148
  - spec/unit/thinking_sphinx/configuration_spec.rb
149
+ - spec/unit/thinking_sphinx/core/string_spec.rb
145
150
  - spec/unit/thinking_sphinx/field_spec.rb
146
151
  - spec/unit/thinking_sphinx/index/builder_spec.rb
147
152
  - spec/unit/thinking_sphinx/index/faux_column_spec.rb
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'thinking_sphinx_tasks')
@@ -1,128 +0,0 @@
1
- require 'fileutils'
2
-
3
- namespace :thinking_sphinx do
4
- task :app_env do
5
- Rake::Task[:environment].invoke if defined?(RAILS_ROOT)
6
- Rake::Task[:merb_env].invoke if defined?(Merb)
7
- end
8
-
9
- desc "Stop if running, then start a Sphinx searchd daemon using Thinking Sphinx's settings"
10
- task :running_start => :app_env do
11
- Rake::Task["thinking_sphinx:stop"].invoke if sphinx_running?
12
- Rake::Task["thinking_sphinx:start"].invoke
13
- end
14
-
15
- desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
16
- task :start => :app_env do
17
- config = ThinkingSphinx::Configuration.instance
18
-
19
- FileUtils.mkdir_p config.searchd_file_path
20
- raise RuntimeError, "searchd is already running." if sphinx_running?
21
-
22
- Dir["#{config.searchd_file_path}/*.spl"].each { |file| File.delete(file) }
23
-
24
- cmd = "#{config.bin_path}searchd --config #{config.config_file}"
25
- puts cmd
26
- system cmd
27
-
28
- sleep(2)
29
-
30
- if sphinx_running?
31
- puts "Started successfully (pid #{sphinx_pid})."
32
- else
33
- puts "Failed to start searchd daemon. Check #{config.searchd_log_file}."
34
- end
35
- end
36
-
37
- desc "Stop Sphinx using Thinking Sphinx's settings"
38
- task :stop => :app_env do
39
- raise RuntimeError, "searchd is not running." unless sphinx_running?
40
- config = ThinkingSphinx::Configuration.instance
41
- pid = sphinx_pid
42
- system "searchd --stop --config #{config.config_file}"
43
- puts "Stopped search daemon (pid #{pid})."
44
- end
45
-
46
- desc "Restart Sphinx"
47
- task :restart => [:app_env, :stop, :start]
48
-
49
- desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
50
- task :configure => :app_env do
51
- config = ThinkingSphinx::Configuration.instance
52
- puts "Generating Configuration to #{config.config_file}"
53
- config.build
54
- end
55
-
56
- desc "Index data for Sphinx using Thinking Sphinx's settings"
57
- task :index => :app_env do
58
- ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
59
-
60
- config = ThinkingSphinx::Configuration.instance
61
- unless ENV["INDEX_ONLY"] == "true"
62
- puts "Generating Configuration to #{config.config_file}"
63
- config.build
64
- end
65
-
66
- FileUtils.mkdir_p config.searchd_file_path
67
- cmd = "#{config.bin_path}indexer --config #{config.config_file} --all"
68
- cmd << " --rotate" if sphinx_running?
69
- puts cmd
70
- system cmd
71
- end
72
-
73
- namespace :index do
74
- task :delta => :app_env do
75
- ThinkingSphinx.indexed_models.select { |model|
76
- model.constantize.sphinx_indexes.any? { |index| index.delta? }
77
- }.each do |model|
78
- model.constantize.sphinx_indexes.select { |index|
79
- index.delta? && index.delta_object.respond_to?(:delayed_index)
80
- }.each { |index|
81
- index.delta_object.delayed_index(index.model)
82
- }
83
- end
84
- end
85
- end
86
-
87
- desc "Process stored delta index requests"
88
- task :delayed_delta => :app_env do
89
- require 'delayed/worker'
90
-
91
- Delayed::Worker.new(
92
- :min_priority => ENV['MIN_PRIORITY'],
93
- :max_priority => ENV['MAX_PRIORITY']
94
- ).start
95
- end
96
- end
97
-
98
- namespace :ts do
99
- desc "Stop if running, then start a Sphinx searchd daemon using Thinking Sphinx's settings"
100
- task :run => "thinking_sphinx:running_start"
101
- desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
102
- task :start => "thinking_sphinx:start"
103
- desc "Stop Sphinx using Thinking Sphinx's settings"
104
- task :stop => "thinking_sphinx:stop"
105
- desc "Index data for Sphinx using Thinking Sphinx's settings"
106
- task :in => "thinking_sphinx:index"
107
- desc "Index data for Sphinx using Thinking Sphinx's settings"
108
- namespace :in do
109
- task :delta => "thinking_sphinx:index:delta"
110
- end
111
- task :index => "thinking_sphinx:index"
112
- desc "Restart Sphinx"
113
- task :restart => "thinking_sphinx:restart"
114
- desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
115
- task :conf => "thinking_sphinx:configure"
116
- desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
117
- task :config => "thinking_sphinx:configure"
118
- desc "Process stored delta index requests"
119
- task :dd => "thinking_sphinx:delayed_delta"
120
- end
121
-
122
- def sphinx_pid
123
- ThinkingSphinx.sphinx_pid
124
- end
125
-
126
- def sphinx_running?
127
- ThinkingSphinx.sphinx_running?
128
- end