solr_lite 0.0.8 → 0.0.9
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 +4 -4
- data/lib/response.rb +54 -3
- data/lib/solr.rb +43 -27
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e3b829f8f239974df1f4e84eff2803d00210c7ee60561cd353b7a9174ff6dd96
|
|
4
|
+
data.tar.gz: 35fcb552f2ad0384b4ae9312287791f4fc46850aa130852efe19a5adfdea6a69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4eacb399b8c0afadf285d706b736612684a82d06acae08929688d87cbf95c5035cc3dfc7bcab3fe9157960f68e5ee7477b4f57c3fa3324cdc212a805342ba5e2
|
|
7
|
+
data.tar.gz: 61a6fba302260f1d992346196e5cf0ea9f5651dd890f2ec4583cbdbbbdbf2daff30df7f14931824a9e1ed5cd80499a56631bf4576570771a2f036d5e5d9f202c
|
data/lib/response.rb
CHANGED
|
@@ -15,7 +15,8 @@ module SolrLite
|
|
|
15
15
|
set_facet_values()
|
|
16
16
|
|
|
17
17
|
# This value can be set by the client if we want to use a custom
|
|
18
|
-
# representation of solr_docs
|
|
18
|
+
# representation of solr_docs while preserving the entire Response
|
|
19
|
+
# object.
|
|
19
20
|
@items = []
|
|
20
21
|
end
|
|
21
22
|
|
|
@@ -39,7 +40,33 @@ module SolrLite
|
|
|
39
40
|
# Total number documents found in solr
|
|
40
41
|
# usually larger than solr_docs.count
|
|
41
42
|
def num_found
|
|
42
|
-
|
|
43
|
+
|
|
44
|
+
if @solr_response["response"] != nil
|
|
45
|
+
# Normal Solr query
|
|
46
|
+
return @solr_response["response"]["numFound"]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if @solr_response["grouped"] != nil
|
|
50
|
+
# Grouped Solr query.
|
|
51
|
+
total = 0
|
|
52
|
+
@solr_response["grouped"].keys.each do |key|
|
|
53
|
+
total += @solr_response["grouped"][key]["matches"]
|
|
54
|
+
end
|
|
55
|
+
return total
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
return 0
|
|
59
|
+
rescue
|
|
60
|
+
0
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Total number documents found in Solr
|
|
64
|
+
# for a given group field/value/
|
|
65
|
+
def num_found_for_group(group_field, group_value)
|
|
66
|
+
group = @solr_response["grouped"][group_field]["groups"]
|
|
67
|
+
docs_for_value = group.find {|x| x["groupValue"] == group_value }
|
|
68
|
+
return 0 if docs_for_value == nil
|
|
69
|
+
docs_for_value["doclist"]["numFound"]
|
|
43
70
|
rescue
|
|
44
71
|
0
|
|
45
72
|
end
|
|
@@ -59,7 +86,16 @@ module SolrLite
|
|
|
59
86
|
|
|
60
87
|
# Start position for retrieval (used for pagination)
|
|
61
88
|
def start
|
|
62
|
-
@solr_response["response"]
|
|
89
|
+
if @solr_response["response"] != nil
|
|
90
|
+
@solr_response["response"]["start"].to_i
|
|
91
|
+
else
|
|
92
|
+
# For grouped responses
|
|
93
|
+
# (I believe we could use this value for grouped and not-grouped
|
|
94
|
+
# responses, but for backwards compatibility and since I have not
|
|
95
|
+
# tested it for non-grouped responses, for now we only use it for
|
|
96
|
+
# grouped responses.)
|
|
97
|
+
@solr_response["responseHeader"]["params"]["start"].to_i
|
|
98
|
+
end
|
|
63
99
|
rescue
|
|
64
100
|
0
|
|
65
101
|
end
|
|
@@ -78,6 +114,21 @@ module SolrLite
|
|
|
78
114
|
@solr_response["response"]["docs"]
|
|
79
115
|
end
|
|
80
116
|
|
|
117
|
+
# Groups in the solr_docs (see Solr.search_group())
|
|
118
|
+
def solr_groups(group_field)
|
|
119
|
+
return [] if @solr_response["grouped"] == nil
|
|
120
|
+
@solr_response["grouped"][group_field]["groups"].map {|x| x["groupValue"]}
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Documents for a given group field and value (see Solr.search_group())
|
|
124
|
+
def solr_docs_for_group(group_field, group_value)
|
|
125
|
+
group = @solr_response["grouped"][group_field]["groups"]
|
|
126
|
+
docs_for_value = group.find {|x| x["groupValue"] == group_value }
|
|
127
|
+
return [] if docs_for_value == nil
|
|
128
|
+
docs = docs_for_value["doclist"]["docs"]
|
|
129
|
+
docs
|
|
130
|
+
end
|
|
131
|
+
|
|
81
132
|
def facets
|
|
82
133
|
@params.facets
|
|
83
134
|
end
|
data/lib/solr.rb
CHANGED
|
@@ -71,34 +71,13 @@ module SolrLite
|
|
|
71
71
|
# @return [SolrLite::Response] The result of the search.
|
|
72
72
|
#
|
|
73
73
|
def search(params, extra_fqs = [], qf = nil, mm = nil, debug = false)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
query_string += "&wt=json&indent=on"
|
|
81
|
-
query_string += "&" + params.to_solr_query_string(extra_fqs)
|
|
82
|
-
query_string += "&q.op=AND"
|
|
83
|
-
|
|
84
|
-
if qf != nil
|
|
85
|
-
query_string += "&qf=#{CGI.escape(qf)}"
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
if mm != nil
|
|
89
|
-
query_string += "&mm=#{CGI.escape(mm)}"
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
if debug
|
|
93
|
-
query_string += "&debugQuery=true"
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
if @def_type != nil
|
|
97
|
-
query_string += "&defType=#{@def_type}"
|
|
98
|
-
end
|
|
74
|
+
http_response = search_core(params, extra_fqs, qf, mm, debug, nil, 0)
|
|
75
|
+
response = Response.new(http_response, params)
|
|
76
|
+
response
|
|
77
|
+
end
|
|
99
78
|
|
|
100
|
-
|
|
101
|
-
http_response =
|
|
79
|
+
def search_group(params, extra_fqs = [], qf = nil, mm = nil, debug = false, group_field, group_limit)
|
|
80
|
+
http_response = search_core(params, extra_fqs, qf, mm, debug, group_field, group_limit)
|
|
102
81
|
response = Response.new(http_response, params)
|
|
103
82
|
response
|
|
104
83
|
end
|
|
@@ -176,6 +155,43 @@ module SolrLite
|
|
|
176
155
|
end
|
|
177
156
|
|
|
178
157
|
private
|
|
158
|
+
def search_core(params, extra_fqs, qf, mm, debug, group_field, group_limit)
|
|
159
|
+
if params.fl != nil
|
|
160
|
+
query_string = "fl=#{params.fl.join(",")}"
|
|
161
|
+
else
|
|
162
|
+
query_string = "" # use Solr defaults
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
query_string += "&wt=json&indent=on"
|
|
166
|
+
query_string += "&" + params.to_solr_query_string(extra_fqs)
|
|
167
|
+
query_string += "&q.op=AND"
|
|
168
|
+
|
|
169
|
+
if qf != nil
|
|
170
|
+
query_string += "&qf=#{CGI.escape(qf)}"
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
if mm != nil
|
|
174
|
+
query_string += "&mm=#{CGI.escape(mm)}"
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
if debug
|
|
178
|
+
query_string += "&debugQuery=true"
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
if group_field != nil
|
|
182
|
+
# See https://lucene.apache.org/solr/guide/7_0/result-grouping.html
|
|
183
|
+
# and https://wiki.apache.org/solr/FieldCollapsing
|
|
184
|
+
query_string += "&group=true&group.field=#{group_field}&group.limit=#{group_limit}"
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
if @def_type != nil
|
|
188
|
+
query_string += "&defType=#{@def_type}"
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
url = "#{@solr_url}/select?#{query_string}"
|
|
192
|
+
http_response = http_get(url)
|
|
193
|
+
end
|
|
194
|
+
|
|
179
195
|
def http_post_json(url, payload)
|
|
180
196
|
content_type = "application/json"
|
|
181
197
|
http_response = http_post(url, payload, content_type)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solr_lite
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hector Correa
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-01-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A lightweight gem to connect to Solr and run queries. Requires no extra
|
|
14
14
|
dependencies.
|