sunspot 2.2.3 → 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c950bbbf13ef68316389d88a82029e32ebe70b05
4
- data.tar.gz: e5cb08d4d7f07f6297adc5a1adb794ba0555c39b
3
+ metadata.gz: 757abddaa2a6004ccb6f5a9b3dda71c672f80d0b
4
+ data.tar.gz: 0fb4c5b1b0212b8a70b71dacaea88daa6452c3a7
5
5
  SHA512:
6
- metadata.gz: 01a20d69d02178fdc65f7adfc2468ce9f598219c867740da7db764d4cb41a4e0cfc1a0c7a755bb341fb0d48125c14d980337699809526de53ac59cd144e1579b
7
- data.tar.gz: 8eb444cf535087bc1599509b35d21cfa59adf28714970dcc4c5cc901e38af9043df3f171dea7447f15cbdcc21c4dfce7a08ca81e56e9ca74b2cb5fe4485a92be
6
+ metadata.gz: ce0f840a319bf645f653529ec91b5738a9ea90327e274c78b07149faeed5650f6ea770680d5ea83899d1a547ddfbca8c19eb39f6b47856541ac9d67ea91a06a0
7
+ data.tar.gz: 615a3f2b08be30c2cc54bd9a204e3efde81a8f0a67af0fda9ec22e6b95b3b10a340bed9502dcdb6ff5d0c13c8f8687499c959ad8942d0b307ad6c26419670485
@@ -123,18 +123,19 @@ module Sunspot
123
123
  # configuration.
124
124
  #
125
125
  class Dynamic < Abstract
126
- attr_accessor :name, :type
126
+ attr_accessor :name, :type, :separator
127
127
 
128
128
  def initialize(name, type, options = {}, &block)
129
129
  super(name, options, &block)
130
130
  @type, @options = type, options
131
+ @separator = @options.delete(:separator) || ':'
131
132
  end
132
133
 
133
134
  #
134
135
  # Build a field based on the dynamic name given.
135
136
  #
136
137
  def build(dynamic_name)
137
- AttributeField.new("#{@name}:#{dynamic_name}", @type, @options.dup)
138
+ AttributeField.new([@name, dynamic_name].join(separator), @type, @options.dup)
138
139
  end
139
140
  #
140
141
  # This alias allows a DynamicFieldFactory to be used in place of a Setup
@@ -160,11 +160,13 @@ module Sunspot
160
160
  #
161
161
  def facet(name, dynamic_name = nil)
162
162
  if name
163
- if dynamic_name
164
- @facets_by_name[:"#{name}:#{dynamic_name}"]
165
- else
166
- @facets_by_name[name.to_sym]
167
- end
163
+ facet_name = if dynamic_name
164
+ separator = @setup.dynamic_field_factory(name).separator
165
+ [name, dynamic_name].join(separator)
166
+ else
167
+ name
168
+ end.to_sym
169
+ @facets_by_name[facet_name]
168
170
  end
169
171
  end
170
172
 
@@ -1,3 +1,3 @@
1
1
  module Sunspot
2
- VERSION = '2.2.3'
2
+ VERSION = '2.2.4'
3
3
  end
@@ -1,17 +1,17 @@
1
1
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
- describe 'dynamic fields' do
3
+ shared_examples 'dynamic fields' do
4
4
  before :each do
5
5
  Sunspot.remove_all
6
- @posts = Post.new(:custom_string => { :cuisine => 'Pizza' }),
7
- Post.new(:custom_string => { :cuisine => 'Greek' }),
8
- Post.new(:custom_string => { :cuisine => 'Greek' })
6
+ @posts = Post.new(field_name => { :cuisine => 'Pizza' }),
7
+ Post.new(field_name => { :cuisine => 'Greek' }),
8
+ Post.new(field_name => { :cuisine => 'Greek' })
9
9
  Sunspot.index!(@posts)
10
10
  end
11
11
 
12
12
  it 'should search for dynamic string field' do
