22from pyravendb .custom_exceptions .exceptions import ErrorResponseException
33from pyravendb .data .indexes import IndexQuery
44from pyravendb .tools .utils import Utils
5+ from datetime import timedelta
6+ import sys
57import time
68
79
@@ -42,9 +44,6 @@ def __call__(self, object_type=None, index_name=None, using_default_operator=Non
4244 self ._with_statistics = with_statistics
4345 return self
4446
45- def __iter__ (self ):
46- return self ._execute_query ().__iter__ ()
47-
4847 def _lucene_builder (self , value , action = None ):
4948 lucene_text = Utils .to_lucene (value , action = action )
5049
@@ -56,6 +55,9 @@ def _lucene_builder(self, value, action=None):
5655
5756 return lucene_text
5857
58+ def __iter__ (self ):
59+ return self ._execute_query ().__iter__ ()
60+
5961 def where_equals (self , field_name , value ):
6062 """
6163 To get all the document that equal to the value in the given field_name
@@ -70,6 +72,10 @@ def where_equals(self, field_name, value):
7072 if value is not None and not isinstance (value , str ) and field_name is not None :
7173 sort_hint = self .session .conventions .get_default_sort_option (type (value ).__name__ )
7274 if sort_hint :
75+ field_name = "{0}_Range" .format (field_name )
76+ if sys .version_info .major > 2 :
77+ if value > sys .maxsize :
78+ sort_hint = self .session .conventions .get_default_sort_option ("long" )
7379 self ._sort_hints .add ("SortHint-{0}={1}" .format (field_name , sort_hint ))
7480
7581 lucene_text = self ._lucene_builder (value , action = "equal" )
@@ -106,6 +112,10 @@ def where_ends_with(self, field_name, value):
106112 if value is not None and not isinstance (value , str ) and field_name is not None :
107113 sort_hint = self .session .conventions .get_default_sort_option (type (value ).__name__ )
108114 if sort_hint :
115+ field_name = "{0}_Range" .format (field_name )
116+ if sys .version_info .major > 2 :
117+ if value > sys .maxsize :
118+ sort_hint = self .session .conventions .get_default_sort_option ("long" )
109119 self ._sort_hints .add ("SortHint-{0}={1}" .format (field_name , sort_hint ))
110120
111121 lucene_text = self ._lucene_builder (value , action = "end_with" )
@@ -127,6 +137,10 @@ def where_starts_with(self, field_name, value):
127137 if value is not None and not isinstance (value , str ) and field_name is not None :
128138 sort_hint = self .session .conventions .get_default_sort_option (type (value ).__name__ )
129139 if sort_hint :
140+ field_name = "{0}_Range" .format (field_name )
141+ if sys .version_info .major > 2 :
142+ if value > sys .maxsize :
143+ sort_hint = self .session .conventions .get_default_sort_option ("long" )
130144 self ._sort_hints .add ("SortHint-{0}={1}" .format (field_name , sort_hint ))
131145
132146 lucene_text = self ._lucene_builder (value , action = "end_with" )
@@ -152,23 +166,40 @@ def where_in(self, field_name, values):
152166 return self
153167
154168 def where_between (self , field_name , start , end ):
169+ if isinstance (start , timedelta ):
170+ start = Utils .timedelta_tick (start )
171+ if isinstance (end , timedelta ):
172+ end = Utils .timedelta_tick (end )
173+
155174 value = start or end
156175 if self .session .conventions .uses_range_type (value ) and not field_name .endswith ("_Range" ):
157176 sort_hint = self .session .conventions .get_default_sort_option (type (value ).__name__ )
158177 if sort_hint :
178+ field_name = "{0}_Range" .format (field_name )
179+ if sys .version_info .major > 2 :
180+ if value > sys .maxsize :
181+ sort_hint = self .session .conventions .get_default_sort_option ("long" )
159182 self ._sort_hints .add ("SortHint-{0}={1}" .format (field_name , sort_hint ))
160- field_name = "{0}_Range" . format ( field_name )
183+
161184 lucene_text = self ._lucene_builder ([start , end ], action = "between" )
162185 self .query_builder += "{0}:{1}" .format (field_name , lucene_text )
163186 return self
164187
165188 def where_between_or_equal (self , field_name , start , end ):
189+ if isinstance (start , timedelta ):
190+ start = Utils .timedelta_tick (start )
191+ if isinstance (end , timedelta ):
192+ end = Utils .timedelta_tick (end )
193+
166194 value = start or end
167195 if self .session .conventions .uses_range_type (value ) and not field_name .endswith ("_Range" ):
168196 sort_hint = self .session .conventions .get_default_sort_option (type (value ).__name__ )
169197 if sort_hint :
198+ field_name = "{0}_Range" .format (field_name )
199+ if sys .version_info .major > 2 :
200+ if value > sys .maxsize :
201+ sort_hint = self .session .conventions .get_default_sort_option ("long" )
170202 self ._sort_hints .add ("SortHint-{0}={1}" .format (field_name , sort_hint ))
171- field_name = "{0}_Range" .format (field_name )
172203 lucene_text = self ._lucene_builder ([start , end ], action = "equal_between" )
173204 self .query_builder += "{0}:{1}" .format (field_name , lucene_text )
174205 return self
0 commit comments