Suggest searching Google if there are no search results
This commit is contained in:
parent
f1c77d1389
commit
627f82d19f
1 changed files with 7 additions and 5 deletions
|
@ -158,14 +158,16 @@ class Ranker:
|
|||
ordered_results, terms, completions = self.get_results(q)
|
||||
if len(ordered_results) == 0:
|
||||
# There are no results so suggest Google searches instead
|
||||
adjusted_completions = ["search: google.com " + c for c in completions]
|
||||
adjusted_completions = set(completions + [q])
|
||||
completed = ["search: google.com " + ' '.join(terms[:-1] + [t]) for t in adjusted_completions]
|
||||
return [q, completed]
|
||||
else:
|
||||
adjusted_completions = [c for c in completions if c != terms[-1]]
|
||||
|
||||
urls = ["go: " + item.url[len(HTTPS_STRING):].rstrip('/') for item in ordered_results[:5]
|
||||
if item.url.startswith(HTTPS_STRING) and all(term in item.url for term in terms)][:1]
|
||||
completed = [' '.join(terms[:-1] + [t]) for t in adjusted_completions]
|
||||
return [q, urls + completed]
|
||||
urls = ["go: " + item.url[len(HTTPS_STRING):].rstrip('/') for item in ordered_results[:5]
|
||||
if item.url.startswith(HTTPS_STRING) and all(term in item.url for term in terms)][:1]
|
||||
completed = [' '.join(terms[:-1] + [t]) for t in adjusted_completions]
|
||||
return [q, urls + completed]
|
||||
|
||||
def get_results(self, q):
|
||||
terms = [x.lower() for x in q.replace('.', ' ').split()]
|
||||
|
|
Loading…
Add table
Reference in a new issue