odba 1.1.3 → 1.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a275f0c5476fd282d1f7c67cce22d64357671f8
4
- data.tar.gz: 7832d2977f9d568801af283a522ea5833ca8bf99
3
+ metadata.gz: e6f43b3ebdb9aebac82426a5d6bbc9b6fea3e354
4
+ data.tar.gz: b4133fcad482006541b799afeaed9a68612d9d45
5
5
  SHA512:
6
- metadata.gz: 898f28dbabb3d7542ebeb6b7bbc3cf49934d036334da1f6042c82446189c8248a108903d0b285001b37a43ac0661c7e83d588680367378e7cc65dc3208eddefd
7
- data.tar.gz: 639fa00ebbb43378e0a2ce97205d0fc367d703a85872c321ecc802061b4a63e9e6e384665d53c495209afc263f7de8fd7f63e12846d8e3f251f35377d57269ff
6
+ metadata.gz: 6bc0fc59862d283549b16141f403176125c50e123d57b015bf68d25c1d4a36071c1dd7bda8587678810dff42f39992c7bd4861d84b6612e90b4c5efbb8974283
7
+ data.tar.gz: c584c8ed6af930ed0ffeb2ff43146285697ec34e758d1079247e2d02c3686f54416563e0c93b126058f7c44bc9dcf1ca91b25f4a7b39e0ed2190509feb0b35a9
data/History.txt CHANGED
@@ -1,8 +1,13 @@
1
+ === 1.1.3 / 13.12.2016
2
+
3
+ * Drop text search dictionaries/configuration before recreating
4
+ * Remove dictionary argument in fulltext search and index_definition
5
+
1
6
  === 1.1.3 / 12.12.2016
2
7
 
3
8
  * Avoid errors by always specifying "IF NOT EXISTS" when creating tables and indices
4
9
  * Add utility method get_server_version
5
- * Removed misleaading check in generate_dictionary
10
+ * Removed misleading check in generate_dictionary
6
11
 
7
12
  === 1.1.2 / 10.05.2016
8
13
 
data/lib/odba/index.rb CHANGED
@@ -23,7 +23,7 @@ module ODBA
23
23
  ]
24
24
  end
25
25
  attr_accessor :origin_klass, :target_klass, :resolve_origin, :resolve_target,
26
- :resolve_search_term, :index_name, :dictionary, :class_filter
26
+ :resolve_search_term, :index_name, :class_filter
27
27
  def initialize(index_definition, origin_module)
28
28
  @origin_klass = origin_module.instance_eval(index_definition.origin_klass.to_s)
29
29
  @target_klass = origin_module.instance_eval(index_definition.target_klass.to_s)
@@ -31,7 +31,6 @@ module ODBA
31
31
  @resolve_target = index_definition.resolve_target
32
32
  @index_name = index_definition.index_name
33
33
  @resolve_search_term = index_definition.resolve_search_term
34
- @dictionary = index_definition.dictionary
35
34
  @class_filter = index_definition.class_filter
36
35
  end
37
36
  def current_origin_ids(target_id) # :nodoc:
@@ -381,15 +380,12 @@ module ODBA
381
380
  end
382
381
  def fetch_ids(search_term, meta=nil) # :nodoc:
383
382
  limit = meta.respond_to?(:limit) && meta.limit
384
- rows = ODBA.storage.retrieve_from_fulltext_index(@index_name,
385
- search_term, @dictionary, limit)
383
+ rows = ODBA.storage.retrieve_from_fulltext_index(@index_name, search_term, limit)
386
384
  set_relevance(meta, rows)
387
385
  rows.collect { |row| row.at(0) }
388
386
  end
389
387
  def do_update_index(origin_id, search_text, target_id=nil) # :nodoc:
390
- ODBA.storage.update_fulltext_index(@index_name, origin_id,
391
- search_text, target_id,
392
- @dictionary)
388
+ ODBA.storage.update_fulltext_index(@index_name, origin_id, search_text, target_id)
393
389
  end
394
390
  end
395
391
  end
