uri_service 0.2.1 → 0.2.2
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/README.md +15 -1
- data/lib/uri_service/client.rb +41 -3
- data/lib/uri_service/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a34c4dd9a5b43b9111f59c0577fd2046bb2f00b9
|
4
|
+
data.tar.gz: 94d3fc905ad56a6aaabb9b0bcad622343877ebfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5566e17cb45ae010a502a9afbcd06325c9b56fe7acde4114861847b64b2f9dd91164ac93e8b6144081f17d21289f2442552b8553e9b342416be30c5b7669113f
|
7
|
+
data.tar.gz: 2b3ebc888583e86f6ee879b03416524c7cf7b10fde9dc184dd501238035b3a0ce95a40a51c2316ba09bd25007f8f9eff0d74549688fcae05c22eceff33ca8c18
|
data/README.md
CHANGED
@@ -118,6 +118,13 @@ Create a vocabulary:
|
|
118
118
|
UriService.client.create_vocabulary('names', 'Names')
|
119
119
|
```
|
120
120
|
|
121
|
+
Listing vocabularies:
|
122
|
+
```ruby
|
123
|
+
limit = 10
|
124
|
+
start = 0
|
125
|
+
UriService.client.list_vocabularies(limit, start)
|
126
|
+
```
|
127
|
+
|
121
128
|
Create a term in a vocabulary:
|
122
129
|
```ruby
|
123
130
|
# Creates a term in the 'names' vocabulary, using the given value, uri and a couple of custom key-value pairs
|
@@ -132,7 +139,7 @@ Create a LOCAL term in a vocabulary (when you don't have a URI for your term):
|
|
132
139
|
UriService.client.create_local_term('names', 'Baby, Newborn', {'is_baby' => true})
|
133
140
|
```
|
134
141
|
|
135
|
-
|
142
|
+
Searching by string query for a term in a vocabulary:
|
136
143
|
```ruby
|
137
144
|
UriService.client.find_terms_by_query('names', 'batman')
|
138
145
|
# =>
|
@@ -152,6 +159,13 @@ UriService.client.find_terms_by_query('names', 'batman')
|
|
152
159
|
# ]
|
153
160
|
```
|
154
161
|
|
162
|
+
Listing terms in a vocabulary:
|
163
|
+
```ruby
|
164
|
+
limit = 10
|
165
|
+
start = 0
|
166
|
+
UriService.client.list_terms('names', limit, start)
|
167
|
+
```
|
168
|
+
|
155
169
|
### Running Integration Tests (for developers):
|
156
170
|
|
157
171
|
Integration tests are great and we should run them. Here's how:
|
data/lib/uri_service/client.rb
CHANGED
@@ -249,7 +249,7 @@ class UriService::Client
|
|
249
249
|
end
|
250
250
|
|
251
251
|
def find_term_by_uri(uri)
|
252
|
-
|
252
|
+
@rsolr_pool.with do |rsolr|
|
253
253
|
response = rsolr.get('select', params: { :q => '*:*', :fq => 'uri:' + UriService.solr_escape(uri) })
|
254
254
|
if response['response']['numFound'] == 1
|
255
255
|
return term_solr_doc_to_frozen_term_hash(response['response']['docs'].first)
|
@@ -279,11 +279,16 @@ class UriService::Client
|
|
279
279
|
end
|
280
280
|
|
281
281
|
def find_terms_by_query(vocabulary_string_key, value_query, limit=10, start=0)
|
282
|
+
|
283
|
+
if value_query.blank?
|
284
|
+
return self.list_terms(vocabulary_string_key, limit, start)
|
285
|
+
end
|
286
|
+
|
282
287
|
terms_to_return = []
|
283
|
-
|
288
|
+
@rsolr_pool.with do |rsolr|
|
284
289
|
|
285
290
|
solr_params = {
|
286
|
-
:q =>
|
291
|
+
:q => UriService.solr_escape(value_query),
|
287
292
|
:fq => 'vocabulary_string_key:' + UriService.solr_escape(vocabulary_string_key),
|
288
293
|
:rows => limit,
|
289
294
|
:start => start
|
@@ -299,6 +304,39 @@ class UriService::Client
|
|
299
304
|
return terms_to_return
|
300
305
|
end
|
301
306
|
|
307
|
+
################
|
308
|
+
# List methods #
|
309
|
+
################
|
310
|
+
|
311
|
+
# Lists vocabularies alphabetically (by string key) and supports paging through results.
|
312
|
+
def list_vocabularies(limit=10, start=0)
|
313
|
+
db_rows = @db[UriService::VOCABULARIES].order(:string_key).limit(limit, start)
|
314
|
+
return db_rows.map{|row| row.except(:id).stringify_keys!}
|
315
|
+
end
|
316
|
+
|
317
|
+
# Lists terms alphabetically and supports paging through results.
|
318
|
+
# Useful for browsing through a term list without a query.
|
319
|
+
def list_terms(vocabulary_string_key, limit=10, start=0)
|
320
|
+
terms_to_return = []
|
321
|
+
@rsolr_pool.with do |rsolr|
|
322
|
+
|
323
|
+
solr_params = {
|
324
|
+
:fq => 'vocabulary_string_key:' + UriService.solr_escape(vocabulary_string_key),
|
325
|
+
:sort => 'value_ssort asc',
|
326
|
+
:rows => limit,
|
327
|
+
:start => start
|
328
|
+
}
|
329
|
+
|
330
|
+
response = rsolr.get('select', params: solr_params)
|
331
|
+
if response['response']['numFound'] > 0
|
332
|
+
response['response']['docs'].each do |doc|
|
333
|
+
terms_to_return << term_solr_doc_to_frozen_term_hash(doc)
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
return terms_to_return
|
338
|
+
end
|
339
|
+
|
302
340
|
##################
|
303
341
|
# Delete methods #
|
304
342
|
##################
|
data/lib/uri_service/version.rb
CHANGED