@@ -40,8 +40,8 @@ def __str__(self):
40
40
class IndexDefinition (object ):
41
41
def __init__ (self , index_map , name = None , ** kwargs ):
42
42
"""
43
- @param index_maps : The map of the index
44
- :type str
43
+ @param index_map : The map of the index
44
+ :type str or tuple
45
45
@param name: The name of the index
46
46
:type str
47
47
@param kwargs: Can be use to initialize the other option in the index definition
@@ -58,16 +58,14 @@ def __init__(self, index_map, name=None, **kwargs):
58
58
self ._is_compiled = False
59
59
self .is_side_by_side_index = kwargs .get ("is_side_by_side_index" , False )
60
60
self .is_test_index = kwargs .get ("is_test_index" , False )
61
- self .is_map_reduce = kwargs .get ("is_map_reduce" , False )
62
61
self .lock_mod = kwargs .get ("lock_mod" , IndexLockMode .Unlock )
63
62
self .max_index_outputs_per_document = kwargs .get ("max_index_outputs_per_document" , None )
64
63
self .sort_options = kwargs .get ("sort_options" , {})
65
64
self .spatial_indexes = kwargs .get ("spatial_indexes" , {})
66
65
self .stores = kwargs .get ("stores" , {})
67
66
self .suggestions = kwargs .get ("suggestions" , {})
68
67
self .term_vectors = kwargs .get ("term_vectors" , {})
69
- self .maps = kwargs .get ("maps" , set ())
70
- self .map = index_map
68
+ self .maps = (index_map ,) if isinstance (index_map , str ) else tuple (set (index_map , ))
71
69
72
70
@property
73
71
def type (self ):
@@ -79,9 +77,15 @@ def type(self):
79
77
return "MapReduce"
80
78
return "Map"
81
79
80
+ @property
81
+ def is_map_reduce (self ):
82
+ return True if self .reduce else False
83
+
82
84
@property
83
85
def map (self ):
84
- return list (self .maps )[0 ]
86
+ if not isinstance (self .maps , str ):
87
+ return self .maps [0 ]
88
+ return self .maps
85
89
86
90
@map .setter
87
91
def map (self , value ):
@@ -96,7 +100,7 @@ def to_json(self):
96
100
"InternalFieldsMapping" : self .internal_fields_mapping , "IsCompiled" : self ._is_compiled ,
97
101
"IsMapReduce" : self .is_map_reduce , "IsSideBySideIndex" : self .is_side_by_side_index ,
98
102
"IsTestIndex" : self .is_test_index , "LockMode" : str (self .lock_mod ), "Map" : self .map ,
99
- "Maps" : list ( self .maps ) ,
103
+ "Maps" : self .maps ,
100
104
"MaxIndexOutputsPerDocument" : self .max_index_outputs_per_document , "Name" : self .name ,
101
105
"Reduce" : self .reduce , "SortOptions" : {key : str (self .sort_options [key ]) for key in self .sort_options },
102
106
"SpatialIndexes" : self .spatial_indexes ,
@@ -115,6 +119,8 @@ def __init__(self, query="", total_size=0, skipped_results=0, default_operator=N
115
119
:type int
116
120
@param default_operator: The operator of the query (AND or OR) the default value is OR
117
121
:type Enum.QueryOperator
122
+ @param fetch fetch only the terms you want from the index
123
+ :type list
118
124
"""
119
125
self .query = query
120
126
self .total_size = total_size
@@ -124,6 +130,7 @@ def __init__(self, query="", total_size=0, skipped_results=0, default_operator=N
124
130
self .default_operator = default_operator
125
131
self .sort_hints = kwargs .get ("sort_hints" , {})
126
132
self .sort_fields = kwargs .get ("sort_fields" , {})
133
+ self .fetch = kwargs .get ("fetch" , [])
127
134
self .wait_for_non_stale_results = kwargs .get ("wait_for_non_stale_results" , False )
128
135
129
136
@property
0 commit comments