@@ -5,8 +5,8 @@ module ODBA
5
5
  # IndexDefinition is a convenience class. Load a yaml-dump of this and pass it
6
6
  # to Cache#create_index to introduce new indices
7
7
  class IndexDefinition
8
- attr_accessor :index_name, :dictionary, :origin_klass,
9
- :target_klass, :resolve_search_term, :resolve_target,
8
+ attr_accessor :index_name, :origin_klass,
9
+ :target_klass, :resolve_search_term, :resolve_target,
10
10
  :resolve_origin, :fulltext, :init_source, :class_filter
11
11
  def initialize
12
12
  @index_name = ""
@@ -15,7 +15,6 @@ module ODBA
15
15
  @resolve_search_term = ""
16
16
  @resolve_target = ""
17
17
  @resolve_origin = ""
18
- @dictionary = ""
19
18
  @init_source = ""
20
19
  @fulltext = false
21
20
  @class_filter = :is_a?
data/lib/odba/storage.rb CHANGED
@@ -158,11 +158,14 @@ CREATE INDEX IF NOT EXISTS target_id_#{table_name} ON #{table_name}(target_id);
158
158
  end
159
159
  def create_fulltext_index(table_name)
160
160
  self.dbi.do <<-SQL
161
- CREATE TABLE IF NOT EXISTS #{table_name} (
161
+ DROP TABLE IF EXISTS #{table_name};
162
+ SQL
163
+ self.dbi.do <<-SQL
164
+ CREATE TABLE IF NOT EXISTS #{table_name} (
162
165
  origin_id INTEGER,
163
166
  search_term tsvector,
164
167
  target_id INTEGER
165
- );
168
+ ) WITH OIDS ;
166
169
  SQL
167
170
  #index origin_id
168
171
  self.dbi.do <<-SQL
@@ -178,12 +181,15 @@ CREATE INDEX IF NOT EXISTS target_id_#{table_name} ON #{table_name}(target_id);
178
181
  SQL
179
182
  end
180
183
  def create_index(table_name)
184
+ self.dbi.do <<-SQL
185
+ DROP TABLE IF EXISTS #{table_name};
186
+ SQL
181
187
  self.dbi.do <<-SQL
182
188
  CREATE TABLE IF NOT EXISTS #{table_name} (
183
189
  origin_id INTEGER,
184
190
  search_term TEXT,
185
191
  target_id INTEGER
186
- );
192
+ ) WITH OIDS;
187
193
  SQL
188
194
  #index origin_id
189
195
  self.dbi.do <<-SQL
@@ -205,7 +211,7 @@ CREATE INDEX IF NOT EXISTS target_id_#{table_name} ON #{table_name}(target_id);
205
211
  Thread.current[:txn] || @dbi
206
212
  end
207
213
  def drop_index(index_name)
208
- self.dbi.do "DROP TABLE #{index_name}"
214
+ self.dbi.do "DROP TABLE IF EXISTS #{index_name}"
209
215
  end
210
216
  def delete_index_element(index_name, odba_id, id_name)
211
217
  self.dbi.do <<-SQL, odba_id
@@ -301,13 +307,20 @@ CREATE INDEX IF NOT EXISTS target_id_#{table_name} ON #{table_name}(target_id);
301
307
  def generate_dictionary(language)
302
308
  # postgres searches for the dictionary file in the directory share/tsearch_data of it installation location
303
309
  # By default under gentoo, this is /usr/share/postgresql/tsearch_data/
310
+ # Use /usr/local/pgsql-10.1/bin/pg_config --sharedir to get the current value
304
311
  # As we have no way to get the current installation path, we do not check whether the files are present or not
305
312
  file='fulltext'
306
313
  # setup configuration
314
+ self.dbi.do <<-SQL
315
+ DROP TEXT SEARCH DICTIONARY IF EXISTS public.default_#{language};
316
+ SQL
307
317
  self.dbi.do <<-SQL
308
318
  CREATE TEXT SEARCH CONFIGURATION public.default_#{language} ( COPY = pg_catalog.#{language} );
309
319
  SQL
310
320
  # ispell
