MCPcopy Create free account
hub / github.com/aitjcize/cppman / _sort_search

Function _sort_search

cppman/main.py:68–93  ·  view source on GitHub ↗

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

(entry, pattern)

Source from the content-addressed store, hash-verified

66
67
68def _sort_search(entry, pattern):
69 """ Sort results
70 0. exact match goes first
71 1. sort by 'std::' (an entry with `std::` goes before an entry without)
72 2. sort by which position the keyword appears
73 """
74
75 title, keyword, url = entry
76
77 if keyword == pattern:
78 # Exact match - lowest key value
79 return (-1, -1, 0, keyword)
80
81 hasStd1 = keyword.find("std::")
82 if hasStd1 == -1:
83 hasStd1 = 1
84 else:
85 hasStd1 = 0
86
87 hasStd2 = title.find("std::")
88 if hasStd2 == -1:
89 hasStd2 = 1
90 else:
91 hasStd2 = 0
92
93 return (hasStd1, hasStd2, keyword.find(pattern), keyword)
94
95# Return the longest prefix of all list elements.
96def _commonprefix(s1, s2):

Callers 1

_search_keywordMethod · 0.85

Calls 1

findMethod · 0.80

Tested by

no test coverage detected