Skip to content

Instantly share code, notes, and snippets.

@debojyoti
Last active April 28, 2026 16:05
Show Gist options
  • Select an option

  • Save debojyoti/d1cb4f31755d0215d706d4c8a6c7f76c to your computer and use it in GitHub Desktop.

Select an option

Save debojyoti/d1cb4f31755d0215d706d4c8a6c7f76c to your computer and use it in GitHub Desktop.

Ticket Ranking Logic

Goal

When multiple tickets match the same confirmation number, rank them so the most recent and relevant ticket appears first.

The ranking gives highest priority to when the ticket was created, while also considering recent activity and whether the ticket is still open.

Scoring Logic

For N matching tickets:

  1. Sort tickets by created_at, newest first.

    • Assign score from N to 1.
    • The newest ticket gets the highest score.
  2. Sort tickets by updated_at, newest first.

    • Assign half-weight score from N * 0.5 to 0.5.
  3. Add a status bonus.

    • Open ticket: +0.5
    • Closed ticket: +0

Final Score

final_score = created_score + updated_score + status_bonus

The ticket with the highest final_score is selected as the best match.

Example

Assume 5 tickets are found:

Ticket Created Rank Created Score Updated Rank Updated Score Status Status Bonus Final Score
A 1 5 3 1.5 Closed 0 6.5
B 2 4 1 2.5 Open 0.5 7.0
C 3 3 2 2.0 Closed 0 5.0
D 4 2 5 0.5 Open 0.5 3.0
E 5 1 4 1.0 Closed 0 2.0

Result

Ticket B is selected.

Even though Ticket A was created most recently, Ticket B has more recent activity and is still open, so it becomes the stronger candidate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment