tanning_bed 0.1.1

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.
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ vendor/solr/solr/data/*
3
+ vendor/solr/logs/*
4
+ !vendor/solr/logs/.keep
5
+ vendor/solr/tmp
6
+ spec/tmp/*
@@ -0,0 +1,24 @@
1
+ == 0.0.8 / 2008-12-31
2
+
3
+ * Version bump
4
+
5
+ == 0.0.7 / 2008-12-22
6
+
7
+ * Better solr_reindex method. Now clears all previously indexed items first
8
+
9
+ == 0.0.6 / 2008-12-22
10
+
11
+ * Solid exception handling with new on_solr_exception hook
12
+
13
+ == 0.0.5 / 2008-12-21
14
+
15
+ * Minor updates and fixes
16
+ * Easier to set sorl_connection
17
+
18
+ == 0.0.3 / 2008-12-16
19
+
20
+ * Added solr_reindex and solr_load class methods
21
+
22
+ == 0.0.2 / 2008-12-15
23
+
24
+ * Added Mr Bones rake tasks and a better gemspec
@@ -0,0 +1,156 @@
1
+ .gitignore
2
+ History.txt
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/tanning_bed.rb
7
+ spec/fixtures/burnt_model.rb
8
+ spec/fixtures/tanning_model.rb
9
+ spec/spec_helper.rb
10
+ spec/tanning_bed_spec.rb
11
+ tanning_bed.gemspec
12
+ tasks/ann.rake
13
+ tasks/bones.rake
14
+ tasks/gem.rake
15
+ tasks/git.rake
16
+ tasks/manifest.rake
17
+ tasks/notes.rake
18
+ tasks/post_load.rake
19
+ tasks/rdoc.rake
20
+ tasks/rubyforge.rake
21
+ tasks/setup.rb
22
+ tasks/solr.rake
23
+ tasks/solr.rb
24
+ tasks/spec.rake
25
+ tasks/svn.rake
26
+ tasks/test.rake
27
+ vendor/solr-ruby/lib/solr.rb
28
+ vendor/solr-ruby/lib/solr/connection.rb
29
+ vendor/solr-ruby/lib/solr/document.rb
30
+ vendor/solr-ruby/lib/solr/exception.rb
31
+ vendor/solr-ruby/lib/solr/field.rb
32
+ vendor/solr-ruby/lib/solr/importer.rb
33
+ vendor/solr-ruby/lib/solr/importer/array_mapper.rb
34
+ vendor/solr-ruby/lib/solr/importer/delimited_file_source.rb
35
+ vendor/solr-ruby/lib/solr/importer/hpricot_mapper.rb
36
+ vendor/solr-ruby/lib/solr/importer/mapper.rb
37
+ vendor/solr-ruby/lib/solr/importer/solr_source.rb
38
+ vendor/solr-ruby/lib/solr/importer/xpath_mapper.rb
39
+ vendor/solr-ruby/lib/solr/indexer.rb
40
+ vendor/solr-ruby/lib/solr/request.rb
41
+ vendor/solr-ruby/lib/solr/request/add_document.rb
42
+ vendor/solr-ruby/lib/solr/request/base.rb
43
+ vendor/solr-ruby/lib/solr/request/commit.rb
44
+ vendor/solr-ruby/lib/solr/request/delete.rb
45
+ vendor/solr-ruby/lib/solr/request/dismax.rb
46
+ vendor/solr-ruby/lib/solr/request/index_info.rb
47
+ vendor/solr-ruby/lib/solr/request/modify_document.rb
48
+ vendor/solr-ruby/lib/solr/request/optimize.rb
49
+ vendor/solr-ruby/lib/solr/request/ping.rb
50
+ vendor/solr-ruby/lib/solr/request/select.rb
51
+ vendor/solr-ruby/lib/solr/request/spellcheck.rb
52
+ vendor/solr-ruby/lib/solr/request/standard.rb
53
+ vendor/solr-ruby/lib/solr/request/update.rb
54
+ vendor/solr-ruby/lib/solr/response.rb
55
+ vendor/solr-ruby/lib/solr/response/add_document.rb
56
+ vendor/solr-ruby/lib/solr/response/base.rb
57
+ vendor/solr-ruby/lib/solr/response/commit.rb
58
+ vendor/solr-ruby/lib/solr/response/delete.rb
59
+ vendor/solr-ruby/lib/solr/response/dismax.rb
60
+ vendor/solr-ruby/lib/solr/response/index_info.rb
61
+ vendor/solr-ruby/lib/solr/response/modify_document.rb
62
+ vendor/solr-ruby/lib/solr/response/optimize.rb
63
+ vendor/solr-ruby/lib/solr/response/ping.rb
64
+ vendor/solr-ruby/lib/solr/response/ruby.rb
65
+ vendor/solr-ruby/lib/solr/response/select.rb
66
+ vendor/solr-ruby/lib/solr/response/spellcheck.rb
67
+ vendor/solr-ruby/lib/solr/response/standard.rb
68
+ vendor/solr-ruby/lib/solr/response/xml.rb
69
+ vendor/solr-ruby/lib/solr/solrtasks.rb
70
+ vendor/solr-ruby/lib/solr/util.rb
71
+ vendor/solr-ruby/lib/solr/xml.rb
72
+ vendor/solr-ruby/test/unit/add_document_test.rb
73
+ vendor/solr-ruby/test/unit/array_mapper_test.rb
74
+ vendor/solr-ruby/test/unit/changes_yaml_test.rb
75
+ vendor/solr-ruby/test/unit/commit_test.rb
76
+ vendor/solr-ruby/test/unit/connection_test.rb
77
+ vendor/solr-ruby/test/unit/data_mapper_test.rb
78
+ vendor/solr-ruby/test/unit/delete_test.rb
79
+ vendor/solr-ruby/test/unit/delimited_file_source_test.rb
80
+ vendor/solr-ruby/test/unit/dismax_request_test.rb
81
+ vendor/solr-ruby/test/unit/document_test.rb
82
+ vendor/solr-ruby/test/unit/field_test.rb
83
+ vendor/solr-ruby/test/unit/hpricot_mapper_test.rb
84
+ vendor/solr-ruby/test/unit/hpricot_test_file.xml
85
+ vendor/solr-ruby/test/unit/indexer_test.rb
86
+ vendor/solr-ruby/test/unit/modify_document_test.rb
87
+ vendor/solr-ruby/test/unit/ping_test.rb
88
+ vendor/solr-ruby/test/unit/request_test.rb
89
+ vendor/solr-ruby/test/unit/response_test.rb
90
+ vendor/solr-ruby/test/unit/select_test.rb
91
+ vendor/solr-ruby/test/unit/solr_mock_base.rb
92
+ vendor/solr-ruby/test/unit/spellcheck_response_test.rb
93
+ vendor/solr-ruby/test/unit/spellchecker_request_test.rb
94
+ vendor/solr-ruby/test/unit/standard_request_test.rb
95
+ vendor/solr-ruby/test/unit/standard_response_test.rb
96
+ vendor/solr-ruby/test/unit/suite.rb
97
+ vendor/solr-ruby/test/unit/tab_delimited.txt
98
+ vendor/solr-ruby/test/unit/util_test.rb
99
+ vendor/solr-ruby/test/unit/xpath_mapper_test.rb
100
+ vendor/solr-ruby/test/unit/xpath_test_file.xml
101
+ vendor/solr/CHANGES.txt
102
+ vendor/solr/LICENSE.txt
103
+ vendor/solr/NOTICE.txt
104
+ vendor/solr/etc/jetty.xml
105
+ vendor/solr/etc/webdefault.xml
106
+ vendor/solr/lib/commons-codec-1.3.jar
107
+ vendor/solr/lib/commons-csv-0.1-SNAPSHOT.jar
108
+ vendor/solr/lib/commons-fileupload-1.2.jar
109
+ vendor/solr/lib/commons-io-1.2.jar
110
+ vendor/solr/lib/easymock.jar
111
+ vendor/solr/lib/jetty-6.1.3.jar
112
+ vendor/solr/lib/jetty-util-6.1.3.jar
113
+ vendor/solr/lib/jsp-2.1/ant-1.6.5.jar
114
+ vendor/solr/lib/jsp-2.1/core-3.1.1.jar
115
+ vendor/solr/lib/jsp-2.1/jsp-2.1.jar
116
+ vendor/solr/lib/jsp-2.1/jsp-api-2.1.jar
117
+ vendor/solr/lib/lucene-analyzers-2007-05-20_00-04-53.jar
118
+ vendor/solr/lib/lucene-core-2007-05-20_00-04-53.jar
119
+ vendor/solr/lib/lucene-highlighter-2007-05-20_00-04-53.jar
120
+ vendor/solr/lib/lucene-snowball-2007-05-20_00-04-53.jar
121
+ vendor/solr/lib/lucene-spellchecker-2007-05-20_00-04-53.jar
122
+ vendor/solr/lib/servlet-api-2.4.jar
123
+ vendor/solr/lib/servlet-api-2.5-6.1.3.jar
124
+ vendor/solr/lib/xpp3-1.1.3.4.O.jar
125
+ vendor/solr/logs/.keep
126
+ vendor/solr/solr/README.txt
127
+ vendor/solr/solr/bin/abc
128
+ vendor/solr/solr/bin/abo
129
+ vendor/solr/solr/bin/backup
130
+ vendor/solr/solr/bin/backupcleaner
131
+ vendor/solr/solr/bin/commit
132
+ vendor/solr/solr/bin/optimize
133
+ vendor/solr/solr/bin/readercycle
134
+ vendor/solr/solr/bin/rsyncd-disable
135
+ vendor/solr/solr/bin/rsyncd-enable
136
+ vendor/solr/solr/bin/rsyncd-start
137
+ vendor/solr/solr/bin/rsyncd-stop
138
+ vendor/solr/solr/bin/scripts-util
139
+ vendor/solr/solr/bin/snapcleaner
140
+ vendor/solr/solr/bin/snapinstaller
141
+ vendor/solr/solr/bin/snappuller
142
+ vendor/solr/solr/bin/snappuller-disable
143
+ vendor/solr/solr/bin/snappuller-enable
144
+ vendor/solr/solr/bin/snapshooter
145
+ vendor/solr/solr/conf/admin-extra.html
146
+ vendor/solr/solr/conf/protwords.txt
147
+ vendor/solr/solr/conf/schema.xml
148
+ vendor/solr/solr/conf/scripts.conf
149
+ vendor/solr/solr/conf/solrconfig.xml
150
+ vendor/solr/solr/conf/stopwords.txt
151
+ vendor/solr/solr/conf/synonyms.txt
152
+ vendor/solr/solr/conf/xslt/example.xsl
153
+ vendor/solr/solr/conf/xslt/example_atom.xsl
154
+ vendor/solr/solr/conf/xslt/example_rss.xsl
155
+ vendor/solr/start.jar
156
+ vendor/solr/webapps/solr.war
@@ -0,0 +1,103 @@
1
+ tanning_bed
2
+ by Rob Kaufman (notch8.com)
3
+ with permission and support from the Assay Depot (assaydepot.com)
4
+
5
+ == DESCRIPTION:
6
+
7
+ Tanning Bed is Solr for models.
8
+ Tanning Bed provides a Ruby interface for the Solr (http://lucene.apache.org/solr/) search engine to use in you're models not matter whether they are Datamapper, Active Record, Couchrest or just general Ruby classes.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Incredibly simple in design, no fancy hooks
13
+ * Very Ruby
14
+ * {Ruby 1.9 Compatible}[http://notch8.github.com/files/Ruby19Badge.png]
15
+
16
+ == SYNOPSIS:
17
+
18
+ === Setup
19
+ Using TanningBed for a given class involves including the TanningBed model and then implementing a few (easy) methods.
20
+
21
+ Objects must implement:
22
+
23
+ * id - unique identifier for the record
24
+ * Class.get - this method receives and object's id and loads it
25
+ * solr_keys - an array of method names, the method results will be added to the index
26
+
27
+ ==== Examples
28
+
29
+ ===== CouchRest
30
+ id is already implemented and so is get. CouchRest has a method called keys which we'll use
31
+
32
+ class MyDocument < CouchRest::Model
33
+ include TanningBed
34
+
35
+ key_accessor :name
36
+ key_accessor :address
37
+
38
+ def solr_keys
39
+ keys
40
+ end
41
+
42
+ ===== ActiveRecord
43
+
44
+ id is implemented in ActiveRecord already
45
+
46
+ class MyModel < ActiveRecord::Base
47
+ include TanningBed
48
+
49
+ def get(value)
50
+ find(value)
51
+ end
52
+
53
+ def solr_keys
54
+ attribute_names
55
+ end
56
+ end
57
+
58
+ === Adding, Updating or Deleting
59
+ Adding a record is accomplished by
60
+
61
+ === Changing Solr connection
62
+ To change the url for Solr or to change whether autocommit is on or not add the following to you're instantiation (for example config/enviroments/production.rb)
63
+
64
+ TanningBed.solr_connection(YOUR_SOLR_URL, :off)
65
+
66
+ === Handling connection issues
67
+ Only you can decide the best way to handle Solr exceptions in your application. TanningBed provides a simple hook to allow you to do just that. By default connection exceptions (Errno::ECONNREFUSED) in TanningBed methods simply output to STDERR. This isn't really sufficient unless you're watching STDERR on you're application for problems. A common thing to want to do is simply be notified of the error while failing silently. To do that you might setup something like this:
68
+
69
+ TanningBed.on_solr_exception = Proc.new {|e| deliver_solr_down_email(e) }
70
+
71
+ == REQUIREMENTS:
72
+
73
+ * Solr (bundled)
74
+ * Solr-Ruby library (bundled)
75
+
76
+ == INSTALL:
77
+
78
+ * sudo gem install notch8-tanning-bed --source http://gems.github.com
79
+
80
+ == LICENSE:
81
+
82
+ (The MIT License)
83
+
84
+ Copyright (c) 2008 Assay Depot Inc.
85
+
86
+ Permission is hereby granted, free of charge, to any person obtaining
87
+ a copy of this software and associated documentation files (the
88
+ 'Software'), to deal in the Software without restriction, including
89
+ without limitation the rights to use, copy, modify, merge, publish,
90
+ distribute, sublicense, and/or sell copies of the Software, and to
91
+ permit persons to whom the Software is furnished to do so, subject to
92
+ the following conditions:
93
+
94
+ The above copyright notice and this permission notice shall be
95
+ included in all copies or substantial portions of the Software.
96
+
97
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
98
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
99
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
100
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
101
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
102
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
103
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,103 @@
1
+ tanning_bed
2
+ by Rob Kaufman (notch8.com)
3
+ with permission and support from the Assay Depot (assaydepot.com)
4
+
5
+ == DESCRIPTION:
6
+
7
+ Tanning Bed is Solr for models.
8
+ Tanning Bed provides a Ruby interface for the Solr (http://lucene.apache.org/solr/) search engine to use in you're models not matter whether they are Datamapper, Active Record, Couchrest or just general Ruby classes.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Incredibly simple in design, no fancy hooks
13
+ * Very Ruby
14
+ * {Ruby 1.9 Compatible}[http://notch8.github.com/files/Ruby19Badge.png]
15
+
16
+ == SYNOPSIS:
17
+
18
+ === Setup
19
+ Using TanningBed for a given class involves including the TanningBed model and then implementing a few (easy) methods.
20
+
21
+ Objects must implement:
22
+
23
+ * id - unique identifier for the record
24
+ * Class.get - this method receives and object's id and loads it
25
+ * solr_keys - an array of method names, the method results will be added to the index
26
+
27
+ ==== Examples
28
+
29
+ ===== CouchRest
30
+ id is already implemented and so is get. CouchRest has a method called keys which we'll use
31
+
32
+ class MyDocument < CouchRest::Model
33
+ include TanningBed
34
+
35
+ key_accessor :name
36
+ key_accessor :address
37
+
38
+ def solr_keys
39
+ keys
40
+ end
41
+
42
+ ===== ActiveRecord
43
+
44
+ id is implemented in ActiveRecord already
45
+
46
+ class MyModel < ActiveRecord::Base
47
+ include TanningBed
48
+
49
+ def get(value)
50
+ find(value)
51
+ end
52
+
53
+ def solr_keys
54
+ attribute_names
55
+ end
56
+ end
57
+
58
+ === Adding, Updating or Deleting
59
+ Adding a record is accomplished by
60
+
61
+ === Changing Solr connection
62
+ To change the url for Solr or to change whether autocommit is on or not add the following to you're instantiation (for example config/enviroments/production.rb)
63
+
64
+ TanningBed.solr_connection(YOUR_SOLR_URL, :off)
65
+
66
+ === Handling connection issues
67
+ Only you can decide the best way to handle Solr exceptions in your application. TanningBed provides a simple hook to allow you to do just that. By default connection exceptions (Errno::ECONNREFUSED) in TanningBed methods simply output to STDERR. This isn't really sufficient unless you're watching STDERR on you're application for problems. A common thing to want to do is simply be notified of the error while failing silently. To do that you might setup something like this:
68
+
69
+ TanningBed.on_solr_exception = Proc.new {|e| deliver_solr_down_email(e) }
70
+
71
+ == REQUIREMENTS:
72
+
73
+ * Solr (bundled)
74
+ * Solr-Ruby library (bundled)
75
+
76
+ == INSTALL:
77
+
78
+ * sudo gem install notch8-tanning-bed --source http://gems.github.com
79
+
80
+ == LICENSE:
81
+
82
+ (The MIT License)
83
+
84
+ Copyright (c) 2008 Assay Depot Inc.
85
+
86
+ Permission is hereby granted, free of charge, to any person obtaining
87
+ a copy of this software and associated documentation files (the
88
+ 'Software'), to deal in the Software without restriction, including
89
+ without limitation the rights to use, copy, modify, merge, publish,
90
+ distribute, sublicense, and/or sell copies of the Software, and to
91
+ permit persons to whom the Software is furnished to do so, subject to
92
+ the following conditions:
93
+
94
+ The above copyright notice and this permission notice shall be
95
+ included in all copies or substantial portions of the Software.
96
+
97
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
98
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
99
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
100
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
101
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
102
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
103
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ rescue LoadError
8
+ abort '### Please install the "bones" gem ###'
9
+ end
10
+
11
+
12
+ ensure_in_path 'lib'
13
+ require 'tanning_bed'
14
+
15
+ task :default => 'spec:run'
16
+
17
+ Bones {
18
+ name 'tanning_bed'
19
+ authors 'Rob Kaufman'
20
+ email 'rob@notch8.com'
21
+ url 'http://notch8.com'
22
+ rubyforge.name = 'tanning_bed'
23
+ spec.opts << '--color'
24
+ depend_on 'solr-ruby', '0.0.8'
25
+ depend_on 'tanning_bed_solr', :development => true
26
+ }
27
+
28
+
29
+ # EOF
@@ -0,0 +1,205 @@
1
+ __DIR__ = File.dirname(__FILE__) + "/"
2
+ begin
3
+ require 'solr'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'solr'
7
+ end
8
+
9
+ # $Id$
10
+
11
+ # Equivalent to a header guard in C/C++
12
+ # Used to prevent the class/module from being loaded more than once
13
+ unless defined? TanningBed
14
+
15
+ module TanningBed
16
+ module ClassMethods
17
+ def solr_search(query_string, options={})
18
+ TanningBed.solr_connection.query(query_string + " AND type_t:#{self}", options)
19
+ rescue Errno::ECONNREFUSED => e
20
+ TanningBed.solr_exception(e)
21
+ end
22
+
23
+ def solr_load(results)
24
+ key_set = results.collect do |result|
25
+ key = result["search_id"].first.split(" ")
26
+ next if key[0] != self.to_s
27
+ Kernel.const_get(key[0]).send(:get, key[1])
28
+ end
29
+ key_set.delete(nil)
30
+ return key_set
31
+ end
32
+
33
+ def solr_reindex
34
+ # Remove all the old entries for this class
35
+ TanningBed.solr_connection.delete_by_query(self.to_s)
36
+
37
+ #Add all the current records into the index
38
+ self.all.each do |item|
39
+ item.solr_add
40
+ end
41
+ end
42
+ end
43
+
44
+ def self.included(base)
45
+ @@conn = nil
46
+ @@on_solr_exception = nil
47
+ base.extend(ClassMethods)
48
+ end
49
+
50
+ # connect to the solr instance
51
+ def self.solr_connection(url='http://localhost:8983/solr', autocommit=:on, reset=false)
52
+ if reset
53
+ @@conn = Solr::Connection.new(url, :autocommit => autocommit)
54
+ else
55
+ @@conn ||= Solr::Connection.new(url, :autocommit => autocommit)
56
+ end
57
+ end
58
+
59
+ def self.solr_exception(e)
60
+ if TanningBed.on_solr_exception
61
+ TanningBed.on_solr_exception.call(e)
62
+ else
63
+ $stderr.puts("SOLR - " + e.to_s)
64
+ end
65
+ end
66
+
67
+ def self.on_solr_exception
68
+ @@on_solr_exception
69
+ end
70
+
71
+ def self.on_solr_exception=(value)
72
+ @@on_solr_exception = value
73
+ end
74
+
75
+ def solr_id
76
+ "#{self.class} #{self.id}"
77
+ end
78
+
79
+ # add a document to the index
80
+ def solr_add
81
+ TanningBed.solr_connection.add(search_fields)
82
+ rescue Errno::ECONNREFUSED => e
83
+ TanningBed.solr_exception(e)
84
+ end
85
+
86
+ def solr_update
87
+ TanningBed.solr_connection.update(search_fields)
88
+ rescue Errno::ECONNREFUSED => e
89
+ TanningBed.solr_exception(e)
90
+ end
91
+
92
+ def self.solr_search(query_string, options={})
93
+ TanningBed.solr_connection.query(query_string, options)
94
+ rescue Errno::ECONNREFUSED => e
95
+ TanningBed.solr_exception(e)
96
+ end
97
+
98
+ def self.solr_load(results)
99
+ key_set = results.collect do |result|
100
+ key = result["search_id"].first.split(" ")
101
+ Kernel.const_get(key[0]).send(:get, key[1])
102
+ end
103
+ return key_set
104
+ end
105
+
106
+ def solr_delete
107
+ TanningBed.solr_connection.delete(solr_id)
108
+ rescue Errno::ECONNREFUSED => e
109
+ TanningBed.solr_exception(e)
110
+ end
111
+
112
+ def solr_keys
113
+ raise "You must define the method solr_keys in the class you want to use for Solr.\n This should return an array of method names to call on you're class for indexing\n eg: ['id', 'name', 'description']"
114
+ end
115
+
116
+ def search_fields
117
+ @fields = {}
118
+ self.solr_keys.each do |key|
119
+ if self.respond_to?(key)
120
+ value = self.send(key)
121
+ key_type = lookup_key_type(key, value.class)
122
+ @fields["#{key}#{key_type}"] = value
123
+ end
124
+ end
125
+ @fields[:search_id] = solr_id
126
+ @fields[:type_t] = self.class.to_s
127
+ @fields[:id_t] = self.id
128
+ return @fields
129
+ end
130
+
131
+ def lookup_key_type(key, klass)
132
+ # is the key already in the correct_format?
133
+ key_postfix = key.split("_").last
134
+ return nil if ["i", "facet", "t", "f", "d", "mv"].include?(key_postfix)
135
+
136
+ # Add the helper to the key string
137
+ case klass.to_s
138
+ when "Fixnum"
139
+ "_i"
140
+ when "String"
141
+ if key.size < 255
142
+ "_facet"
143
+ else
144
+ "_t"
145
+ end
146
+ when "Float"
147
+ "_f"
148
+ when "Date", "Datetime", "Time"
149
+ "_d"
150
+ when "Array"
151
+ "_s_mv"
152
+ else
153
+ "_t"
154
+ end
155
+ end
156
+
157
+
158
+ # :stopdoc:
159
+ VERSION = '0.0.11'
160
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
161
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
162
+ # :startdoc:
163
+
164
+ # Returns the version string for the library.
165
+ #
166
+ def self.version
167
+ VERSION
168
+ end
169
+
170
+ # Returns the library path for the module. If any arguments are given,
171
+ # they will be joined to the end of the libray path using
172
+ # <tt>File.join</tt>.
173
+ #
174
+ def self.libpath( *args )
175
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
176
+ end
177
+
178
+ # Returns the lpath for the module. If any arguments are given,
179
+ # they will be joined to the end of the path using
180
+ # <tt>File.join</tt>.
181
+ #
182
+ def self.path( *args )
183
+ args.empty? ? PATH : ::File.join(PATH, *args)
184
+ end
185
+
186
+ # Utility method used to rquire all files ending in .rb that lie in the
187
+ # directory below this file that has the same name as the filename passed
188
+ # in. Optionally, a specific _directory_ name can be passed in such that
189
+ # the _filename_ does not have to be equivalent to the directory.
190
+ #
191
+ def self.require_all_libs_relative_to( fname, dir = nil )
192
+ dir ||= ::File.basename(fname, '.*')
193
+ search_me = ::File.expand_path(
194
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
195
+
196
+ Dir.glob(search_me).sort.each {|rb| require rb}
197
+ end
198
+
199
+ end # module TanningBed
200
+
201
+ TanningBed.require_all_libs_relative_to __FILE__
202
+
203
+ end # unless defined?
204
+
205
+ # EOF
@@ -0,0 +1,22 @@
1
+ class BurntModel
2
+ include TanningBed
3
+ attr_accessor :name, :description
4
+
5
+ def initialize
6
+ @name = "Big Bad Voodoo Daddy"
7
+ @description = "Not really that bad after all."
8
+ end
9
+
10
+ def id
11
+ 666
12
+ end
13
+
14
+ def find(value)
15
+ 666
16
+ end
17
+ alias :get :find
18
+
19
+ def solr_keys
20
+ ["name", "description"]
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ class TanningModel
2
+ include TanningBed
3
+ attr_accessor :name, :description, :tan_facet, :keywords
4
+ def initialize
5
+ @name = "Big Bad Voodoo Daddy"
6
+ @description = "Not really that bad after all."
7
+ @tan_facet = "dark"
8
+ @keywords = ["Record", "stuff", "other"]
9
+ end
10
+
11
+ def id
12
+ 666
13
+ end
14
+
15
+ def keywords_facet
16
+ keywords
17
+ end
18
+
19
+
20
+ def solr_keys
21
+ ["name", "description", "tan_facet", "keywords_facet"]
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # $Id$
2
+ require 'spec'
3
+
4
+ __DIR__ = File.dirname(__FILE__) + "/"
5
+
6
+ require File.expand_path(
7
+ File.join(File.dirname(__FILE__), %w[.. lib tanning_bed]))
8
+
9
+ require __DIR__ + "fixtures/tanning_model.rb"
10
+ require __DIR__ + "fixtures/burnt_model.rb"
11
+
12
+ Spec::Runner.configure do |config|
13
+ # == Mock Framework
14
+ #
15
+ # RSpec uses it's own mocking framework by default. If you prefer to
16
+ # use mocha, flexmock or RR, uncomment the appropriate line:
17
+ #
18
+ # config.mock_with :mocha
19
+ # config.mock_with :flexmock
20
+ # config.mock_with :rr
21
+ end
22
+
23
+ # EOF
@@ -0,0 +1,105 @@
1
+ # $Id$
2
+ require 'open-uri'
3
+ __DIR__ = File.dirname(__FILE__) + "/"
4
+
5
+ require __DIR__ + 'spec_helper.rb'
6
+
7
+ describe "TanningBed" do
8
+ before(:all) do
9
+ begin
10
+ open("http://localhost:8984/solr")
11
+ rescue
12
+ puts "Solr must be started on port 8984 before you run the specs. Use rake solr:start SOLR_PORT=8984"
13
+ exit 1
14
+ end
15
+ TanningBed.solr_connection('http://localhost:8984/solr', :on)
16
+ end
17
+
18
+ before(:each) do
19
+ @tanning = TanningModel.new
20
+ @burnt = BurntModel.new
21
+ end
22
+
23
+ it "should be includeable in a ruby class" do
24
+ TanningModel.included_modules.should include(TanningBed)
25
+ end
26
+
27
+ it "should enable adding a record to solr" do
28
+ @tanning.respond_to?("solr_add").should be_true
29
+ @tanning.solr_add.should be_true
30
+ end
31
+
32
+ it "should enable updating a record in solr" do
33
+ @tanning.solr_add
34
+ old_total = TanningBed.solr_connection.query("Big Bad Voodoo Daddy").total_hits
35
+ @tanning.name = "Joe the Plumber"
36
+ @tanning.solr_update
37
+ new_total = TanningBed.solr_connection.query("Big Bad Voodoo Daddy").total_hits
38
+ new_total.should be_eql(old_total - 1)
39
+ end
40
+
41
+ it "should enable deleting a record in solr" do
42
+ @tanning.solr_add
43
+ old_total = TanningBed.solr_connection.query("Big Bad Voodoo Daddy").total_hits
44
+ @tanning.solr_delete
45
+ new_total = TanningBed.solr_connection.query("Big Bad Voodoo Daddy").total_hits
46
+ new_total.should be_equal(old_total - 1)
47
+ end
48
+
49
+ it "should enable searching solr for a set of search_ids" do
50
+ @tanning.solr_add
51
+ @burnt.solr_add
52
+ result = TanningBed.solr_search("Big")
53
+ result.total_hits.should be_equal(2)
54
+ result.hits.first["search_id"].should eql(["TanningModel 666"])
55
+ result.hits.last["search_id"].should eql(["BurntModel 666"])
56
+ end
57
+
58
+ it "should allow searching for only records of a specific class" do
59
+ @tanning.solr_add
60
+ @burnt.solr_add
61
+ result = TanningModel.solr_search("Big")
62
+ result.total_hits.should be_equal(1)
63
+ result.hits.first["search_id"].should eql(["TanningModel 666"])
64
+ end
65
+
66
+ it "should not add a postfix to a key that is already in the correct format" do
67
+ ["_i", "_facet", "_t", "_f", "_d"].each do |postfix|
68
+ @tanning.lookup_key_type("test_#{postfix}", String).should be_nil
69
+ end
70
+ end
71
+
72
+ it "should swallow exceptions by default if Solr is down" do
73
+ tmp_file = __DIR__ + "/tmp/solr_err.tmp"
74
+ FileUtils.mkdir_p(__DIR__ + "/tmp")
75
+ TanningBed.solr_connection('http://localhost:9999/solr', :on, true)
76
+
77
+ old_err = $stderr
78
+ $stderr = File.open(tmp_file, "w")
79
+ TanningBed.solr_search("test")
80
+ $stderr.flush
81
+ $stderr.close
82
+ $stderr = old_err
83
+ File.open(tmp_file, "r") do |file|
84
+ file.read.should == "SOLR - Connection refused - connect(2)\n"
85
+ end
86
+ TanningBed.solr_connection('http://localhost:8984/solr', :on, true)
87
+
88
+ end
89
+
90
+ it "should store a proc to handle exceptions if Solr is down" do
91
+ tmp_file = __DIR__ + "/tmp/solr_err.tmp"
92
+
93
+ TanningBed.solr_connection('http://localhost:9999/solr', :on, true)
94
+
95
+ TanningBed.on_solr_exception = Proc.new {|e| raise e}
96
+ lambda {TanningBed.solr_search("test")}.should raise_error(Errno::ECONNREFUSED)
97
+
98
+ TanningBed.on_solr_exception = nil
99
+ TanningBed.solr_connection('http://localhost:8984/solr', :on, true)
100
+ end
101
+
102
+
103
+ end
104
+
105
+ # EOF
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{tanning_bed}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Rob Kaufman"]
9
+ s.date = %q{2010-03-15}
10
+ s.description = %q{Tanning Bed is Solr for models.
11
+ Tanning Bed provides a Ruby interface for the Solr (http://lucene.apache.org/solr/) search engine to use in you're models not matter whether they are Datamapper, Active Record, Couchrest or just general Ruby classes.}
12
+ s.email = %q{rob@notch8.com}
13
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc", "README.txt", "version.txt"]
14
+ s.files = [".gitignore", "History.txt", "Manifest.txt", "README.rdoc", "README.txt", "Rakefile", "lib/tanning_bed.rb", "spec/fixtures/burnt_model.rb", "spec/fixtures/tanning_model.rb", "spec/spec_helper.rb", "spec/tanning_bed_spec.rb", "tanning_bed.gemspec", "tasks/solr.rake", "tasks/solr.rb", "version.txt"]
15
+ s.homepage = %q{http://notch8.com}
16
+ s.rdoc_options = ["--main", "README.txt"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{tanning_bed}
19
+ s.rubygems_version = %q{1.3.6}
20
+ s.summary = %q{Tanning Bed is Solr for models}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<solr-ruby>, [">= 0.0.8"])
28
+ s.add_development_dependency(%q<tanning_bed_solr>, [">= 0.0.1"])
29
+ s.add_development_dependency(%q<bones>, [">= 3.4.0"])
30
+ else
31
+ s.add_dependency(%q<solr-ruby>, [">= 0.0.8"])
32
+ s.add_dependency(%q<tanning_bed_solr>, [">= 0.0.1"])
33
+ s.add_dependency(%q<bones>, [">= 3.4.0"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<solr-ruby>, [">= 0.0.8"])
37
+ s.add_dependency(%q<tanning_bed_solr>, [">= 0.0.1"])
38
+ s.add_dependency(%q<bones>, [">= 3.4.0"])
39
+ end
40
+ end
@@ -0,0 +1,2 @@
1
+ __DIR__ = File.dirname(__FILE__)
2
+ require __DIR__ + '/solr.rb'
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'net/http'
4
+ require 'fileutils'
5
+
6
+ namespace :solr do
7
+
8
+ desc 'Start Solr for tests. Sets SOLR_PORT to 8984 and index is puts in /tmp'
9
+ task :start_testing do
10
+ ENV["SOLR_PORT"] = '8984'
11
+ solr_command = "java -Dsolr.data.dir=/tmp -Djetty.port=#{solr_port} -jar start.jar"
12
+ start_solr(solr_command)
13
+ end
14
+
15
+ desc 'Starts Solr. SOLR_PORT=XX. SOLR_PATH=yy'
16
+ task :start do
17
+ solr_command = "java -Dsolr.data.dir=solr/data -Djetty.port=#{solr_port} -jar start.jar"
18
+ start_solr(solr_command)
19
+ end
20
+
21
+ desc 'Stops Solr.'
22
+ task :stop do
23
+ fork do
24
+ file_path = "#{solr_path}/tmp/solr_pid"
25
+ if File.exists?(file_path)
26
+ File.open(file_path, "r") do |f|
27
+ pid = f.readline
28
+ Process.kill('TERM', pid.to_i)
29
+ end
30
+ File.unlink(file_path)
31
+ # Rake::Task["solr:destroy_index"].invoke if ENV['RAILS_ENV'] == 'test'
32
+ puts "Solr shutdown successfully."
33
+ else
34
+ puts "Solr is not running. I haven't done anything."
35
+ end
36
+ end
37
+ end
38
+
39
+ desc 'Remove Solr index'
40
+ task :destroy_index do
41
+ index_path = "#{solr_path}/solr/data"
42
+ if File.exists?(index_path)
43
+ Dir[ index_path + "/index/*"].each{|f| File.unlink(f)}
44
+ Dir.rmdir(index_path + "/index")
45
+ puts "Index files removed under #{index_path}/index"
46
+ end
47
+ end
48
+
49
+ def solr_port
50
+ if ENV["SOLR_PORT"]
51
+ return ENV["SOLR_PORT"]
52
+ else
53
+ return "8983"
54
+ end
55
+ end
56
+
57
+ def solr_path
58
+ return @solr_path if @solr_path
59
+ return @solr_path = ENV["SOLR_PATH"] if ENV["SOLR_PATH"]
60
+ if Gem.available? 'tanning_bed_solr'
61
+ return @solr_path = "#{Gem.searcher.find('tanning_bed_solr').full_gem_path}/vendor/solr"
62
+ else
63
+ raise 'No solr install found, either set SOLR_PATH or install tanning_bed_solr gem'
64
+ end
65
+ end
66
+
67
+ def start_solr(solr_command)
68
+ begin
69
+ n = Net::HTTP.new('localhost', solr_port)
70
+ n.request_head('/').value
71
+
72
+ rescue Net::HTTPServerException #responding
73
+ puts "Port #{solr_port} in use" and return
74
+
75
+ rescue Errno::ECONNREFUSED #not responding
76
+ Dir.chdir(solr_path) do
77
+ pid = fork do
78
+ #STDERR.close
79
+ exec solr_command
80
+ end
81
+ sleep(5)
82
+ FileUtils.mkdir_p("#{solr_path}/tmp")
83
+ File.open("#{solr_path}/tmp/solr_pid", "w"){ |f| f << pid}
84
+ puts "Solr started successfully on #{solr_port}, pid: #{pid}."
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1 @@
1
+ 0.1.1
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tanning_bed
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Rob Kaufman
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-15 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: solr-ruby
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 8
31
+ version: 0.0.8
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: tanning_bed_solr
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 0
44
+ - 1
45
+ version: 0.0.1
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: bones
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 3
57
+ - 4
58
+ - 0
59
+ version: 3.4.0
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: |-
63
+ Tanning Bed is Solr for models.
64
+ Tanning Bed provides a Ruby interface for the Solr (http://lucene.apache.org/solr/) search engine to use in you're models not matter whether they are Datamapper, Active Record, Couchrest or just general Ruby classes.
65
+ email: rob@notch8.com
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files:
71
+ - History.txt
72
+ - Manifest.txt
73
+ - README.rdoc
74
+ - README.txt
75
+ - version.txt
76
+ files:
77
+ - .gitignore
78
+ - History.txt
79
+ - Manifest.txt
80
+ - README.rdoc
81
+ - README.txt
82
+ - Rakefile
83
+ - lib/tanning_bed.rb
84
+ - spec/fixtures/burnt_model.rb
85
+ - spec/fixtures/tanning_model.rb
86
+ - spec/spec_helper.rb
87
+ - spec/tanning_bed_spec.rb
88
+ - tanning_bed.gemspec
89
+ - tasks/solr.rake
90
+ - tasks/solr.rb
91
+ - version.txt
92
+ has_rdoc: true
93
+ homepage: http://notch8.com
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --main
99
+ - README.txt
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project: tanning_bed
119
+ rubygems_version: 1.3.6
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Tanning Bed is Solr for models
123
+ test_files: []
124
+