datastax_rails 1.0.13.2 → 1.0.13.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -4
- data/lib/datastax_rails/attribute_methods/typecasting.rb +54 -15
- data/lib/datastax_rails/connection.rb +4 -0
- data/lib/datastax_rails/relation/finder_methods.rb +0 -1
- data/lib/datastax_rails/relation/search_methods.rb +19 -18
- data/lib/datastax_rails/relation.rb +1 -1
- data/lib/datastax_rails/rsolr_client_wrapper.rb +1 -0
- data/lib/datastax_rails/types/array_type.rb +3 -3
- data/lib/datastax_rails/version.rb +1 -1
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +777 -0
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -36,8 +36,8 @@ Configure the config/datastax.yml file:
|
|
36
36
|
connection_options:
|
37
37
|
timeout: 2
|
38
38
|
solr:
|
39
|
-
|
40
|
-
|
39
|
+
port: 8983
|
40
|
+
path: /solr
|
41
41
|
|
42
42
|
The above is configured to use NetworkTopologyStrategy. If you go with this, you'll need to configure Datastax to use the
|
43
43
|
NetworkTopologySnitch and set up the cassandra-topology.properties file. See the Datastax documentation for more information.
|
@@ -52,8 +52,8 @@ For a more simple, single datacenter setup, something like this should probably
|
|
52
52
|
connection_options:
|
53
53
|
timeout: 2
|
54
54
|
solr:
|
55
|
-
|
56
|
-
|
55
|
+
port: 8983
|
56
|
+
path: /solr
|
57
57
|
|
58
58
|
See DatastaxRails::Connection::ClassMethods for a description of what options are available.
|
59
59
|
|
@@ -75,6 +75,9 @@ attributes on any model. DSR will only upload schema files if they have changed
|
|
75
75
|
Calling +find+ on a model with a bogus ID returns an empty model instead of RecordNotFound. This is due to a bug
|
76
76
|
in DSE that is supposedly fixed in the upcoming 2.2 release.
|
77
77
|
|
78
|
+
Setting an integer field to something other than an integer results in nothing being set and no validation error
|
79
|
+
(if you were using one).
|
80
|
+
|
78
81
|
=== More information
|
79
82
|
|
80
83
|
The documentation for DatastaxRails::Base and DatastaxRails::SearchMethods will give you quite a few examples
|
@@ -11,31 +11,70 @@ module DatastaxRails
|
|
11
11
|
self.lazy_attributes = []
|
12
12
|
self.readonly_attributes = []
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
# We need to ensure that inherited classes get their own attribute definitions.
|
18
|
+
# In addition, we take the opportunity to track all the DatastaxRails::Base decendents.
|
19
|
+
# This will be useful when it comes to things like schema generation.
|
20
|
+
def inherited(child)
|
21
|
+
super
|
22
|
+
child.attribute_definitions = attribute_definitions.dup
|
23
|
+
self.models << child
|
20
24
|
end
|
21
25
|
|
22
|
-
|
26
|
+
# @!group Attribute Types
|
27
|
+
|
28
|
+
# @!macro [new] attr_doc
|
29
|
+
# Declare an attribute of the given type
|
30
|
+
#
|
31
|
+
# @param [Symbol] name the name of the attribute to create
|
32
|
+
# @param [Hash] options the options to use in setting up the attribute
|
33
|
+
def binary(name, options = {})
|
23
34
|
options.reverse_merge!(:lazy => true)
|
24
35
|
attribute(name, options.update(:type => :binary))
|
25
36
|
end
|
26
37
|
|
27
|
-
|
38
|
+
# Declare the timestamps attribute type method.
|
39
|
+
# Creates both the created_at and updated_at attributes with type +time+.
|
40
|
+
#
|
41
|
+
# @param [Hash] options the options to use in setting up the attribute
|
42
|
+
def timestamps(options = {})
|
28
43
|
attribute(:created_at, options.update(:type => :time))
|
29
44
|
attribute(:updated_at, options.update(:type => :time))
|
30
45
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
46
|
+
|
47
|
+
# @!method array(name, options = {})
|
48
|
+
# @macro attr_doc
|
49
|
+
# @!method boolean(name, options = {})
|
50
|
+
# @macro attr_doc
|
51
|
+
# @!method date(name, options = {})
|
52
|
+
# @macro attr_doc
|
53
|
+
# @!method float(name, options = {})
|
54
|
+
# @macro attr_doc
|
55
|
+
# @!method integer(name, options = {})
|
56
|
+
# @macro attr_doc
|
57
|
+
# @!method json(name, options = {})
|
58
|
+
# @macro attr_doc
|
59
|
+
# @!method string(name, options = {})
|
60
|
+
# @macro attr_doc
|
61
|
+
# @!method text(name, options = {})
|
62
|
+
# @macro attr_doc
|
63
|
+
# @!method time(name, options = {})
|
64
|
+
# @macro attr_doc
|
65
|
+
# @!method time_with_zone(name, options = {})
|
66
|
+
# @macro attr_doc
|
67
|
+
|
68
|
+
# The following sets up a bunch of nearly identical attribute methods
|
69
|
+
%w(array boolean date float integer json string text time time_with_zone).each do |type|
|
70
|
+
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
71
|
+
def #{type}(name, options = {}) # def string(name, options = {})
|
72
|
+
attribute(name, options.update(:type => :#{type})) # attribute(name, options.update(type: :string))
|
73
|
+
end # end
|
74
|
+
EOV
|
38
75
|
end
|
76
|
+
|
77
|
+
# @!endgroup
|
39
78
|
|
40
79
|
# Casts a single attribute according to the appropriate coder.
|
41
80
|
#
|
@@ -20,6 +20,8 @@ module DatastaxRails
|
|
20
20
|
# cluster, and we want to know which server specifically we are connected to.
|
21
21
|
#
|
22
22
|
# Used by Relation to calculate the SOLR URL so that it follows the Cassandra connection.
|
23
|
+
#
|
24
|
+
# @return [String] the hostname or ip address of the current server
|
23
25
|
def current_server
|
24
26
|
thrift_client.instance_variable_get(:@current_server).to_s.split(/\:/).first
|
25
27
|
end
|
@@ -99,6 +101,8 @@ module DatastaxRails
|
|
99
101
|
# Similar to +establish_connection+, this method creates a connection object for Solr. Since HTTP is stateless, this doesn't
|
100
102
|
# actually launch the connection, but it gets everything set up so that RSolr can do its work. It's important to note that
|
101
103
|
# unlike the cassandra connection which is global to all of DSR, each model will have its own solr_connection.
|
104
|
+
#
|
105
|
+
# @return [DatastaxRails::RSolrClientWrapper] a wrapped RSolr connection
|
102
106
|
def solr_connection
|
103
107
|
@rsolr ||= DatastaxRails::RSolrClientWrapper.new(RSolr.connect :url => "#{solr_base_url}/#{DatastaxRails::Base.connection.keyspace}.#{self.column_family}")
|
104
108
|
end
|
@@ -309,34 +309,35 @@ module DatastaxRails
|
|
309
309
|
end
|
310
310
|
end
|
311
311
|
|
312
|
-
#
|
312
|
+
# @see where
|
313
313
|
def less_than(value)
|
314
314
|
raise ArgumentError, "#less_than can only be called after an appropriate where call. e.g. where(:created_at).less_than(1.day.ago)"
|
315
315
|
end
|
316
316
|
|
317
|
-
#
|
317
|
+
# @see where
|
318
318
|
def greater_than(value)
|
319
319
|
raise ArgumentError, "#greater_than can only be called after an appropriate where call. e.g. where(:created_at).greater_than(1.day.ago)"
|
320
320
|
end
|
321
321
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
322
|
+
protected
|
323
|
+
def solr_format(value)
|
324
|
+
return value unless use_solr_value
|
325
|
+
case
|
326
|
+
when value.is_a?(Date), value.is_a?(Time)
|
327
|
+
value.strftime('%Y-%m-%dT%H:%M:%SZ')
|
328
|
+
when value.is_a?(Array)
|
329
|
+
value.collect {|v| v.gsub(/ /,"\\ ") }.join(" OR ")
|
330
|
+
when value.is_a?(Fixnum)
|
331
|
+
value < 0 ? "\\#{value}" : value
|
332
|
+
when value.is_a?(Range)
|
333
|
+
"[#{solr_format(value.first)} TO #{solr_format(value.last)}]"
|
334
|
+
when value.is_a?(String)
|
335
|
+
solr_escape(downcase_query(value.gsub(/ /,"\\ ")))
|
336
|
+
else
|
337
|
+
value
|
338
|
+
end
|
336
339
|
end
|
337
|
-
end
|
338
340
|
|
339
|
-
protected
|
340
341
|
def find_by_attributes(match, attributes, *args) #:nodoc:
|
341
342
|
conditions = Hash[attributes.map {|a| [a, args[attributes.index(a)]]}]
|
342
343
|
result = where(conditions).send(match.finder)
|
@@ -271,7 +271,7 @@ module DatastaxRails
|
|
271
271
|
@where_values.each do |wv|
|
272
272
|
wv.each do |k,v|
|
273
273
|
# If v is blank, check that there is no value for the field in the document
|
274
|
-
filter_queries << (v.blank? ? "-#{k}:[
|
274
|
+
filter_queries << (v.blank? ? "-#{k}:[\"\" TO *]" : "#{k}:(#{v})")
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
@@ -2,6 +2,7 @@ module DatastaxRails
|
|
2
2
|
# Wraps the RSolr Client class so that exceptions such as Connection Refused can be caught and
|
3
3
|
# a new server tried (if one is available)
|
4
4
|
class RSolrClientWrapper < BlankSlate
|
5
|
+
# @param [RSolr::Client] rsolr the initial RSolr client object to wrap
|
5
6
|
def initialize(rsolr)
|
6
7
|
@rsolr = rsolr
|
7
8
|
end
|
@@ -69,13 +69,13 @@ module DatastaxRails
|
|
69
69
|
raise ArgumentError.new("#{self} requires an Array") unless array.kind_of?(Array)
|
70
70
|
ar = Array(array)
|
71
71
|
ar.uniq! if options[:unique]
|
72
|
-
ar.join("
|
72
|
+
ar.join("$$$$")
|
73
73
|
end
|
74
74
|
|
75
75
|
def decode(str)
|
76
76
|
return [] if str.blank?
|
77
|
-
|
78
|
-
str.is_a?(Array) ? str.flatten : str.split(
|
77
|
+
# Temporary fix
|
78
|
+
str.is_a?(Array) ? str.flatten : str.gsub(/&&&&/,'$$$$').split(/\$\$\$\$/).reject{|a|a.blank?}
|
79
79
|
end
|
80
80
|
|
81
81
|
def wrap(record, name, value)
|
File without changes
|