An open source, non-profit web search engine
Suggest searching Google if there are no search results
Daoud Clarke627f82d19f49
diff --git a/mwmbl/tinysearchengine/rank.py b/mwmbl/tinysearchengine/rank.pyindex 5c9199d..d774955 100644--- a/mwmbl/tinysearchengine/rank.py+++ b/mwmbl/tinysearchengine/rank.py@@ -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()]