DO not change the query value while looping

This commit is contained in:
Kovid Goyal 2013-06-13 14:03:08 +05:30
parent 4787801c0d
commit 74d1e247f1

View File

@ -25,11 +25,11 @@ def comparable_price(text):
if match: if match:
# replace all separators with '.' # replace all separators with '.'
m = re.sub(r'[.,\' ]', '.', match.group()) m = re.sub(r'[.,\' ]', '.', match.group())
# remove all separators accept fraction, # remove all separators accept fraction,
# leave only 2 digits in fraction # leave only 2 digits in fraction
m = re.sub(r'\.(?!\d*$)', r'', m) m = re.sub(r'\.(?!\d*$)', r'', m)
text = '{0:0>8.0f}'.format(float(m) * 100.) text = '{0:0>8.0f}'.format(float(m) * 100.)
return text return text
class Matches(QAbstractItemModel): class Matches(QAbstractItemModel):
@ -138,7 +138,7 @@ class Matches(QAbstractItemModel):
def set_query(self, query): def set_query(self, query):
self.query = query self.query = query
self.filterable_query = self.is_filterable_query(query) self.filterable_query = self.is_filterable_query(query)
def is_filterable_query(self, query): def is_filterable_query(self, query):
# Remove control modifiers. # Remove control modifiers.
query = query.replace('\\', '') query = query.replace('\\', '')
@ -398,13 +398,14 @@ class SearchFilter(SearchQueryParser):
q[x+'s'] = q[x] q[x+'s'] = q[x]
q['author2'] = q['author'] q['author2'] = q['author']
q['title2'] = q['title'] q['title2'] = q['title']
# make the price in query the same format as result # make the price in query the same format as result
if location == 'price': if location == 'price':
query = comparable_price(query) query = comparable_price(query)
for sr in self.srs: for sr in self.srs:
for locvalue in locations: for locvalue in locations:
final_query = query
accessor = q[locvalue] accessor = q[locvalue]
if query == 'true': if query == 'true':
# True/False. # True/False.
@ -451,10 +452,10 @@ class SearchFilter(SearchQueryParser):
elif locvalue in ('author2', 'title2'): elif locvalue in ('author2', 'title2'):
m = self.IN_MATCH m = self.IN_MATCH
vals = re.sub(r'(^|\s)(and|not|or|a|the|is|of|,)(\s|$)', ' ', accessor(sr)).split(' ') vals = re.sub(r'(^|\s)(and|not|or|a|the|is|of|,)(\s|$)', ' ', accessor(sr)).split(' ')
query = query.lower() final_query = query.lower()
else: else:
vals = [accessor(sr)] vals = [accessor(sr)]
if self._match(query, vals, m): if self._match(final_query, vals, m):
matches.add(sr) matches.add(sr)
break break
except ValueError: # Unicode errors except ValueError: # Unicode errors