in treeherder/model/models.py [0:0]
def search(cls, search_term):
max_size = 50
search_term = search_term.lower()
# On PostgreSQL we can use the ORM directly, but NOT the full text search
# 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)
.annotate(similarity=TrigramSimilarity("summary", search_term))
.order_by("-similarity")[0:max_size]
)
try:
open_recent_match_string = [item.serialize() for item in recent_qs]
all_data = [
match
for match in open_recent_match_string
if match["summary"].lower().startswith(search_term)
or "/" + search_term in match["summary"].lower()
or " " + search_term in match["summary"].lower()
or "\\" + search_term in match["summary"].lower()
or "," + search_term in match["summary"].lower()
]
open_recent = [x for x in all_data if x["resolution"] == ""]
all_others = [x for x in all_data if x["resolution"] != ""]
except ProgrammingError as e:
newrelic.agent.notice_error()
logger.error(
f"Failed to execute FULLTEXT search on Bugscache, error={e}, SQL={recent_qs.query.__str__()}"
)
open_recent = []
all_others = []
return {"open_recent": open_recent, "all_others": all_others}