Skip to content

Commit 2bb55e8

Browse files
glenvt18aitjcize
authored andcommitted
Prioritize exact matches in search results
This fixes 'string (2)' vs 'std::to_string(2)' issue (std:: has a higher priority). To reproduce run: cppman 'string (2)'
1 parent e2cdb92 commit 2bb55e8

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

cppman/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ def _sort_crawl(entry):
6767

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

7475
title, keyword, url = entry
76+
77+
if keyword == pattern:
78+
# Exact match - lowest key value
79+
return (-1, -1, 0, keyword)
80+
7581
hasStd1 = keyword.find("std::")
7682
if hasStd1 == -1:
7783
hasStd1 = 1

0 commit comments

Comments
 (0)