- table_name = self._parse_table_name(valid_type)
-
- # Quietly ignore bogus valid_types; more likely to DTRT
- if table_name:
- final_valid_types.append(valid_type)
- type_terms.append(whoosh.query.Term(u'table', table_name))
-
- return name, final_valid_types, whoosh.query.Or(type_terms)
+ if valid_type.startswith(u'@'):
+ # @foo means: language must be foo.
+ # Allow for either country or language codes
+ lang_code = valid_type[1:]
+ lang_terms.append(whoosh.query.Term(u'iso639', lang_code))
+ lang_terms.append(whoosh.query.Term(u'iso3166', lang_code))
+ else:
+ # otherwise, this is a type/table name
+ table_name = self._parse_table_name(valid_type)
+
+ # Quietly ignore bogus valid_types; more likely to DTRT
+ if table_name:
+ type_terms.append(whoosh.query.Term(u'table', table_name))
+
+ # Combine both kinds of restriction
+ all_terms = []
+ if type_terms:
+ all_terms.append(whoosh.query.Or(type_terms))
+ if lang_terms:
+ all_terms.append(whoosh.query.Or(lang_terms))
+
+ return name, combined_valid_types, whoosh.query.And(all_terms)