sunspot_plus 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -7
- data/lib/sunspot_plus.rb +6 -1
- data/lib/sunspot_plus/dsl/fields.rb +12 -0
- data/lib/sunspot_plus/dsl/query/case_insensitive_sort.rb +17 -0
- data/lib/sunspot_plus/type/case_insensitive_sort_type.rb +43 -0
- data/spec/spec_helper.rb +8 -4
- data/spec/sunspot/types/case_insensitive_sort_type_spec.rb +101 -0
- metadata +72 -19
data/README.rdoc
CHANGED
@@ -8,16 +8,17 @@ Particularly useful for using 3rd party or remote solr servers over http as ofte
|
|
8
8
|
|
9
9
|
* Use rails initializer to create the sunspot session
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
require 'sunspot_rails'
|
12
|
+
# set the session to the delayed_job handler - this will send all model CRUD reindexing to delayed_job
|
13
|
+
Sunspot.session = Sunspot::SessionProxy::DelayedJobSessionProxy.new(Sunspot.session)
|
14
14
|
|
15
15
|
* Define your searchable blocks as usual in ActiveRecord models.
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
class Model < ActiveRecord::Base
|
18
|
+
searchable do
|
19
|
+
text :name
|
20
|
+
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
23
|
== Note on Patches/Pull Requests
|
23
24
|
|
data/lib/sunspot_plus.rb
CHANGED
@@ -2,4 +2,9 @@ require 'sunspot'
|
|
2
2
|
require 'sunspot_plus/session_proxy/delayed_job_session_proxy'
|
3
3
|
require 'sunspot_plus/session_proxy/silent_fail_session_proxy'
|
4
4
|
require 'sunspot_plus/session_proxy/delayed_job/indexing_job'
|
5
|
-
require 'sunspot_plus/session_proxy/delayed_job/safe_configuration'
|
5
|
+
require 'sunspot_plus/session_proxy/delayed_job/safe_configuration'
|
6
|
+
require 'sunspot_plus/type/case_insensitive_sort_type'
|
7
|
+
require 'sunspot_plus/dsl/fields'
|
8
|
+
require 'sunspot_plus/dsl/query/case_insensitive_sort'
|
9
|
+
|
10
|
+
Sunspot::DSL::FieldQuery.extend SunspotPlus::DSL::Query::CaseInsensitiveSort
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Sunspot
|
2
|
+
module DSL
|
3
|
+
class Fields
|
4
|
+
# NOTE : I want to call case_insensitive_sort using method missing but with adjusted name
|
5
|
+
# Could use adjust_solr_params but not sure about this method.
|
6
|
+
def sort_fields(*names, &block)
|
7
|
+
options = names.pop if names.last.is_a?(Hash)
|
8
|
+
names.each{|name| case_insensitive_sort(Sunspot::Type::CaseInsensitiveSortType.instance.field_name(name), options, &block)}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SunspotPlus
|
2
|
+
module DSL
|
3
|
+
module Query
|
4
|
+
module CaseInsensitiveSort
|
5
|
+
def self.extended(base)
|
6
|
+
base.send(:include, InstanceMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
def ci_order_by(field_name, direction = nil)
|
11
|
+
order_by(Sunspot::Type::CaseInsensitiveSortType.instance.field_name(field_name), direction)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Sunspot
|
2
|
+
module Type
|
3
|
+
#
|
4
|
+
# The CaseInsensitiveSort type represents string data optimised for case insensitve search.
|
5
|
+
#
|
6
|
+
class CaseInsensitiveSortType < StringType
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def pattern
|
10
|
+
@@pattern
|
11
|
+
end
|
12
|
+
|
13
|
+
def pattern=(value)
|
14
|
+
@@pattern=value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
self.pattern = :downcase
|
19
|
+
|
20
|
+
def pattern
|
21
|
+
self.class.pattern
|
22
|
+
end
|
23
|
+
|
24
|
+
def indexed_name(name) #:nodoc:
|
25
|
+
"sort_#{name}_s"
|
26
|
+
end
|
27
|
+
|
28
|
+
def field_name(name)
|
29
|
+
"case_insensitive_sort_#{name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_indexed(value) #:nodoc:
|
33
|
+
if value
|
34
|
+
if pattern.is_a?(Symbol)
|
35
|
+
value.to_s.send(pattern)
|
36
|
+
elsif pattern.is_a?(Proc)
|
37
|
+
pattern.call(value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,12 +2,16 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'rubygems'
|
4
4
|
require 'sunspot'
|
5
|
+
require 'sunspot_matchers'
|
5
6
|
require 'sunspot_plus'
|
6
7
|
require 'sunspot/session_proxy/abstract_session_proxy'
|
7
|
-
require '
|
8
|
-
require 'spec/autorun'
|
8
|
+
require 'rspec'
|
9
9
|
require 'helpers/delayed_job_stub'
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.before do
|
13
|
+
Sunspot.session = SunspotMatchers::SunspotSessionSpy.new(Sunspot.session)
|
14
|
+
end
|
15
|
+
config.include SunspotMatchers
|
13
16
|
end
|
17
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
class SomethingToIndex
|
4
|
+
def name
|
5
|
+
"something"
|
6
|
+
end
|
7
|
+
|
8
|
+
def description
|
9
|
+
"description"
|
10
|
+
end
|
11
|
+
|
12
|
+
def another
|
13
|
+
"another"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Sunspot::Type::CaseInsensitiveSortType do
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
@sort_type = Sunspot::Type::CaseInsensitiveSortType.instance
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have an indexed name" do
|
24
|
+
@sort_type.indexed_name(:test).should == "sort_test_s"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should convert a field attribute into a case insensitive field name" do
|
28
|
+
@sort_type.field_name(:test).should == "case_insensitive_sort_test"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should make the value lowercase" do
|
32
|
+
@sort_type.to_indexed("This is a sort term that needs to be Case Insensitive").should == "this is a sort term that needs to be case insensitive"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should case the value to a string" do
|
36
|
+
@sort_type.cast("string").should == "string"
|
37
|
+
@sort_type.cast("sting").should be_a(String)
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "if i want to defined another pattern" do
|
41
|
+
before(:each) do
|
42
|
+
Sunspot::Type::CaseInsensitiveSortType.pattern = :upcase
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should use upcase to transform the value" do
|
46
|
+
Sunspot::Type::CaseInsensitiveSortType.instance.pattern.should == :upcase
|
47
|
+
@sort_type.to_indexed("This is a sort term that needs to be Case Insensitive").should == "THIS IS A SORT TERM THAT NEEDS TO BE CASE INSENSITIVE"
|
48
|
+
end
|
49
|
+
|
50
|
+
context "using a proc" do
|
51
|
+
before(:each) do
|
52
|
+
Sunspot::Type::CaseInsensitiveSortType.pattern = Proc.new{|value| value << "999"}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should get rid of an and and the and upcase" do
|
56
|
+
Sunspot::Type::CaseInsensitiveSortType.instance.pattern.should be_a(Proc)
|
57
|
+
@sort_type.to_indexed("Please call ").should == "Please call 999"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "using the type" do
|
63
|
+
before(:each) do
|
64
|
+
Sunspot.setup(SomethingToIndex) do
|
65
|
+
string :name
|
66
|
+
sort_fields :name
|
67
|
+
sort_fields :description, :another
|
68
|
+
end
|
69
|
+
@something = SomethingToIndex.new
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should index something_to_index with sort field" do
|
73
|
+
Sunspot.search(SomethingToIndex) do
|
74
|
+
keywords "something"
|
75
|
+
order_by((:case_insensitive_sort_name))
|
76
|
+
end
|
77
|
+
Sunspot.session.should have_search_params(:order_by, :case_insensitive_sort_name, :asc)
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "the ci_order method" do
|
81
|
+
it "should add a new ci_order_by method" do
|
82
|
+
Sunspot.search(SomethingToIndex) do
|
83
|
+
keywords "bobbins"
|
84
|
+
ci_order_by(:name)
|
85
|
+
end
|
86
|
+
Sunspot.session.should have_search_params(:order_by, :case_insensitive_sort_name, :asc)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should allow the direction to be changed" do
|
90
|
+
Sunspot.search(SomethingToIndex) do
|
91
|
+
keywords "bobbins"
|
92
|
+
ci_order_by(:description, :desc)
|
93
|
+
end
|
94
|
+
Sunspot.session.should have_search_params(:order_by, :case_insensitive_sort_description, :desc)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Louis Gillies
|
@@ -15,13 +15,44 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-04 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
23
|
-
prerelease: false
|
22
|
+
name: rspec
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
version: 2.3.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: yard
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 7
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 6
|
48
|
+
- 0
|
49
|
+
version: 0.6.0
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: bundler
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
25
56
|
none: false
|
26
57
|
requirements:
|
27
58
|
- - ">="
|
@@ -30,12 +61,28 @@ dependencies:
|
|
30
61
|
segments:
|
31
62
|
- 0
|
32
63
|
version: "0"
|
33
|
-
type: :
|
34
|
-
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: *id003
|
35
67
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
68
|
+
name: jeweler
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 7
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 5
|
78
|
+
- 2
|
79
|
+
version: 1.5.2
|
80
|
+
type: :development
|
37
81
|
prerelease: false
|
38
|
-
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rcov
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
39
86
|
none: false
|
40
87
|
requirements:
|
41
88
|
- - ">="
|
@@ -44,12 +91,12 @@ dependencies:
|
|
44
91
|
segments:
|
45
92
|
- 0
|
46
93
|
version: "0"
|
47
|
-
type: :
|
48
|
-
|
94
|
+
type: :development
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: *id005
|
49
97
|
- !ruby/object:Gem::Dependency
|
50
98
|
name: rspec
|
51
|
-
|
52
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
99
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
53
100
|
none: false
|
54
101
|
requirements:
|
55
102
|
- - "="
|
@@ -61,11 +108,11 @@ dependencies:
|
|
61
108
|
- 0
|
62
109
|
version: 1.3.0
|
63
110
|
type: :development
|
64
|
-
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *id006
|
65
113
|
- !ruby/object:Gem::Dependency
|
66
114
|
name: yard
|
67
|
-
|
68
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
115
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
69
116
|
none: false
|
70
117
|
requirements:
|
71
118
|
- - ">="
|
@@ -75,8 +122,9 @@ dependencies:
|
|
75
122
|
- 0
|
76
123
|
version: "0"
|
77
124
|
type: :development
|
78
|
-
|
79
|
-
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: *id007
|
127
|
+
description: "A library of extensions for outoftime's sunspot gem for solr indexing server. Using the session adapter design pattern to add support for:\n 1) delayed_job to move indexing commits out of process.\n Support for case insensitive sort fields by creating indexed copy of fields transformed for sort.\n "
|
80
128
|
email: louisgillies@yahoo.co.uk
|
81
129
|
executables: []
|
82
130
|
|
@@ -87,10 +135,13 @@ extra_rdoc_files:
|
|
87
135
|
- README.rdoc
|
88
136
|
files:
|
89
137
|
- lib/sunspot_plus.rb
|
138
|
+
- lib/sunspot_plus/dsl/fields.rb
|
139
|
+
- lib/sunspot_plus/dsl/query/case_insensitive_sort.rb
|
90
140
|
- lib/sunspot_plus/session_proxy/delayed_job/indexing_job.rb
|
91
141
|
- lib/sunspot_plus/session_proxy/delayed_job/safe_configuration.rb
|
92
142
|
- lib/sunspot_plus/session_proxy/delayed_job_session_proxy.rb
|
93
143
|
- lib/sunspot_plus/session_proxy/silent_fail_session_proxy.rb
|
144
|
+
- lib/sunspot_plus/type/case_insensitive_sort_type.rb
|
94
145
|
- LICENSE
|
95
146
|
- README.rdoc
|
96
147
|
- spec/helpers/delayed_job_stub.rb
|
@@ -98,6 +149,7 @@ files:
|
|
98
149
|
- spec/sunspot/session_proxy/delayed_job/safe_configuration_spec.rb
|
99
150
|
- spec/sunspot/session_proxy/delayed_job_session_proxy_spec.rb
|
100
151
|
- spec/sunspot/session_proxy/spec_helper.rb
|
152
|
+
- spec/sunspot/types/case_insensitive_sort_type_spec.rb
|
101
153
|
- spec/sunspot_plus_spec.rb
|
102
154
|
has_rdoc: true
|
103
155
|
homepage: http://github.com/playgood/sunspot_plus
|
@@ -139,4 +191,5 @@ test_files:
|
|
139
191
|
- spec/sunspot/session_proxy/delayed_job/safe_configuration_spec.rb
|
140
192
|
- spec/sunspot/session_proxy/delayed_job_session_proxy_spec.rb
|
141
193
|
- spec/sunspot/session_proxy/spec_helper.rb
|
194
|
+
- spec/sunspot/types/case_insensitive_sort_type_spec.rb
|
142
195
|
- spec/sunspot_plus_spec.rb
|