321
+ self.dbi.do <<-SQL
322
+ DROP TEXT SEARCH DICTIONARY IF EXISTS #{language}_ispell;
323
+ SQL
311
324
  self.dbi.do <<-SQL
312
325
  CREATE TEXT SEARCH DICTIONARY #{language}_ispell (
313
326
  TEMPLATE = ispell,
@@ -460,7 +473,7 @@ CREATE INDEX IF NOT EXISTS target_id_#{table_name} ON #{table_name}(target_id);
460
473
  end
461
474
  self.dbi.select_all(sql, *values)
462
475
  end
463
- def retrieve_from_fulltext_index(index_name, search_term, dict, limit=nil)
476
+ def retrieve_from_fulltext_index(index_name, search_term, limit=nil)
464
477
  ## this combination of gsub statements solves the problem of
465
478
  # properly escaping strings of this form: "(2:1)" into
466
479
  # '\(2\:1\)' (see test_retrieve_from_fulltext_index)
@@ -468,19 +481,19 @@ CREATE INDEX IF NOT EXISTS target_id_#{table_name} ON #{table_name}(target_id);
468
481
  .gsub(/[():]/i, '\\ \\&').gsub(/\s/, '')
469
482
  sql = <<-EOQ
470
483
  SELECT target_id,
471
- max(ts_rank(search_term, to_tsquery(?, ?))) AS relevance
484
+ max(ts_rank(search_term, to_tsquery(?))) AS relevance
472
485
  FROM #{index_name}
473
- WHERE search_term @@ to_tsquery(?, ?)
486
+ WHERE search_term @@ to_tsquery(?)
474
487
  GROUP BY target_id
475
488
  ORDER BY relevance DESC
476
489
  EOQ
477
490
  if(limit)
478
491
  sql << " LIMIT #{limit}"
479
492
  end
480
- self.dbi.select_all(sql, dict, term, dict, term)
493
+ self.dbi.select_all(sql, term, term)
481
494
  rescue DBI::ProgrammingError => e
482
495
  warn("ODBA::Storage.retrieve_from_fulltext_index rescued a DBI::ProgrammingError(#{e.message}). Query:")
483
- warn("self.dbi.select_all(#{sql}, #{dict}, #{term}, #{dict}, #{term})")
496
+ warn("self.dbi.select_all(#{sql}, #{term}, #{term})")
484
497
  warn("returning empty result")
485
498
  []
486
499
  end
@@ -583,17 +596,21 @@ WHERE origin_id = ?
583
596
  def update_fulltext_index(index_name, origin_id, search_term, target_id, dict)
584
597
  search_term = search_term.gsub(/\s+/, ' ').strip
585
598
  if(target_id)
586
- self.dbi.do <<-SQL, origin_id, dict, search_term, target_id
599
+ value = <<-SQL, origin_id.to_s, search_term, target_id
587
600
  INSERT INTO #{index_name} (origin_id, search_term, target_id)
588
- VALUES (?, to_tsvector(?, ?), ?)
601
+ VALUES (?, to_tsvector(?), ?)
602
+ SQL
603
+ result = self.dbi.do <<-SQL, origin_id.to_s, search_term, target_id
604
+ INSERT INTO #{index_name} (origin_id, search_term, target_id)
605
+ VALUES (?, to_tsvector(?), ?)
589
606
  SQL
590
607
  else
591
- self.dbi.do <<-SQL, dict, search_term, origin_id
592
- UPDATE #{index_name} SET search_term=to_tsvector(?, ?)
608
+ result = self.dbi.do <<-SQL, search_term, origin_id
609
+ UPDATE #{index_name} SET search_term=to_tsvector(?)
593
610
  WHERE origin_id=?
594
611
  SQL
595
612
  end
596
- end
613
+ end
597
614
  def update_index(index_name, origin_id, search_term, target_id)
598
615
  if(target_id)
599
616
  self.dbi.do <<-SQL, origin_id, search_term, target_id
data/lib/odba/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  class Odba
4
- VERSION = '1.1.3'
4
+ VERSION = '1.1.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaomi Hatakeyama, Zeno R.R. Davatz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ydbi