1
1
from six import add_metaclass
2
2
3
- from .utils import DslMeta , DslBase , BoolMixin
3
+ from .utils import DslMeta , DslBase , BoolMixin , _make_dsl_class
4
4
from .function import SF , ScoreFunction
5
5
6
6
class QueryMeta (DslMeta ):
@@ -41,7 +41,6 @@ def __add__(self, other):
41
41
def __or__ (self , other ):
42
42
return self
43
43
__ror__ = __or__
44
-
45
44
EMPTY_QUERY = MatchAll ()
46
45
47
46
class Bool (BoolMixin , Query ):
@@ -51,7 +50,6 @@ class Bool(BoolMixin, Query):
51
50
'should' : {'type' : 'query' , 'multi' : True },
52
51
'must_not' : {'type' : 'query' , 'multi' : True },
53
52
}
54
-
55
53
# register this as Bool for Query
56
54
Query ._bool = Bool
57
55
@@ -117,17 +115,8 @@ def __init__(self, **kwargs):
117
115
('wildcard' , None ),
118
116
)
119
117
120
- def _make_query_class (name , params_def = None ):
121
- """
122
- Generate a query class based on the name of the query and it's parameters
123
- """
124
- attrs = {'name' : name }
125
- if params_def :
126
- attrs ['_param_defs' ] = params_def
127
- cls_name = '' .join (s .title () for s in name .split ('_' ))
128
- globals ()[cls_name ] = type (cls_name , (Query , ), attrs )
129
-
130
118
# generate the query classes dynamicaly
131
119
for qname , params_def in QUERIES :
132
- _make_query_class (qname , params_def )
120
+ qclass = _make_dsl_class (Query , qname , params_def )
121
+ globals ()[qclass .__name__ ] = qclass
133
122
0 commit comments