Skip to content

Commit

Permalink
modifications nom variables case + ajout case sensitivity notlike
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliettejns committed Mar 14, 2024
1 parent dce862f commit 77abbfe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions app/main/views/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ def tokens_search_through_fields(corpus_id):
search_branches: List[Dict[str, str]] = [dict(prod) for prod in product(*flat_fields)]

value_filters = []
caseIssensitive=True
caseIsensitive=True
if 'caseBox' in source_dict:
caseIssensitive = False
caseIsensitive = False
# for each branch filter (= OR clauses if any)
for search_branch in search_branches:
# filtre minimal = bon corpus (id)
Expand All @@ -325,7 +325,7 @@ def tokens_search_through_fields(corpus_id):
# for each field (lemma, pos, form, morph)
for name, value in search_branch.items():
# transformation couple clé valeur en filtre SQLalchemy
branch_filters.extend(column_search_filter(getattr(WordToken, name), value, case=caseIssensitive))
branch_filters.extend(column_search_filter(getattr(WordToken, name), value, case_sensitive=caseIsensitive))

value_filters.append(branch_filters)

Expand Down
31 changes: 17 additions & 14 deletions app/utils/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ def prepare_search_string(string: str) -> list:
return value


def column_search_filter(field, value: str, case=True) -> list:
def column_search_filter(field, value: str, case_sensitive=True) -> list:
""" Based on a field name and a string value, computes the list of search WHERE that needs to be \
applied to a query
:param field: ORM Field Property
:param value: Search String
:return: List of WHERE clauses
"""
# modifier ici case.
branch_filters = []
if len(value) > 0:
value = value.replace(" ", "")
Expand All @@ -56,23 +55,27 @@ def column_search_filter(field, value: str, case=True) -> list:
value = value.replace("*", "%")
# unescape '\*'
value = value.replace('¤$¤', '*')

if value.startswith("!") and len(value) > 1:
value = value[1:]
branch_filters.append(field.notlike(value, escape='\\'))
elif case:
# unescape '\!'
value = value.replace('¤$$¤', '!')
branch_filters.append(field.like(value, escape='\\'))
if case_sensitive:
if value.startswith("!") and len(value) > 1:
value = value[1:]
branch_filters.append(field.notlike(value, escape='\\'))
else:
# unescape '\!'
value = value.replace('¤$$¤', '!')
branch_filters.append(field.like(value, escape='\\'))
else:
# unescape '\!'
value = value.replace('¤$$¤', '!')
branch_filters.append(field.ilike(value, escape='\\'))
if value.startswith("!") and len(value) > 1:
value = value[1:]
branch_filters.append(func.lower(field).notlike(func.lower(value), escape='\\'))
else:
# unescape '\!'
value = value.replace('¤$$¤', '!')
branch_filters.append(field.ilike(value, escape='\\'))

else:
# unescape '\*'
value = value.replace('¤$¤', '*')
if case:
if case_sensitive:
if value is not None and value.startswith("!") and len(value) > 1:
value = value[1:]
branch_filters.append(field != value)
Expand Down
1 change: 0 additions & 1 deletion tests/test_selenium/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,6 @@ def setUp(self):
db.session.commit()

def search(self, form="", lemma="", pos="", morph="", case=False):
print(case)
self.go_to_search_tokens_page(TokensSearchThroughFieldsBase.CORPUS_ID, as_callback=False)
self.fill_filter_row(form, lemma, pos, morph)
if case:
Expand Down

0 comments on commit 77abbfe

Please sign in to comment.