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 +4 -4
- data/lib/uri_service/client.rb +64 -21
- 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: bc7a8ad42646a876ba2d722a8635dd64d0ec25d8
|
4
|
+
data.tar.gz: 77102259da8003218eb289fc4dae9f9eb25c0672
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06aa62d6544f47d4704c8ae71e1cb7f7482e42bc97056e556d0999f75b522fc3b35edd110c74e40ea41fff8e09427081114179c551259cafca94d515cb45e540
|
7
|
+
data.tar.gz: eddc0dfab80498102100b6971a0ce4bb26a00a893c1da0f374961cf3d8d3ac185755215b3cdc7815f0f2a9463e97a70aad6a674e8b1f4d0a53fc73d61038ef80
|
data/lib/uri_service/client.rb
CHANGED
@@ -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
|
-
|
96
|
+
self.handle_database_disconnect do
|
64
97
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
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
|
data/lib/uri_service/version.rb
CHANGED