@@ -19,81 +19,72 @@ class Field(object):
19
19
TAG = 'TAG'
20
20
SORTABLE = 'SORTABLE'
21
21
NOINDEX = 'NOINDEX'
22
- SEPARATOR = 'SEPARATOR'
23
- PHONETIC = 'PHONETIC'
24
22
25
- def __init__ (self , name , * args ):
23
+ def __init__ (self , name , * args , sortable = False , no_index = False ):
26
24
self .name = name
27
- self .args = args
25
+ self .args = list (args )
26
+ self .args_suffix = list ()
27
+
28
+ if sortable :
29
+ self .args_suffix .append (Field .SORTABLE )
30
+ if no_index :
31
+ self .args_suffix .append (Field .NOINDEX )
32
+
33
+ if no_index and not sortable :
34
+ raise ValueError ('Non-Sortable non-Indexable fields are ignored' )
35
+
36
+ def append_arg (self , value ):
37
+ self .args .append (value )
28
38
29
39
def redis_args (self ):
30
- return [self .name ] + list ( self .args )
40
+ return [self .name ] + self .args + self . args_suffix
31
41
32
42
33
43
class TextField (Field ):
34
44
"""
35
45
TextField is used to define a text field in a schema definition
36
46
"""
37
47
NOSTEM = 'NOSTEM'
48
+ PHONETIC = 'PHONETIC'
49
+
50
+ def __init__ (self , name , weight = 1.0 , no_stem = False , phonetic_matcher = None , ** kwargs ):
51
+ Field .__init__ (self , name , Field .TEXT , Field .WEIGHT , weight , ** kwargs )
38
52
39
- def __init__ (self , name , weight = 1.0 , sortable = False , no_stem = False ,
40
- no_index = False , phonetic_matcher = None ):
41
- args = [Field .TEXT , Field .WEIGHT , weight ]
42
53
if no_stem :
43
- args .append (self .NOSTEM )
44
- if sortable :
45
- args .append (Field .SORTABLE )
46
- if no_index :
47
- args .append (self .NOINDEX )
54
+ Field .append_arg (self , self .NOSTEM )
48
55
if phonetic_matcher and phonetic_matcher in ['dm:en' , 'dm:fr' , 'dm:pt' , 'dm:es' ]:
49
- args .append (self .PHONETIC )
50
- args .append (phonetic_matcher )
51
-
52
- if no_index and not sortable :
53
- raise ValueError ('Non-Sortable non-Indexable fields are ignored' )
54
- Field .__init__ (self , name , * args )
56
+ Field .append_arg (self , self .PHONETIC )
57
+ Field .append_arg (self , phonetic_matcher )
55
58
56
59
57
60
class NumericField (Field ):
58
61
"""
59
- NumericField is used to define a numeric field in a schema defintion
62
+ NumericField is used to define a numeric field in a schema definition
60
63
"""
61
64
62
- def __init__ (self , name , sortable = False , no_index = False ):
63
- args = [Field .NUMERIC ]
64
- if sortable :
65
- args .append (Field .SORTABLE )
66
- if no_index :
67
- args .append (Field .NOINDEX )
68
-
69
- if no_index and not sortable :
70
- raise ValueError ('Non-Sortable non-Indexable fields are ignored' )
71
-
72
- super (NumericField , self ).__init__ (name , * args )
65
+ def __init__ (self , name , ** kwargs ):
66
+ Field .__init__ (self , name , Field .NUMERIC , ** kwargs )
73
67
74
68
75
69
class GeoField (Field ):
76
70
"""
77
- GeoField is used to define a geo-indexing field in a schema defintion
71
+ GeoField is used to define a geo-indexing field in a schema definition
78
72
"""
79
73
80
- def __init__ (self , name ):
81
- Field .__init__ (self , name , Field .GEO )
74
+ def __init__ (self , name , ** kwargs ):
75
+ Field .__init__ (self , name , Field .GEO , ** kwargs )
82
76
83
77
84
78
class TagField (Field ):
79
+ SEPARATOR = 'SEPARATOR'
80
+
85
81
"""
86
82
TagField is a tag-indexing field with simpler compression and tokenization.
87
83
See http://redisearch.io/Tags/
88
84
"""
89
85
90
- def __init__ (self , name , separator = ',' , no_index = False ):
91
- args = [Field .TAG , Field .SEPARATOR , separator ]
92
-
93
- if no_index :
94
- args .append (Field .NOINDEX )
95
-
96
- Field .__init__ (self , name , * args )
86
+ def __init__ (self , name , separator = ',' , ** kwargs ):
87
+ Field .__init__ (self , name , Field .TAG , self .SEPARATOR , separator , ** kwargs )
97
88
98
89
99
90
class IndexDefinition (object ):
0 commit comments