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)
| 66 | |
| 67 | |
| 68 | def _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. |
| 96 | def _commonprefix(s1, s2): |