@@ -60,22 +60,6 @@ class CardSearchQueryBuilder
6060 }
6161 @@term_to_field_map = {
6262 # 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-
7963 '_' => 'cards.stripped_title' ,
8064 'advancement_cost' => 'cards.advancement_requirement' ,
8165 'agenda_points' => 'cards.agenda_points' ,
@@ -88,6 +72,7 @@ class CardSearchQueryBuilder
8872 'eternal_points' => 'unified_restrictions.eternal_points' ,
8973 'f' => 'cards.faction_id' ,
9074 'faction' => 'cards.faction_id' ,
75+ 'format' => 'unified_restrictions.format_id' ,
9176 'g' => 'cards.advancement_requirement' ,
9277 'global_penalty' => 'unified_restrictions.global_penalty' ,
9378 'h' => 'cards.trash_cost' ,
@@ -115,11 +100,23 @@ class CardSearchQueryBuilder
115100 'x' => 'cards.stripped_text' ,
116101 }
117102
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+
118115 def initialize ( query )
119116 @query = query
120117 @parse_error = nil
121118 @parse_tree = nil
122- @left_joins = [ ]
119+ @left_joins = Set . new
123120 @where = ''
124121 @where_values = [ ]
125122 begin
@@ -152,9 +149,6 @@ def initialize(query)
152149 @parse_error = 'Invalid boolean operator "%s"' % match_type
153150 return
154151 end
155- if [ 'is_banned' , 'is_restricted' ] . include? ( keyword )
156- @left_joins << :unified_restrictions
157- end
158152 constraints << '%s %s ?' % [ @@term_to_field_map [ keyword ] , operator ]
159153 where << value
160154 elsif @@numeric_keywords . include? ( keyword )
@@ -163,10 +157,7 @@ def initialize(query)
163157 return
164158 end
165159 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 )
170161 operator = @@numeric_operators [ match_type ]
171162 else
172163 @parse_error = 'Invalid numeric operator "%s"' % match_type
@@ -184,15 +175,13 @@ def initialize(query)
184175 @parse_error = 'Invalid string operator "%s"' % match_type
185176 return
186177 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 ]
193179 where << '%%%s%%' % value
194180 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
196185
197186 # bare/quoted words in the query are automatically mapped to stripped_title
198187 if f . include? ( :string )
@@ -216,6 +205,6 @@ def where_values
216205 return @where_values
217206 end
218207 def left_joins
219- return @left_joins
208+ return @left_joins . to_a
220209 end
221210end
0 commit comments