uri_service 0.2.3 → 0.2.4

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: 5d86291e7f55d8b02a1bda38a3ce2442c57369ed
4
- data.tar.gz: 1646c0c6ac51556df8823c9c23db7e1a64682692
3
+ metadata.gz: bc7a8ad42646a876ba2d722a8635dd64d0ec25d8
4
+ data.tar.gz: 77102259da8003218eb289fc4dae9f9eb25c0672
5
5
  SHA512:
6
- metadata.gz: 7b9a6958a9f48b28a238d79d66ac490e24317d1ffffaa4bfa8d5a29d6fc075b75bcae0c6ff8d6963f61937f499288b69543adfc59d7b2539ee644c254cf90cf6
7
- data.tar.gz: 3c50a6fd5cdf0d0f16092a8fd5be1e83a2af3a8d689cb9b580a339067374e1fc0dbcbe23836cfc7130d71e0b745d9cfa5d1cf170851aac951df09f247b352988
6
+ metadata.gz: 06aa62d6544f47d4704c8ae71e1cb7f7482e42bc97056e556d0999f75b522fc3b35edd110c74e40ea41fff8e09427081114179c551259cafca94d515cb45e540
7
+ data.tar.gz: eddc0dfab80498102100b6971a0ce4bb26a00a893c1da0f374961cf3d8d3ac185755215b3cdc7815f0f2a9463e97a70aad6a674e8b1f4d0a53fc73d61038ef80
@@ -21,6 +21,39 @@ class UriService::Client
21
21
  @rsolr_pool = ConnectionPool.new( size: opts['solr']['pool_size'], timeout: (opts['solr']['pool_timeout'].to_f/1000.to_f) ) { RSolr.connect(:url => opts['solr']['url']) }
22
22
  end
23
23
 
24
+ def reindex_all_terms(print_progress_to_console=false)
25
+ self.handle_database_disconnect do
26
+
27
+ if print_progress_to_console
28
+ puts "Getting database term count..."
29
+ total = @db[UriService::TERMS].count
30
+ reindex_counter = 0
31
+ puts "Number of terms to index: #{total.to_s}"
32
+ puts ""
33
+ end
34
+
35
+ # Need to use unambiguous order when using paged_each
36
+ @db[UriService::TERMS].order(:id).paged_each(:rows_per_fetch=>100) do |term_db_row|
37
+ self.send_term_to_solr(
38
+ term_db_row[:vocabulary_string_key],
39
+ term_db_row[:value],
40
+ term_db_row[:uri],
41
+ JSON.parse(term_db_row[:additional_fields]),
42
+ term_db_row[:is_local],
43
+ false)
44
+
45
+ if print_progress_to_console
46
+ reindex_counter += 1
47
+ print "\rIndexed #{reindex_counter.to_s} of #{total.to_s}"
48
+ end
49
+ end
50
+
51
+ puts "\n" + "Committing solr updates..." if print_progress_to_console
52
+ self.do_solr_commit
53
+ puts "Done." if print_progress_to_console
54
+ end
55
+ end
56
+
24
57
  def disconnect!
25
58
  unless @db.nil?
26
59
  db_reference = @db
@@ -60,30 +93,34 @@ class UriService::Client
60
93
  end
61
94
 
62
95
  def create_required_tables
63
- current_tables = @db.tables
96
+ self.handle_database_disconnect do
64
97
 
65
- unless current_tables.include?(UriService::VOCABULARIES)
66
- @db.create_table UriService::VOCABULARIES do |t|
67
- primary_key :id
68
- String :string_key, size: 255, index: true, unique: true
69
- String :display_label, size: 255
98
+ current_tables = @db.tables
99
+
100
+ unless current_tables.include?(UriService::VOCABULARIES)
101
+ @db.create_table UriService::VOCABULARIES do |t|
102
+ primary_key :id
103
+ String :string_key, size: 255, index: true, unique: true
104
+ String :display_label, size: 255
105
+ end
106
+ else
107
+ puts 'Skipped creation of table ' + UriService::VOCABULARIES.to_s + ' because it already exists.'
70
108
  end
71
- else
72
- puts 'Skipped creation of table ' + UriService::VOCABULARIES.to_s + ' because it already exists.'
73
- end
74
-
75
- unless current_tables.include?(UriService::TERMS)
76
- @db.create_table UriService::TERMS do |t|
77
- primary_key :id
78
- String :vocabulary_string_key, size: 255, index: true
79
- String :uri, text: true # This needs to be a text field because utf8 strings cannot be our desired 2000 characters long in MySQL. uri_hash will be used to verify uniqueness.
80
- String :uri_hash, fixed: true, size: 64, unique: true
81
- String :value, text: true
82
- TrueClass :is_local, default: false
83
- String :additional_fields, text: true
109
+
110
+ unless current_tables.include?(UriService::TERMS)
111
+ @db.create_table UriService::TERMS do |t|
112
+ primary_key :id
113
+ String :vocabulary_string_key, size: 255, index: true
114
+ String :uri, text: true # This needs to be a text field because utf8 strings cannot be our desired 2000 characters long in MySQL. uri_hash will be used to verify uniqueness.
115
+ String :uri_hash, fixed: true, size: 64, unique: true
116
+ String :value, text: true
117
+ TrueClass :is_local, default: false
118
+ String :additional_fields, text: true
119
+ end
120
+ else
121
+ puts 'Skipped creation of table ' + UriService::TERMS.to_s + ' because it already exists.'
84
122
  end
85
- else
86
- puts 'Skipped creation of table ' + UriService::TERMS.to_s + ' because it already exists.'
123
+
87
124
  end
88
125
  end
89
126
 
@@ -421,6 +458,12 @@ class UriService::Client
421
458
  end
422
459
  end
423
460
 
461
+ def do_solr_commit
462
+ @rsolr_pool.with do |rsolr|
463
+ rsolr.commit
464
+ end
465
+ end
466
+
424
467
  end
425
468
 
426
469
  class UriService::InvalidAdditionalFieldKeyError < StandardError;end
@@ -1,6 +1,6 @@
1
1
  module UriService
2
2
 
3
- VERSION = '0.2.3'
3
+ VERSION = '0.2.4'
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.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric O'Hanlon