tanker 1.1.4 → 1.1.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/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ branches:
2
+ only:
3
+ - master
4
+ rvm:
5
+ - 1.8.7 # (current default)
6
+ - 1.9.2
7
+
data/Gemfile CHANGED
@@ -6,7 +6,8 @@ group :test do
6
6
  gem 'rspec', '>= 2.5.0'
7
7
  gem 'activerecord', '>= 3.0.7'
8
8
  gem 'sqlite3'
9
- #gem 'ruby-debug19'
9
+ gem 'rcov'
10
+ gem 'ruby-debug19'
10
11
  end
11
12
 
12
13
  group :development do
data/README.rdoc CHANGED
@@ -1,3 +1,5 @@
1
+ {<img src="https://secure.travis-ci.org/kidpollo/tanker.png" />}[https://secure.travis-ci.org/kidpollo/tanker.png]
2
+
1
3
  = Tanker - IndexTank integration to your favorite orm
2
4
 
3
5
  IndexTank is a great search indexing service, this gem tries to make
@@ -150,9 +152,6 @@ Paginate Results
150
152
  <%= will_paginate @topics %> for WillPaginate
151
153
  <%= paginate @topics %> for Kaminari
152
154
 
153
- Disable pagination of search results
154
-
155
- @topics = Topic.search_tank('keyword', :paginate => false)
156
155
 
157
156
  == Fetching attributes and snippets
158
157
 
data/Rakefile CHANGED
@@ -21,11 +21,25 @@ end
21
21
  require "rspec/core/rake_task"
22
22
  # RSpec 2.0
23
23
  RSpec::Core::RakeTask.new(:spec) do |spec|
24
- spec.pattern = 'spec/*_spec.rb'
24
+ spec.pattern = 'spec/{tanker,utilities}_spec.rb'
25
25
  spec.rspec_opts = ['--backtrace']
26
26
  end
27
27
  task :default => :spec
28
28
 
29
+ desc "Generate code coverage"
30
+ RSpec::Core::RakeTask.new(:coverage) do |t|
31
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
32
+ t.rcov = true
33
+ t.rcov_opts = ['--exclude', 'spec']
34
+ end
35
+
36
+ desc "Run Integration Specs"
37
+ RSpec::Core::RakeTask.new(:integration) do |t|
38
+ t.pattern = "spec/integration_spec.rb" # don't need this, it's default.
39
+ t.rcov = true
40
+ t.rcov_opts = ['--exclude', 'spec']
41
+ end
42
+
29
43
  require 'rake/rdoctask'
30
44
  Rake::RDocTask.new do |rdoc|
31
45
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.4
1
+ 1.1.5
data/lib/tanker.rb CHANGED
@@ -61,7 +61,7 @@ module Tanker
61
61
  records.first.class.tanker_index.add_documents(data)
62
62
  end
63
63
 
64
- def search(models, query, options = {})
64
+ def search_results(models, query, options = {})
65
65
  ids = []
66
66
  models = [models].flatten.uniq
67
67
  index = models.first.tanker_index
@@ -111,6 +111,41 @@ module Tanker
111
111
  query = "(#{search_on_fields}:(#{query.to_s}) OR __any:(#{query.to_s})) __type:(#{models.map(&:name).map {|name| "\"#{name.split('::').join(' ')}\"" }.join(' OR ')})"
112
112
  options = { :start => paginate[:per_page] * (paginate[:page] - 1), :len => paginate[:per_page] }.merge(options) if paginate
113
113
  results = index.search(query, options)
114
+ SearchState.new(results, fetch, snippets, paginate)
115
+ end
116
+
117
+ class SearchState
118
+ def initialize(results, fetch, snippets, paginate)
119
+ @results = results
120
+ @fetch = fetch
121
+ @snippets = snippets
122
+ @paginate = paginate
123
+ end
124
+ def results
125
+ @results
126
+ end
127
+ def fetch
128
+ @fetch
129
+ end
130
+ def snippets
131
+ @snippets
132
+ end
133
+ def paginate
134
+ @paginate
135
+ end
136
+ end
137
+
138
+ def search(models, query, options = {})
139
+ search_state = search_results(models, query, options)
140
+ instantiate(search_state)
141
+ end
142
+
143
+ def instantiate(search_state)
144
+ results = search_state.results
145
+ fetch = search_state.fetch
146
+ snippets = search_state.snippets
147
+ paginate = search_state.paginate
148
+
114
149
  categories = results['facets'] if results.has_key?('facets')
