groonga-client-rails 0.9.6 → 0.9.7

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: 2ca5a60fd3fca5df8832cd9c8be6683466666614
4
- data.tar.gz: 7da2fe87adb1ba2e2b2c9f0bee00edcb84581a0a
3
+ metadata.gz: a5944798b653ef748f6429cdd1fdb0a558c89654
4
+ data.tar.gz: 1c78060794d0cf29cef4557f57ff9d1e13d50b50
5
5
  SHA512:
6
- metadata.gz: 114bb69be2a9d780fc5d4864f4f16fd902902046fa8895bd54a1174f64c96b2245425e255d93aad06984be15e0ea4e087bab119f65907fc18596eba53d7c82f7
7
- data.tar.gz: 220a17172ebb90296290974f7232a56f3e54a9878155a7b9b45b6d70779f1168bbd5ff6b20fa48b752957ef89776dd32fcfc7138dcaa3b5ee0c4a016cc9f6b13
6
+ metadata.gz: 6de16e66a42cd4cf2eb103c904dd52d5709c7de1f6d6de76b3ab493adc8fb28a656cb35a9eeb4cec175a09d9beecb73d68535787690b57eade16fd05868a3237
7
+ data.tar.gz: 48f6ef9c6225805038aca00ca820835676fe1fc6752dbe8259c5618265d66aed2f8672f60627a7ff5ab203d10c6cbfd8dcb1d57369197cc94a86fba7af924426
@@ -1,5 +1,15 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.9.7 - 2016-12-22
4
+
5
+ ### Improvements
6
+
7
+ * Supported reference column.
8
+
9
+ * Added response error checks on synchronization.
10
+
11
+ * Supported disabling normalizer.
12
+
3
13
  ## 0.9.6 - 2016-12-21
4
14
 
5
15
  ### Improvements
@@ -17,7 +17,7 @@
17
17
  module Groonga
18
18
  class Client
19
19
  module Rails
20
- VERSION = "0.9.6"
20
+ VERSION = "0.9.7"
21
21
  end
22
22
  end
23
23
  end
@@ -60,6 +60,10 @@ module Groonga
60
60
  @options[:type] || "Text"
61
61
  end
62
62
 
63
+ def normalizer
64
+ @options[:normalizer]
65
+ end
66
+
63
67
  def text_family_type?
64
68
  case type
65
69
  when "ShortText", "Text", "LongText"
@@ -73,6 +77,10 @@ module Groonga
73
77
  @options[:vector]
74
78
  end
75
79
 
80
+ def reference?
81
+ @options[:reference]
82
+ end
83
+
76
84
  def have_index?
77
85
  @options[:index]
78
86
  end
@@ -33,11 +33,10 @@ module Groonga
33
33
  current_table = find_current_table
34
34
  return if current_table # TODO: validation
35
35
 
36
- Client.open do |client|
37
- client.table_create(:name => @schema.table,
38
- :flags => "TABLE_PAT_KEY",
39
- :key_type => "ShortText")
40
- end
36
+ execute(:table_create,
37
+ :name => @schema.table,
38
+ :flags => "TABLE_PAT_KEY",
39
+ :key_type => "ShortText")
41
40
  end
42
41
 
43
42
  def sync_columns
@@ -49,26 +48,50 @@ module Groonga
49
48
 
50
49
  def sync_column(column, current_column)
51
50
  if current_column.nil?
52
- Client.open do |client|
53
- flags = []
54
- if column.vector?
55
- flags << "COLUMN_VECTOR"
56
- else
57
- flags << "COLUMN_SCALAR"
58
- end
59
- client.column_create(:table => @schema.table,
60
- :name => column.name,
61
- :type => column.type,
62
- :flags => flags.join("|"))
51
+ flags = []
52
+ if column.vector?
53
+ flags << "COLUMN_VECTOR"
54
+ else
55
+ flags << "COLUMN_SCALAR"
56
+ end
57
+ if column.reference?
58
+ reference_table_name = generate_reference_table_name(column)
59
+ sync_reference_table(column, reference_table_name)
60
+ type = reference_table_name
61
+ else
62
+ type = column.type
63
63
  end
64
+ execute(:column_create,
65
+ :table => @schema.table,
66
+ :name => column.name,
67
+ :type => type,
68
+ :flags => flags.join("|"))
64
69
  end
65
70
 
66
71
  sync_column_index(column, current_column)
