solr4r 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5406b14611075ff4787018f75d1f11cb9c89a79b
4
- data.tar.gz: 1ed6e0ae00ebd920fe2aaddd7ce6c9d51ea9c1d4
3
+ metadata.gz: 9aabdc8bcfbbe6f6e020f57575dde3039db78d3e
4
+ data.tar.gz: 9e953a10513ce911d43892e38b993ec019d7c797
5
5
  SHA512:
6
- metadata.gz: 95f762843eaf9ecbdfe557df2f7eb786caf1e74ef54a006df1396dedfb1b1d3ff0ef23d75cd6d34bd6a7831015a7c1d26e10b3620a5301fa7373de2a1de021f3
7
- data.tar.gz: bccd496fa4035ba6a9b39d244bd120eed385cd25779f5a8c943729975c4da00a63a243535fac98a0b36b69eb0d446e42333c8789b20f0fdb259cce09faa09e9c
6
+ metadata.gz: a0520d856c12f475f91fe67b9bdea73429f02671612fefcabf8bdac584f5ffa30cf58e454a75e646b6ec52aa55b29d3ac9f24f87421e87bebf5c78188cd1514a
7
+ data.tar.gz: e85a0383e19a5a74af7c11d888cef0d49a01fd35783fafd3f7d95b8347f12a900af3badc3ce179a96013fc38267838d5c2c0a609d96082968d91fc1c55466cad
data/ChangeLog CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  = Revision history for solr4r
4
4
 
