Skip to content

Commit

Permalink
Skip escaping special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien Abadie committed Mar 25, 2024
1 parent 4f86df2 commit 68647cb
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions treeherder/model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ def sanitized_search_term(cls, search_term):
def search(cls, search_term):
max_size = 50

# Do not wrap a string in quotes to search as a phrase;
# see https://bugzilla.mozilla.org/show_bug.cgi?id=1704311
search_term_fulltext = cls.sanitized_search_term(search_term)

if settings.DATABASES["default"]["ENGINE"] == "django.db.backends.mysql":
# Do not wrap a string in quotes to search as a phrase;
# see https://bugzilla.mozilla.org/show_bug.cgi?id=1704311
search_term_fulltext = cls.sanitized_search_term(search_term)

# Substitute escape and wildcard characters, so the search term is used
# literally in the LIKE statement.
search_term_like = (
Expand All @@ -279,10 +279,11 @@ def search(cls, search_term):
# as the ranking algorithm expects english words, not paths
# So we use standard pattern matching AND trigram similarity to compare suite of characters
# instead of words
# Django already escapes special characters, so we do not need to handle that here
recent_qs = (
Bugscache.objects.filter(summary__icontains=search_term_fulltext)
.annotate(similarity=TrigramSimilarity("summary", search_term_fulltext))
.order_by("-similarity")[0:max_size]
Bugscache.objects.filter(summary__icontains=search_term)
.annotate(similarity=TrigramSimilarity("summary", search_term))
.order_by("similarity")[0:max_size]
)

exclude_fields = ["modified", "processed_update"]
Expand Down

0 comments on commit 68647cb

Please sign in to comment.