uri_service 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa061d4a76679f11f545ef93aeeda1409d086a85
4
- data.tar.gz: cda87cf20d8b71717fa36086a4706421c0c46cce
3
+ metadata.gz: a34c4dd9a5b43b9111f59c0577fd2046bb2f00b9
4
+ data.tar.gz: 94d3fc905ad56a6aaabb9b0bcad622343877ebfe
5
5
  SHA512:
6
- metadata.gz: 9a3f1b9a03fac329bd363a9de844c2f485d4275609358349590c3aaa14c5081333366d7cf11bfba31b83a5660f8474df95818490ca9e3a73f23ea7a7ec88b5a5
7
- data.tar.gz: d5862ddf5f8c2971cc9d63d2dce2702677e7c4011849f1ae3bc7546f95886a446f45ba0d17eba2d6e167558f5d2dc711505dc7e8de99b6328427beb40ad5b85c
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
- Find a term in a vocabulary (after you've already added the term to the vocabulary):
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:
@@ -249,7 +249,7 @@ class UriService::Client
249
249
  end
250
250
 
251
251
  def find_term_by_uri(uri)
252
- UriService.client.rsolr_pool.with do |rsolr|
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
- UriService.client.rsolr_pool.with do |rsolr|
288
+ @rsolr_pool.with do |rsolr|
284
289
 
285
290
  solr_params = {
286
- :q => value_query == '' ? '*' : UriService.solr_escape(value_query),
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
  ##################
@@ -1,6 +1,6 @@
1
1
  module UriService
2
2
 
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
 
5
5
  def self.version
6
6
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric O'Hanlon