13
13
  Sunspot.search(Post) do
14
- dynamic(:custom_string) do
14
+ dynamic(field_name) do
15
15
  with(:cuisine, 'Pizza')
16
16
  end
17
17
  end.results.should == [@posts.first]
@@ -20,20 +20,20 @@ describe 'dynamic fields' do
20
20
  describe 'faceting' do
21
21
  before :each do
22
22
  @search = Sunspot.search(Post) do
23
- dynamic :custom_string do
23
+ dynamic field_name do
24
24
  facet :cuisine
25
25
  end
26
26
  end
27
27
  end
28
28
 
29
29
  it 'should return value "value" with count 2' do
30
- row = @search.dynamic_facet(:custom_string, :cuisine).rows[0]
30
+ row = @search.dynamic_facet(field_name, :cuisine).rows[0]
31
31
  row.value.should == 'Greek'
32
32
  row.count.should == 2
33
33
  end
34
34
 
35
35
  it 'should return value "other" with count 1' do
36
- row = @search.dynamic_facet(:custom_string, :cuisine).rows[1]
36
+ row = @search.dynamic_facet(field_name, :cuisine).rows[1]
37
37
  row.value.should == 'Pizza'
38
38
  row.count.should == 1
39
39
  end
@@ -41,7 +41,7 @@ describe 'dynamic fields' do
41
41
 
42
42
  it 'should order by dynamic string field ascending' do
43
43
  Sunspot.search(Post) do
44
- dynamic :custom_string do
44
+ dynamic field_name do
45
45
  order_by :cuisine, :asc
46
46
  end
47
47
  end.results.last.should == @posts.first
@@ -49,9 +49,20 @@ describe 'dynamic fields' do
49
49
 
50
50
  it 'should order by dynamic string field descending' do
51
51
  Sunspot.search(Post) do
52
- dynamic :custom_string do
52
+ dynamic field_name do
53
53
  order_by :cuisine, :desc
54
54
  end
55
55
  end.results.first.should == @posts.first
56
56
  end
57
57
  end
58
+
59
+ describe "default separator" do
60
+ it_behaves_like "dynamic fields" do
61
+ let(:field_name) { :custom_string }
62
+ end
63
+ end
64
+ describe "custom separator" do
65
+ it_behaves_like "dynamic fields" do
66
+ let(:field_name) { :custom_underscored_string }
67
+ end
68
+ end
@@ -15,6 +15,10 @@ class Post < SuperClass
15
15
  @custom_string ||= {}
16
16
  end
17
17
 
18
+ def custom_underscored_string
19
+ @custom_underscored_string ||= {}
20
+ end
21
+
18
22
  def custom_fl
19
23
  @custom_fl ||= {}
20
24
  end
@@ -28,7 +32,7 @@ class Post < SuperClass
28
32
  end
29
33
 
30
34
  private
31
- attr_writer :category_ids, :custom_string, :custom_fl, :custom_time, :custom_boolean
35
+ attr_writer :category_ids, :custom_string, :custom_underscored_string, :custom_fl, :custom_time, :custom_boolean
32
36
  end
33
37
 
34
38
  Sunspot.setup(Post) do
@@ -59,6 +63,7 @@ Sunspot.setup(Post) do
59
63
  latlon(:coordinates_new) { coordinates }
60
64
 
61
65
  dynamic_string :custom_string, :stored => true
66
+ dynamic_string :custom_underscored_string, separator: '__'
62
67
  dynamic_float :custom_float, :multiple => true, :using => :custom_fl
63
68
  dynamic_integer :custom_integer do
64
69
  category_ids.inject({}) do |hash, category_id|
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: 2.2.3
4
+ version: 2.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -29,7 +29,7 @@ authors:
29
29
  autorequire:
30
30
  bindir: bin
31
31
  cert_chain: []
32
- date: 2015-12-15 00:00:00.000000000 Z
32
+ date: 2016-01-21 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rsolr