sunspot 0.10.8 → 0.10.9

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/README.rdoc CHANGED
@@ -107,13 +107,24 @@ to define your own. See Sunspot::Adapters for more information.
107
107
 
108
108
  See Sunspot.search for more information.
109
109
 
110
- === Get data from search:
111
-
112
- search.results
113
- search.total
114
- search.page
115
- search.per_page
116
- search.facet(:blog_id)
110
+ === Work with search results (Haml for readability):
111
+
112
+ .facets
113
+ ul.blog_facet
114
+ - @search.facet(:blog_id).rows.each do |row|
115
+ li.facet_row
116
+ = link_to(row.instance.name, params.merge(:blog_id => row.value))
117
+ %span.count== (#{row.count})
118
+ .page_info== Displaying page #{@search.page} of #{@search.per_page} out of #{@search.total} results
119
+ - @search.hits.each do |hit|
120
+ - post = hit.result
121
+ .search_result
122
+ %h3.title
123
+ = link_to(h(hit.stored(:title)), post_url(post))
124
+ - if hit.score
125
+ %span.relevance== (#{hit.score})
126
+ %p= hit.highlight(:description).format { |word| "<span class=\"highlight\">#{word}</span>" }
127
+ .pagination= will_paginate(search.hits)
117
128
 
118
129
  == About the API documentation
119
130
 
data/TODO CHANGED
@@ -1,7 +1,15 @@
1
+ <<<<<<< HEAD:TODO
1
2
  === 0.10.x ===
2
3
  * Can retrieve facets from search via string
3
4
  * Allow #latitude and #longitude as coordinate attributes
4
5
  * Allow use of #text_fields from inside disjunction
6
+ =======
7
+ === 1.0 ===
8
+ * Built-in session proxies; #thread_local_sessions! method
9
+ * Support 1.4, retaining 1.3 support if/as much as possible
10
+ * Working local + keyword search
11
+ * Facet filter exclusion
12
+ >>>>>>> d8e4337... Minor API & documentation improvements:TODO
5
13
 
6
14
  * Assumed inconsistency
7
15
  * Support all operations in batches. Make it smart.
data/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
- :minor: 10
3
- :patch: 8
4
2
  :major: 0
3
+ :minor: 10
4
+ :patch: 9
5
+ :build:
@@ -52,6 +52,14 @@ module Sunspot
52
52
  end || []
53
53
  end
54
54
 
55
+ #
56
+ # Return the first highlight found for a given field, or nil if there is
57
+ # none.
58
+ #
59
+ def highlight(field_name)
60
+ highlights(field_name).first
61
+ end
62
+
55
63
  #
56
64
  # Retrieve stored field value. For any attribute field configured with
57
65
  # :stored => true, the Hit object will contain the stored value for
@@ -78,6 +86,7 @@ module Sunspot
78
86
  end
79
87
  @instance
80
88
  end
89
+ alias_method :result, :instance
81
90
 
82
91
  def inspect #:nodoc:
83
92
  "#<Sunspot::Search::Hit:#{@class_name} #{@primary_key}>"
@@ -48,13 +48,7 @@ module Sunspot
48
48
  # WillPaginate::Collection or Array:: Instantiated result objects
49
49
  #
50
50
  def results
51
- @results ||= if @query.page && defined?(WillPaginate::Collection)
52
- WillPaginate::Collection.create(@query.page, @query.per_page, total) do |pager|
53
- pager.replace(hits.map { |hit| hit.instance })
54
- end
55
- else
56
- hits.map { |hit| hit.instance }
57
- end
51
+ @results ||= maybe_will_paginate(hits.map { |hit| hit.instance })
58
52
  end
59
53
 
60
54
  #
@@ -67,7 +61,12 @@ module Sunspot
67
61
  # Array:: Ordered collection of Hit objects
68
62
  #
69
63
  def hits
70
- @hits ||= solr_response['docs'].map { |doc| Hit.new(doc, highlights_for(doc), self) }
64
+ @hits ||=
65
+ maybe_will_paginate(
66
+ solr_response['docs'].map do |doc|
67
+ Hit.new(doc, highlights_for(doc), self)
68
+ end
69
+ )
71
70
  end
72
71
  alias_method :raw_results, :hits
73
72
 
@@ -165,9 +164,9 @@ module Sunspot
165
164
  end
166
165
  id_hit_hash.each_pair do |class_name, hits|
167
166
  ids = hits.map { |id, hit| hit.primary_key }
168
- data_accessor_for(Util.full_const_get(class_name)).load_all(ids).each do |instance|
169
- hit = id_hit_hash[class_name][Adapters::InstanceAdapter.adapt(instance).id.to_s]
170
- hit.instance = instance
167
+ data_accessor_for(Util.full_const_get(class_name)).load_all(ids).each do |result|
168
+ hit = id_hit_hash[class_name][Adapters::InstanceAdapter.adapt(result).id.to_s]
169
+ hit.instance = result
171
170
  end
172
171
  end
173
172
  end
@@ -207,6 +206,16 @@ module Sunspot
207
206
  @solr_result['highlighting'][doc['id']]
208
207
  end
209
208
  end
209
+
210
+ def maybe_will_paginate(collection)
211
+ if defined?(WillPaginate::Collection)
212
+ WillPaginate::Collection.create(@query.page, @query.per_page, total) do |pager|
213
+ pager.replace(collection)
214
+ end
215
+ else
216
+ collection
217
+ end
218
+ end
210
219
 
211
220
  # Clear out all the cached ivars so the search can be called again.
212
221
  def reset
@@ -21,23 +21,27 @@ describe 'search with highlighting results', :type => :search do
21
21
  @search.hits.last.should have(2).highlights(:body)
22
22
  end
23
23
 
24
+ it 'returns first highlight for a specified field' do
25
+ @search.hits.first.highlight(:title).format.should == 'one <em>two</em> three'
26
+ end
27
+
24
28
  it 'returns an empty array if a given field does not have a highlight' do
25
29
  @search.hits.first.highlights(:body).should == []
26
30
  end
27
31
 
28
- it 'should format hits with <em> by default' do
32
+ it 'formats hits with <em> by default' do
29
33
  highlight = @search.hits.first.highlights(:title).first.formatted
30
34
  highlight.should == 'one <em>two</em> three'
31
35
  end
32
36
 
33
- it 'should format hits with provided block' do
37
+ it 'formats hits with provided block' do
34
38
  highlight = @search.hits.first.highlights(:title).first.format do |word|
35
39
  "<i>#{word}</i>"
36
40
  end
37
41
  highlight.should == 'one <i>two</i> three'
38
42
  end
39
43
 
40
- it 'should handle multiple highlighted words' do
44
+ it 'handles multiple highlighted words' do
41
45
  highlight = @search.hits.last.highlights(:body).last.format do |word|
42
46
  "<b>#{word}</b>"
43
47
  end
@@ -12,6 +12,24 @@ describe 'hits', :type => :search do
12
12
  end.should == [['Post', post_1.id.to_s], ['Post', post_2.id.to_s]]
13
13
  end
14
14
 
15
+ if ENV['USE_WILL_PAGINATE']
16
+
17
+ it 'returns search total as attribute of hits' do
18
+ stub_results(Post.new, 4)
19
+ session.search(Post) do
20
+ paginate(:page => 1)
21
+ end.hits.total_entries.should == 4
22
+ end
23
+ else
24
+
25
+ it 'returns vanilla array of hits if WillPaginate is not available' do
26
+ stub_results(Post.new)
27
+ session.search(Post) do
28
+ paginate(:page => 1)
29
+ end.hits.should_not respond_to(:total_entries)
30
+ end
31
+ end
32
+
15
33
  it 'should return instance from hit' do
16
34
  posts = Array.new(2) { Post.new }
17
35
  stub_results(*posts)
data/tasks/gemspec.rake CHANGED
@@ -38,5 +38,5 @@ namespace :release do
38
38
  end
39
39
 
40
40
  desc "Release gem to RubyForge and GitHub"
41
- task :all => [:gemspec, :tag, :"rubyforge:release:gem", :"gemcutter:release"]
41
+ task :all => [:gemspec, :tag, :"gemcutter:release"]
42
42
  end
data/tasks/rdoc.rake CHANGED
@@ -1,4 +1,4 @@
1
- gem 'mislav-hanna'
1
+ gem 'hanna'
2
2
  require 'hanna/rdoctask'
3
3
  require 'jeweler'
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.8
4
+ version: 0.10.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2009-11-24 00:00:00 -05:00
21
+ date: 2010-01-10 00:00:00 -05:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -258,59 +258,59 @@ signing_key:
258
258
  specification_version: 3
259
259
  summary: Library for expressive, powerful interaction with the Solr search engine
260
260
  test_files:
261
- - spec/spec_helper.rb
262
- - spec/helpers/indexer_helper.rb
263
- - spec/helpers/search_helper.rb
264
261
  - spec/helpers/query_helper.rb
265
- - spec/integration/spec_helper.rb
266
- - spec/integration/local_search_spec.rb
267
- - spec/integration/faceting_spec.rb
268
- - spec/integration/scoped_search_spec.rb
269
- - spec/integration/highlighting_spec.rb
270
- - spec/integration/keyword_search_spec.rb
271
- - spec/integration/indexing_spec.rb
272
- - spec/integration/dynamic_fields_spec.rb
273
- - spec/integration/stored_fields_spec.rb
274
- - spec/integration/test_pagination.rb
275
- - spec/mocks/mock_record.rb
276
- - spec/mocks/blog.rb
277
- - spec/mocks/adapters.rb
278
- - spec/mocks/mock_adapter.rb
279
- - spec/mocks/user.rb
280
- - spec/mocks/photo.rb
281
- - spec/mocks/post.rb
282
- - spec/mocks/comment.rb
283
- - spec/mocks/super_class.rb
284
- - spec/mocks/connection.rb
285
- - spec/api/spec_helper.rb
262
+ - spec/helpers/search_helper.rb
263
+ - spec/helpers/indexer_helper.rb
264
+ - spec/api/adapters_spec.rb
265
+ - spec/api/query/text_field_scoping_spec.rb
266
+ - spec/api/query/fulltext_spec.rb
267
+ - spec/api/query/adjust_params_spec.rb
268
+ - spec/api/query/dynamic_fields_spec.rb
269
+ - spec/api/query/highlighting_spec.rb
270
+ - spec/api/query/ordering_pagination_spec.rb
271
+ - spec/api/query/spec_helper.rb
272
+ - spec/api/query/local_spec.rb
273
+ - spec/api/query/types_spec.rb
274
+ - spec/api/query/scope_spec.rb
275
+ - spec/api/query/faceting_spec.rb
276
+ - spec/api/query/dsl_spec.rb
277
+ - spec/api/query/connectives_spec.rb
286
278
  - spec/api/session_spec.rb
287
- - spec/api/indexer/spec_helper.rb
288
- - spec/api/indexer/fixed_fields_spec.rb
289
- - spec/api/indexer/attributes_spec.rb
290
- - spec/api/indexer/dynamic_fields_spec.rb
279
+ - spec/api/spec_helper.rb
291
280
  - spec/api/indexer/fulltext_spec.rb
281
+ - spec/api/indexer/dynamic_fields_spec.rb
292
282
  - spec/api/indexer/removal_spec.rb
283
+ - spec/api/indexer/spec_helper.rb
284
+ - spec/api/indexer/fixed_fields_spec.rb
293
285
  - spec/api/indexer/batch_spec.rb
294
- - spec/api/search/spec_helper.rb
286
+ - spec/api/indexer/attributes_spec.rb
287
+ - spec/api/indexer_spec.rb
295
288
  - spec/api/search/hits_spec.rb
296
- - spec/api/search/faceting_spec.rb
297
- - spec/api/search/highlighting_spec.rb
298
289
  - spec/api/search/dynamic_fields_spec.rb
299
290
  - spec/api/search/search_spec.rb
300
291
  - spec/api/search/results_spec.rb
301
- - spec/api/adapters_spec.rb
302
- - spec/api/query/dsl_spec.rb
303
- - spec/api/query/spec_helper.rb
304
- - spec/api/query/faceting_spec.rb
305
- - spec/api/query/connectives_spec.rb
306
- - spec/api/query/adjust_params_spec.rb
307
- - spec/api/query/local_spec.rb
308
- - spec/api/query/highlighting_spec.rb
309
- - spec/api/query/ordering_pagination_spec.rb
310
- - spec/api/query/dynamic_fields_spec.rb
311
- - spec/api/query/types_spec.rb
312
- - spec/api/query/scope_spec.rb
313
- - spec/api/query/text_field_scoping_spec.rb
314
- - spec/api/query/fulltext_spec.rb
292
+ - spec/api/search/highlighting_spec.rb
293
+ - spec/api/search/spec_helper.rb
294
+ - spec/api/search/faceting_spec.rb
315
295
  - spec/api/sunspot_spec.rb
316
- - spec/api/indexer_spec.rb
296
+ - spec/mocks/connection.rb
297
+ - spec/mocks/comment.rb
298
+ - spec/mocks/photo.rb
299
+ - spec/mocks/post.rb
300
+ - spec/mocks/super_class.rb
301
+ - spec/mocks/blog.rb
302
+ - spec/mocks/adapters.rb
303
+ - spec/mocks/mock_adapter.rb
304
+ - spec/mocks/mock_record.rb
305
+ - spec/mocks/user.rb
306
+ - spec/integration/dynamic_fields_spec.rb
307
+ - spec/integration/stored_fields_spec.rb
308
+ - spec/integration/highlighting_spec.rb
309
+ - spec/integration/local_search_spec.rb
310
+ - spec/integration/spec_helper.rb
311
+ - spec/integration/indexing_spec.rb
312
+ - spec/integration/keyword_search_spec.rb
313
+ - spec/integration/test_pagination.rb
314
+ - spec/integration/faceting_spec.rb
315
+ - spec/integration/scoped_search_spec.rb
316
+ - spec/spec_helper.rb