115
150
 
116
151
  instantiated_results = if (fetch || snippets)
@@ -195,7 +230,7 @@ module Tanker
195
230
 
196
231
  def extract_setup_paginate_options(options, defaults)
197
232
  # extract
198
- paginate_options = if options[:paginate] or options[:paginate] === false
233
+ paginate_options = if options[:paginate]
199
234
  options.delete(:paginate)
200
235
  else
201
236
  { :page => options.delete(:page), :per_page => options.delete(:per_page) }
@@ -78,6 +78,8 @@ describe 'An imaginary store' do
78
78
  @iphone = Product.create(:name => 'iphone', :href => "apple", :tags => ['awesome', 'poor reception'],
79
79
  :description => 'Puts even more features at your fingertips')
80
80
 
81
+ 100.times do ; Product.create(:name => 'crapoola', :href => "crappy", :tags => ['crappy']) ; end
82
+
81
83
  @products_in_database = Product.all
82
84
 
83
85
  Product.tanker_reindex
@@ -86,6 +88,13 @@ describe 'An imaginary store' do
86
88
  Company.tanker_reindex
87
89
  end
88
90
 
91
+ describe 'pagination' do
92
+ it 'should dilplay total results correctly' do
93
+ results = Product.search_tank('crapoola')
94
+ results.total_entries.should == 100
95
+ end
96
+ end
97
+
89
98
  describe 'basic searching' do
90
99
 
91
100
  it 'should find all amazon products' do
data/spec/tanker_spec.rb CHANGED
@@ -355,34 +355,6 @@ describe Tanker do
355
355
  Foo::Bar.search_tank('bar')
356
356
  end
357
357
 
358
- it 'should be able to perform a search without pagination' do
359
- Person.tanker_index.should_receive(:search).and_return(
360
- {
361
- "matches" => 2,
362
- "results" => [{
363
- "docid" => 'Person 1',
364
- "name" => 'pedro',
365
- "__type" => 'Person',
366
- "__id" => '1'
367
- },{
368
- "docid" => 'Person 2',
369
- "name" => 'jaun',
370
- "__type" => 'Person',
371
- "__id" => '2'
372
- }],
373
- "search_time" => 1
374
- }
375
- )
376
-
377
- Person.should_receive(:find_all_by_id).with(['1', '2']).and_return(
378
- [Person.new(:id => 1), Person.new(:id => 2)]
379
- )
380
-
381
- collection = Person.search_tank('hey!', :paginate => false)
382
- collection.class.should == Array
383
- collection.size.should == 2
384
- end
385
-
386
358
  it 'should be able to perform a search with pagination settings in :paginate option' do
387
359
  Person.tanker_index.should_receive(:search).and_return(
388
360
  {
data/tanker.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tanker}
8
- s.version = "1.1.4"
8
+ s.version = "1.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Francisco Viramontes}, %q{Jack Danger Canty}]
12
- s.date = %q{2011-08-31}
12
+ s.date = %q{2011-09-23}
13
13
  s.description = %q{IndexTank is a great search indexing service, this gem tries to make any orm keep in sync with indextank with ease}
14
14
  s.email = %q{kidpollo@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".travis.yml",
21
22
  "Gemfile",
22
23
  "LICENSE",
23
24
  "README.rdoc",
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tanker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.4
5
+ version: 1.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Francisco Viramontes
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-08-31 00:00:00 Z
14
+ date: 2011-09-23 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -68,6 +68,7 @@ extra_rdoc_files:
68
68
  - README.rdoc
69
69
  files:
70
70
  - .document
71
+ - .travis.yml
71
72
  - Gemfile
72
73
  - LICENSE
73
74
  - README.rdoc