Skip to content

Commit

Permalink
Prioritize exact matches in search results
Browse files Browse the repository at this point in the history
This fixes 'string (2)' vs 'std::to_string(2)' issue (std:: has a higher
priority). To reproduce run:

    cppman 'string (2)'
  • Loading branch information
glenvt18 authored and aitjcize committed Apr 4, 2023
1 parent e2cdb92 commit 2bb55e8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cppman/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ def _sort_crawl(entry):

def _sort_search(entry, pattern):
""" Sort results
0. exact match goes first
1. sort by 'std::' (an entry with `std::` goes before an entry without)
2. sort by which position the keyword appears
"""

title, keyword, url = entry

if keyword == pattern:
# Exact match - lowest key value
return (-1, -1, 0, keyword)

hasStd1 = keyword.find("std::")
if hasStd1 == -1:
hasStd1 = 1
Expand Down

0 comments on commit 2bb55e8

Please sign in to comment.