@@ -60,22 +60,6 @@ class CardSearchQueryBuilder
60
60
}
61
61
@@term_to_field_map = {
62
62
# format should implicitly use the currently active card pool and restriction lists unless another is specified.
63
- # 'format' => '',
64
- # 'restriction' => '',
65
-
66
- # printing? or minimum release date from printing for the card? Add release date to the card? 'r' => 'release_date',
67
- # printing 'a' => 'flavor',
68
- # printing 'c' => 'card_cycle_id',
69
- # printing 'card_cycle' => 'card_cycle_id'',
70
- # printing 'card_set' => 'card_set_id'',
71
- # printing 'e' => 'card_set_id',
72
- # printing 'i' => 'illustrator',
73
- # printing 'quantity_in_card_set' => ''',
74
- # printing 'release_date' => ''',
75
- # printing flavor 'flavor_text' => ''',
76
- # printing illustrator 'illustrator' => ''',
77
- # printing quantity 'y' => ''',
78
-
79
63
'_' => 'cards.stripped_title' ,
80
64
'advancement_cost' => 'cards.advancement_requirement' ,
81
65
'agenda_points' => 'cards.agenda_points' ,
@@ -88,6 +72,7 @@ class CardSearchQueryBuilder
88
72
'eternal_points' => 'unified_restrictions.eternal_points' ,
89
73
'f' => 'cards.faction_id' ,
90
74
'faction' => 'cards.faction_id' ,
75
+ 'format' => 'unified_restrictions.format_id' ,
91
76
'g' => 'cards.advancement_requirement' ,
92
77
'global_penalty' => 'unified_restrictions.global_penalty' ,
93
78
'h' => 'cards.trash_cost' ,
@@ -115,11 +100,23 @@ class CardSearchQueryBuilder
115
100
'x' => 'cards.stripped_text' ,
116
101
}
117
102
103
+ @@term_to_left_join_map = {
104
+ 'card_pool' => :card_pool_cards ,
105
+ 'card_subtype' => :card_subtypes ,
106
+ 'eternal_points' => :unified_restrictions ,
107
+ 'global_penalty' => :unified_restrictions ,
108
+ 'is_banned' => :unified_restrictions ,
109
+ 'is_restricted' => :unified_restrictions ,
110
+ 'restriction_id' => :unified_restrictions ,
111
+ 's' => :card_subtypes ,
112
+ 'universal_faction_cost' => :unified_restrictions ,
113
+ }
114
+
118
115
def initialize ( query )
119
116
@query = query
120
117
@parse_error = nil
121
118
@parse_tree = nil
122
- @left_joins = [ ]
119
+ @left_joins = Set . new
123
120
@where = ''
124
121
@where_values = [ ]
125
122
begin
@@ -152,9 +149,6 @@ def initialize(query)
152
149
@parse_error = 'Invalid boolean operator "%s"' % match_type
153
150
return
154
151
end
155
- if [ 'is_banned' , 'is_restricted' ] . include? ( keyword )
156
- @left_joins << :unified_restrictions
157
- end
158
152
constraints << '%s %s ?' % [ @@term_to_field_map [ keyword ] , operator ]
159
153
where << value
160
154
elsif @@numeric_keywords . include? ( keyword )
@@ -163,10 +157,7 @@ def initialize(query)
163
157
return
164
158
end
165
159
operator = ''
166
- if [ 'eternal_points' , 'global_penalty' , 'universal_faction_cost' ] . include? ( keyword )
167
- @left_joins << :unified_restrictions
168
- end
169
- if @@numeric_operators . include? ( match_type )
160
+ if @@numeric_operators . include? ( match_type )
170
161
operator = @@numeric_operators [ match_type ]
171
162
else
172
163
@parse_error = 'Invalid numeric operator "%s"' % match_type
@@ -184,15 +175,13 @@ def initialize(query)
184
175
@parse_error = 'Invalid string operator "%s"' % match_type
185
176
return
186
177
end
187
- if [ 's' , 'card_subtype' ] . include? ( keyword )
188
- @left_joins << :card_subtypes
189
- elsif keyword == 'card_pool'
190
- @left_joins << :card_pool_cards
191
- end
192
- constraints << 'lower(%s) %s ?' % [ @@term_to_field_map [ keyword ] , operator ]
178
+ constraints << 'lower(%s) %s ?' % [ @@term_to_field_map [ keyword ] , operator ]
193
179
where << '%%%s%%' % value
194
180
end
195
- end
181
+ if @@term_to_left_join_map . include? ( keyword )
182
+ @left_joins << @@term_to_left_join_map [ keyword ]
183
+ end
184
+ end
196
185
197
186
# bare/quoted words in the query are automatically mapped to stripped_title
198
187
if f . include? ( :string )
@@ -216,6 +205,6 @@ def where_values
216
205
return @where_values
217
206
end
218
207
def left_joins
219
- return @left_joins
208
+ return @left_joins . to_a
220
209
end
221
210
end
0 commit comments