67
72
  end
68
73
 
74
+ def sync_reference_table(column, reference_table_name)
75
+ return if @current_schema.tables[reference_table_name]
76
+
77
+ parameters = {
78
+ :name => reference_table_name,
79
+ :flags => "TABLE_PAT_KEY",
80
+ }
81
+ parameters[:key_type] = column.type
82
+ if column.text_family_type?
83
+ parameters[:normalizer] = decide_normalizer(column.normalizer)
84
+ end
85
+ execute(:table_create, parameters)
86
+ end
87
+
69
88
  def sync_column_index(column, current_column)
70
89
  if column.have_index?
71
- lexicon_name = "lexicon_#{@schema.table}_#{column.name}"
90
+ if column.reference?
91
+ lexicon_name = generate_reference_table_name(column)
92
+ else
93
+ lexicon_name = generate_lexicon_name(column)
94
+ end
72
95
  index_column_name = "index"
73
96
  if current_column
74
97
  indexes = current_column.indexes
@@ -78,7 +101,7 @@ module Groonga
78
101
  indexes.each do |index|
79
102
  return if index.full_name == "#{lexicon_name}.#{index_column_name}"
80
103
  end
81
- sync_lexicon(column, lexicon_name)
104
+ sync_lexicon(column, lexicon_name) unless column.reference?
82
105
  create_index_column(column, lexicon_name, index_column_name)
83
106
  else
84
107
  remove_indexes(current_column)
@@ -95,37 +118,35 @@ module Groonga
95
118
  if column.have_full_text_search_index?
96
119
  parameters[:key_type] = "ShortText"
97
120
  parameters[:default_tokenizer] = "TokenBigram"
98
- parameters[:normalizer] = "NormalizerAuto"
121
+ parameters[:normalizer] = decide_normalizer(column.normalizer)
122
+ elsif column.reference?
123
+ parameters[:key_type] = generate_reference_table_name(column)
99
124
  else
100
125
  parameters[:key_type] = column.type
101
126
  if column.text_family_type?
102
- parameters[:normalizer] = "NormalizerAuto"
127
+ parameters[:normalizer] = decide_normalizer(column.normalizer)
103
128
  end
104
129
  end
105
- Client.open do |client|
106
- client.table_create(parameters)
107
- end
130
+ execute(:table_create, parameters)
108
131
  end
109
132
 
110
133
  def create_index_column(column, lexicon_name, index_column_name)
111
134
  flags = "COLUMN_INDEX"
112
135
  flags += "|WITH_POSITION" if column.have_full_text_search_index?
113
- Client.open do |client|
114
- client.column_create(:table => lexicon_name,
115
- :name => index_column_name,
116
- :flags => flags,
117
- :type => @schema.table,
118
- :source => column.name)
119
- end
136
+ execute(:column_create,
137
+ :table => lexicon_name,
138
+ :name => index_column_name,
139
+ :flags => flags,
140
+ :type => @schema.table,
141
+ :source => column.name)
120
142
  end
121
143
 
122
144
  def remove_indexes(current_column)
123
145
  return if current_column.nil?
124
146
  current_column.indexes.each do |index|
125
- Client.open do |client|
126
- clinet.column_remove(:table => index.table.name,
127
- :name => index.name)
128
- end
147
+ execute(:column_remove,
148
+ :table => index.table.name,
149
+ :name => index.name)
129
150
  end
130
151
  end
131
152
 
@@ -141,6 +162,32 @@ module Groonga
141
162
  current_table.columns
142
163
  end
143
164
  end
165
+
166
+ def decide_normalizer(custom_normalizer)
167
+ if custom_normalizer == false
168
+ nil
169
+ else
170
+ custom_normalizer || "NormalizerAuto"
171
+ end
172
+ end
173
+
174
+ def execute(name, parameters)
175
+ Client.open do |client|
176
+ response = client.execute(name, parameters)
177
+ unless response.success?
178
+ raise Client::Request::ErrorResponse.new(response)
179
+ end
180
+ response
181
+ end
182
+ end
183
+
184
+ def generate_reference_table_name(column)
185
+ "reference_#{@schema.table}_#{column.name}"
186
+ end
187
+
188
+ def generate_lexicon_name(column)
189
+ "lexicon_#{@schema.table}_#{column.name}"
190
+ end
144
191
  end
145
192
  end
146
193
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-client-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: groonga-client