5
+ == 0.0.5 [2015-02-11]
6
+
7
+ * Fixed Solr4R::Result for unsupported types.
8
+ * Extended Solr4R::Result for
9
+ {facet counts}[https://wiki.apache.org/solr/SolrFacetingOverview].
10
+ * Extended Solr4R::Client and Solr4R::Document for
11
+ MoreLikeThis[https://wiki.apache.org/solr/MoreLikeThis] queries.
12
+ * Extended Solr4R::RequestUriExtension for nested params (via hashes).
13
+
5
14
  == 0.0.4 [2014-12-19]
6
15
 
7
16
  * Fixed Solr4R::Request#make_request to set request body if string (XML).
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to solr4r version 0.0.4
5
+ This documentation refers to solr4r version 0.0.5
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -25,7 +25,7 @@ Travis CI:: https://travis-ci.org/blackwinter/solr4r
25
25
 
26
26
  == LICENSE AND COPYRIGHT
27
27
 
28
- Copyright (C) 2014 Jens Wille
28
+ Copyright (C) 2014-2015 Jens Wille
29
29
 
30
30
  solr4r is free software: you can redistribute it and/or modify it
31
31
  under the terms of the GNU Affero General Public License as published by
data/lib/solr4r/client.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # solr4r -- A Ruby client for Apache Solr #
7
7
  # #
8
- # Copyright (C) 2014 Jens Wille #
8
+ # Copyright (C) 2014-2015 Jens Wille #
9
9
  # #
10
10
  # Mir is free software: you can redistribute it and/or modify it under the #
11
11
  # terms of the GNU Affero General Public License as published by the Free #
@@ -47,6 +47,8 @@ module Solr4R
47
47
 
48
48
  DEFAULT_UPDATE_PATH = 'update'
49
49
 
50
+ DEFAULT_MLT_PATH = 'mlt'
51
+
50
52
  SYSTEM_INFO_PATH = 'admin/info/system'
51
53
 
52
54
  MATCH_ALL_QUERY = '*:*'
@@ -60,8 +62,11 @@ module Solr4R
60
62
 
61
63
  self.logger = options.fetch(:logger, default_logger)
62
64
 
63
- self.builder = options.fetch(:builder) { forward_logger(Builder.new) }
64
- self.request = options.fetch(:request) { forward_logger(Request.new(uri)) }
65
+ self.builder = options.fetch(:builder) {
66
+ forward_logger(Builder.new) }
67
+
68
+ self.request = options.fetch(:request) {
69
+ forward_logger(Request.new(self, uri)) }
65
70
 
66
71
  self.default_params = options.fetch(:default_params, DEFAULT_PARAMS)
67
72
 
@@ -174,6 +179,10 @@ module Solr4R
174
179
  json(path, params.merge(q: query_string(params[:q])), options, &block)
175
180
  end
176
181
 
182
+ def more_like_this(params = {}, options = {}, path = DEFAULT_MLT_PATH, &block)
183
+ json_query(params, options, path, &block)
184
+ end
185
+
177
186
  def query_string(query)
178
187
  case query
179
188
  when nil
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # solr4r -- A Ruby client for Apache Solr #
7
7
  # #
8
- # Copyright (C) 2014 Jens Wille #
8
+ # Copyright (C) 2014-2015 Jens Wille #
9
9
  # #
10
10
  # Mir is free software: you can redistribute it and/or modify it under the #
11
11
  # terms of the GNU Affero General Public License as published by the Free #
@@ -30,7 +30,12 @@ module Solr4R
30
30
  class Document
31
31
 
32
32
  extend Forwardable
33
- def_delegators :to_hash, :[], :each
33
+
34
+ UNIQUE_KEY = 'id'
35
+
36
+ MLT_DEFAULT_FL = '*,score'
37
+
38
+ MLT_DEFAULT_ROWS = 5
34
39
 
35
40
  def initialize(result, hash)
36
41
  @result, @hash = result, hash
@@ -38,10 +43,22 @@ module Solr4R
38
43
 
39
44
  attr_reader :result
40
45
 
46
+ def_delegators :result, :client
47
+
48
+ def_delegators :to_hash, :[], :each, :to_json
49
+
41
50
  def to_hash
42
51
  @hash
43
52
  end
44
53
 
54
+ def more_like_this(fl = nil, params = {}, *args, &block)
55
+ client.more_like_this(params.merge(
56
+ q: { id: self[UNIQUE_KEY] },
57
+ fl: params.fetch(:fl, MLT_DEFAULT_FL),
58
+ rows: params.fetch(:rows, MLT_DEFAULT_ROWS),
59
+ 'mlt.fl' => Array(fl).join(',')), *args, &block)
60
+ end
61
+
45
62
  end
46
63
 
47
64
  end
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # solr4r -- A Ruby client for Apache Solr #
7
7
  # #
8
- # Copyright (C) 2014 Jens Wille #
8
+ # Copyright (C) 2014-2015 Jens Wille #
9
9
  # #
10
10
  # Mir is free software: you can redistribute it and/or modify it under the #
11
11
  # terms of the GNU Affero General Public License as published by the Free #
@@ -38,11 +38,13 @@ module Solr4R
38
38
 
39
39
  DEFAULT_USER_AGENT = "Solr4R/#{VERSION}"
40
40
 
41
- def initialize(base_uri, http_options = {})
42
- self.base_uri, self.http_options =
41
+ def initialize(client, base_uri, http_options = {})
42
+ @client, self.base_uri, self.http_options = client,
43
43
  URI(base_uri).extend(BaseUriExtension), http_options
44
44
  end
45
45
 
46
+ attr_reader :client
47
+
46
48
  def start
47
49
  self.http = Net::HTTP.start(base_uri.hostname, base_uri.port,
48
50
  { use_ssl: base_uri.scheme == 'https' }.merge(http_options))
@@ -67,7 +69,7 @@ module Solr4R
67
69
  req = prepare_request(path, options, &block)
68
70
  res = http.request(req)
69
71
 
70
- self.last_response = Response.new(
72
+ self.last_response = Response.new(self,
71
73
  request_body: req.body,
72
74
  request_headers: req.to_hash,
73
75
  request_method: req.method.downcase.to_sym,
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # solr4r -- A Ruby client for Apache Solr #
7
7
  # #
8
- # Copyright (C) 2014 Jens Wille #
8
+ # Copyright (C) 2014-2015 Jens Wille #
9
9
  # #
10
10
  # Mir is free software: you can redistribute it and/or modify it under the #
11
11
  # terms of the GNU Affero General Public License as published by the Free #
@@ -30,18 +30,25 @@ module Solr4R
30
30
 
31
31
  class Response
32
32
 
33
+ extend Forwardable
34
+
33
35
  DEFAULT_CHARSET = 'UTF-8'
34
36
 
35
37
  EVALUATE_METHODS = [:get, :post]
36
38
 
37
- def initialize(options)
39
+ def initialize(request, options)
40
+ @request = request
38
41
  options.each { |key, value| send("#{key}=", value) }
39
42
  @evaluate = EVALUATE_METHODS.include?(request_method)
40
43
  end
41
44
 
45
+ attr_reader :request
46
+
42
47
  attr_accessor :response_body, :response_charset, :response_code, :response_headers,
43
48
  :request_body, :request_method, :request_params, :request_url, :request_headers
44
49
 
50
+ def_delegators :request, :client
51
+
45
52
  def request_line
46
53
  '"%s %s" %d' % [request_method.upcase, request_url, response_code]
47
54
  end
data/lib/solr4r/result.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # solr4r -- A Ruby client for Apache Solr #
7
7
  # #
8
- # Copyright (C) 2014 Jens Wille #
8
+ # Copyright (C) 2014-2015 Jens Wille #
9
9
  # #
10
10
  # Mir is free software: you can redistribute it and/or modify it under the #
11
11
  # terms of the GNU Affero General Public License as published by the Free #
@@ -25,6 +25,7 @@
25
25
 
26
26
  require 'forwardable'
27
27
  require 'nuggets/hash/deep_fetch_mixin'
28
+ require 'nuggets/string/camelscore_mixin'
28
29
 
29
30
  require_relative 'document'
30
31
 
@@ -35,26 +36,27 @@ module Solr4R
35
36
  include Enumerable
36
37
 
37
38
  extend Forwardable
38
- def_delegators :to_hash, :fetch, :deep_fetch, :%
39
39
 
40
- def self.type_for(hash)
41
- constants.find { |const|
42
- if hash.key?(const.to_s.downcase)
40
+ def self.types_for(hash, mix = Nuggets::String::CamelscoreMixin)
41
+ constants.map { |const|
42
+ if hash.key?(const.to_s.extend(mix).underscore!)
43
43
  mod = const_get(const)
44
- return mod if mod.is_a?(Module)
44
+ mod if mod.is_a?(Module)
45
45
  end
46
- }
47
-
48
- raise TypeError, "could not find supported type: #{hash.keys.join(', ')}"
46
+ }.compact
49
47
  end
50
48
 
51
49
  def initialize(response, hash)
52
- extend(self.class.type_for(hash))
50
+ types = self.class.types_for(hash); extend(*types) unless types.empty?
53
51
  @response, @hash = response, hash.extend(Nuggets::Hash::DeepFetchMixin)
54
52
  end
55
53
 
56
54
  attr_reader :response
57
55
 
56
+ def_delegators :response, :client
57
+
58
+ def_delegators :to_hash, :fetch, :deep_fetch, :%
59
+
58
60
  def to_hash
59
61
  @hash
60
62
  end
@@ -64,7 +66,7 @@ module Solr4R
64
66
  end
65
67
 
66
68
  def each(&block)
67
- block ? _each(&block) : enum_for(:each)
69
+ block ? _each(&block) : enum_for(__method__)
68
70
  end
69
71
 
70
72
  def empty?
@@ -116,6 +118,30 @@ module Solr4R
116
118
 
117
119
  end
118
120
 
121
+ module FacetCounts
122
+
123
+ def facet_counts
124
+ fetch(__method__.to_s)
125
+ end
126
+
127
+ def facet_fields
128
+ return enum_for(__method__) unless block_given?
129
+
130
+ facet_counts.fetch(__method__.to_s).each { |key, value|
131
+ yield key, Hash[*value]
132
+ }
133
+ end
134
+
135
+ def facet_ranges
136
+ return enum_for(__method__) unless block_given?
137
+
138
+ facet_counts.fetch(__method__.to_s).each { |key, value|
139
+ yield key, value.merge('counts' => Hash[*value['counts']])
140
+ }
141
+ end
142
+
143
+ end
144
+
119
145
  end
120
146
 
121
147
  end
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # solr4r -- A Ruby client for Apache Solr #
7
7
  # #
8
- # Copyright (C) 2014 Jens Wille #
8
+ # Copyright (C) 2014-2015 Jens Wille #
9
9
  # #
10
10
  # Mir is free software: you can redistribute it and/or modify it under the #
11
11
  # terms of the GNU Affero General Public License as published by the Free #
@@ -42,16 +42,30 @@ module Solr4R
42
42
  def with_params(params)
43
43
  self.params, query = params, [self.query].compact
44
44
 
45
- params.each { |key, value|
46
- key = CGI.escape(key.to_s)
47
- Array(value).each { |val| query << "#{key}=#{CGI.escape(val.to_s)}" }
48
- }
45
+ params.each { |key, value| query_pairs(key, value).each { |k, v|
46
+ query << "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
47
+ } }
49
48
 
50
49
  self.query = query.join('&') unless query.empty?
51
50
 
52
51
  self
53
52
  end
54
53
 
54
+ private
55
+
56
+ def query_pairs(key, value, pairs = [])
57
+ if value.is_a?(Hash)
58
+ pairs << [key, true]
59
+
60
+ value.each { |sub, val|
61
+ query_pairs("#{key}.#{sub}", val, pairs) }
62
+ else
63
+ Array(value).each { |val| pairs << [key, val] }
64
+ end
65
+
66
+ pairs
67
+ end
68
+
55
69
  end
56
70
 
57
71
  end
@@ -4,7 +4,7 @@ module Solr4R
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- TINY = 4
7
+ TINY = 5
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solr4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -125,21 +125,18 @@ licenses:
125
125
  metadata: {}
126
126
  post_install_message: |2+
127
127
 
128
- solr4r-0.0.4 [2014-12-19]:
128
+ solr4r-0.0.5 [2015-02-11]:
129
129
 
130
- * Fixed Solr4R::Request#make_request to set request body if string (XML).
131
- * Fixed Solr4R::Builder#to_xml to replace illegal characters.
132
- * Added Solr4R::Response#success?.
133
- * Added Solr4R::Client#add_batch.
134
- * Added Solr4R::Client#query_string.
135
- * Added basic logging infrastructure.
130
+ * Fixed Solr4R::Result for unsupported types.
136
131
  * Extended Solr4R::Result for
137
- terms[https://wiki.apache.org/solr/TermsComponent] response.
138
- * Updated Solr4R::Client#json_query to use Solr4R::Client#query_string.
132
+ {facet counts}[https://wiki.apache.org/solr/SolrFacetingOverview].
133
+ * Extended Solr4R::Client and Solr4R::Document for
134
+ MoreLikeThis[https://wiki.apache.org/solr/MoreLikeThis] queries.
135
+ * Extended Solr4R::RequestUriExtension for nested params (via hashes).
139
136
 
140
137
  rdoc_options:
141
138
  - "--title"
142
- - solr4r Application documentation (v0.0.4)
139
+ - solr4r Application documentation (v0.0.5)
143
140
  - "--charset"
144
141
  - UTF-8
145
142
  - "--line-numbers"