mwmitchell-rsolr 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,3 +1,8 @@
1
+ 0.6.4 - January 26, 2009
2
+ Updated the mapping output for the :filters and :phrase_filters (when using the #search method)
3
+ - now sending multiple fq's instead of one
4
+ Updated mapping tests
5
+
1
6
  0.6.3 - January 21, 2009
2
7
  Added a new param mapping module: RSolr::Connection::ParamMapping
3
8
  Mapping only for fields that need conversion/escaping or nested (facet.*) etc.
@@ -21,7 +21,7 @@ class RSolr::Connection::Adapter::HTTP
21
21
  #
22
22
  def initialize(opts={}, &block)
23
23
  opts[:url]||='http://127.0.0.1:8983/solr'
24
- @opts = default_options.merge(opts) # default_options are coming from RSolr::Connection::Adapter::CommonMethods
24
+ @opts = default_options.merge(opts).to_mash # default_options are coming from RSolr::Connection::Adapter::CommonMethods
25
25
  end
26
26
 
27
27
  def connection
@@ -11,7 +11,7 @@ class RSolr::Connection::Base
11
11
  # RSolr::Adapter::HTTP
12
12
  # RSolr::Adapter::Direct (jRuby only)
13
13
  def initialize(adapter, opts={})
14
- @adapter=adapter
14
+ @adapter = adapter
15
15
  @param_mappers = {
16
16
  :standard=>RSolr::Connection::ParamMapping::Standard,
17
17
  :dismax=>RSolr::Connection::ParamMapping::Dismax
@@ -45,7 +45,7 @@ class RSolr::Connection::Base
45
45
  p[:wt]==:ruby ? RSolr::Response::Query::Base.new(response) : response
46
46
  end
47
47
 
48
- # register your own mapper?
48
+ # register your own mapper if you want?
49
49
  def search(params,&blk)
50
50
  qt = params[:qt] ? params[:qt].to_sym : :dismax
51
51
  mapper_class = @param_mappers[qt]
@@ -4,7 +4,7 @@ class RSolr::Connection::ParamMapping::Dismax < RSolr::Connection::ParamMapping:
4
4
  super
5
5
 
6
6
  mapping_for :alternate_query, :q.alt do |val|
7
- format_query(val)
7
+ format_query(val).join(' ')
8
8
  end
9
9
 
10
10
  mapping_for :query_fields, :qf do |val|
@@ -16,7 +16,7 @@ class RSolr::Connection::ParamMapping::Dismax < RSolr::Connection::ParamMapping:
16
16
  end
17
17
 
18
18
  mapping_for :boost_query, :bq do |val|
19
- format_query(val)
19
+ format_query(val).join(' ')
20
20
  end
21
21
 
22
22
  end
@@ -28,7 +28,11 @@ class RSolr::Connection::ParamMapping::Standard
28
28
  end
29
29
 
30
30
  mapping_for :phrase_queries, :q do |val|
31
- [@output[:q], format_query(val, true)].reject{|v|v.to_s.empty?}.join(' ')
31
+ values = [@output[:q], format_query(val, true)]
32
+ # remove blank items
33
+ values.reject!{|v|v.to_s.empty?}
34
+ # join all items on a space
35
+ values.join(' ')
32
36
  end
33
37
 
34
38
  mapping_for :filters, :fq do |val|
@@ -37,7 +41,14 @@ class RSolr::Connection::ParamMapping::Standard
37
41
 
38
42
  # this must come after the :filter/:fq mapper
39
43
  mapping_for :phrase_filters, :fq do |val|
40
- [@output[:fq], format_query(val, true)].reject{|v|v.to_s.empty?}.join(' ')
44
+ # use the previously set fq queries and generate the new phrased based ones
45
+ values = [@output[:fq], format_query(val, true)]
46
+ # flatten (need to do this because the previous fq could have been an array)
47
+ values = values.flatten
48
+ # remove blank items
49
+ values.reject!{|v|v.to_s.empty?} # don't join -- instead create multiple fq params
50
+ # don't join... fq needs to be an array so multiple fq params are sent to solr
51
+ values
41
52
  end
42
53
 
43
54
  mapping_for :facets do |input|
@@ -72,6 +83,7 @@ class RSolr::Connection::ParamMapping::Standard
72
83
  end
73
84
  end
74
85
 
86
+ # takes an input and returns a formatted value
75
87
  def format_query(input, quote=false)
76
88
  case input
77
89
  when Array
@@ -86,7 +98,7 @@ class RSolr::Connection::ParamMapping::Standard
86
98
  def format_array_query(input, quote)
87
99
  input.collect do |v|
88
100
  v.is_a?(Hash) ? format_hash_query(v, quote) : prep_value(v, quote)
89
- end.join(' ')
101
+ end
90
102
  end
91
103
 
92
104
  # groups values to a single field: title:(value1 value2) instead of title:value1 title:value2
@@ -101,11 +113,11 @@ class RSolr::Connection::ParamMapping::Standard
101
113
  vv.is_a?(Range) ? "[#{vv.min} TO #{vv.max}]" : prep_value(vv, quote)
102
114
  end
103
115
  field = field.to_s.empty? ? '' : "#{field}:"
104
- if fielded_queries.size > 0
105
- q << (fielded_queries.size > 1 ? "#{field}(#{fielded_queries.join(' ')})" : "#{field}#{fielded_queries.to_s}")
116
+ fielded_queries.each do |fq|
117
+ q << "#{field}(#{fq})"
106
118
  end
107
119
  end
108
- q.join(' ')
120
+ q
109
121
  end
110
122
 
111
123
  def prep_value(val, quote=false)
@@ -33,7 +33,11 @@ module RSolr::HTTPClient
33
33
  else
34
34
  raise UnkownAdapterError.new("Name: #{adapter_name}")
35
35
  end
36
- Base.new RSolr::HTTPClient::Adapter.const_get(klass).new(url)
36
+ begin
37
+ Base.new RSolr::HTTPClient::Adapter.const_get(klass).new(url)
38
+ rescue URI::InvalidURIError
39
+ raise "#{$!} == #{url}"
40
+ end
37
41
  end
38
42
 
39
43
  class Base
data/lib/rsolr.rb CHANGED
@@ -7,7 +7,7 @@ proc {|base, files|
7
7
 
8
8
  module RSolr
9
9
 
10
- VERSION = '0.6.3'
10
+ VERSION = '0.6.4'
11
11
 
12
12
  autoload :Message, 'rsolr/message'
13
13
  autoload :Response, 'rsolr/response'
@@ -20,6 +20,7 @@ module RSolr
20
20
  # opts are sent to the adapter instance (:url for http, :dist_dir for :direct etc.)
21
21
  # and to the connection instance
22
22
  def self.connect(opts={})
23
+ opts = opts.to_mash
23
24
  adapter_name = opts[:adapter] ||= :http
24
25
  types = {
25
26
  :http=>'HTTP',
@@ -20,7 +20,7 @@ class ParamMappingTest < RSolrBaseTest
20
20
  output = mapper.map
21
21
 
22
22
  assert_equal "a query \"a phrase query\"", output[:q]
23
- assert_equal "a filter \"a phrase filter\"", output[:fq]
23
+ assert_equal ["a filter", "\"a phrase filter\""], output[:fq]
24
24
  assert_equal 0, output[:start]
25
25
  assert_equal 10, output[:rows]
26
26
  # facet.field can be specified multiple times, so we need an array
@@ -38,8 +38,8 @@ class ParamMappingTest < RSolrBaseTest
38
38
  mapper = Standard.new(input)
39
39
  output = mapper.map
40
40
 
41
- assert_equal "a query field:value blah \"a phrase\" phrase_field:\"phrase value\"", output[:q]
42
- assert_equal "a filter filter:field blah can_also_be_a:\"hash\"", output[:fq]
41
+ assert_equal "a query field:(value) blah \"a phrase\" phrase_field:(\"phrase value\")", output[:q]
42
+ assert_equal ["a filter", "filter:(field)", "blah", "can_also_be_a:(\"hash\")"], output[:fq]
43
43
  end
44
44
 
45
45
  def test_dismax
@@ -51,11 +51,11 @@ class ParamMappingTest < RSolrBaseTest
51
51
  }
52
52
  mapper = Dismax.new(input)
53
53
  output = mapper.map
54
- assert_equal 'can_be_a_string_hash_or_array:OK', output[:q.alt]
54
+ assert_equal 'can_be_a_string_hash_or_array:(OK)', output[:q.alt]
55
55
  assert output[:qf]=~/another_field_to_boost\^200/
56
56
  assert output[:qf]=~/a_field_to_boost\^20/
57
57
  assert_equal 'phrase_field^20', output[:pf]
58
- assert_equal 'field_to_use_for_boost_query:a test', output[:bq]
58
+ assert_equal 'field_to_use_for_boost_query:(a) test', output[:bq]
59
59
  end
60
60
 
61
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mwmitchell-rsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Mitchell
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-21 00:00:00 -08:00
12
+ date: 2009-01-26 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency