From 2e562a926b659f084014876b7b11a8aa27884489 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 6 Nov 2018 08:05:17 -0500 Subject: [PATCH 1/2] Don't complete url and title from same search word. Resolves #4411: > When opening a webpage, the suggested results will include those whose > URL ends with the beginning of the string you've typed and whose title > begins with the rest of the string. By joining the url and title with a space, we ensure that the last word of the url and the first word of the title are treated as separate words. --- qutebrowser/completion/models/histcategory.py | 2 +- tests/unit/completion/test_histcategory.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/qutebrowser/completion/models/histcategory.py b/qutebrowser/completion/models/histcategory.py index 7c9fc920d..b6d5f0465 100644 --- a/qutebrowser/completion/models/histcategory.py +++ b/qutebrowser/completion/models/histcategory.py @@ -76,7 +76,7 @@ class HistoryCategory(QSqlQueryModel): # given the search term "a b", the WHERE clause would be: # ((url || title) LIKE '%a%') AND ((url || title) LIKE '%b%') where_clause = ' AND '.join( - "(url || title) LIKE :{} escape '\\'".format(i) + "(url || ' ' || title) LIKE :{} escape '\\'".format(i) for i in range(len(words))) # replace ' in timestamp-format to avoid breaking the query diff --git a/tests/unit/completion/test_histcategory.py b/tests/unit/completion/test_histcategory.py index b36125a4a..02a6cfd1e 100644 --- a/tests/unit/completion/test_histcategory.py +++ b/tests/unit/completion/test_histcategory.py @@ -82,6 +82,14 @@ def hist(init_sql, config_stub): ("ample itle", [('example.com', 'title'), ('example.com', 'nope')], [('example.com', 'title')]), + + # https://github.com/qutebrowser/qutebrowser/issues/4411 + ("mlfreq", + [('https://qutebrowser.org/FAQ.html', 'Frequently Asked Questions')], + []), + ("ml freq", + [('https://qutebrowser.org/FAQ.html', 'Frequently Asked Questions')], + [('https://qutebrowser.org/FAQ.html', 'Frequently Asked Questions')]), ]) def test_set_pattern(pattern, before, after, model_validator, hist): """Validate the filtering and sorting results of set_pattern.""" From bf10f483e14bd47a9ebd4dacded0d608d4304642 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 13 Nov 2018 20:44:57 -0500 Subject: [PATCH 2/2] Fix sql comment to match updated code. --- qutebrowser/completion/models/histcategory.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/completion/models/histcategory.py b/qutebrowser/completion/models/histcategory.py index b6d5f0465..83eafef50 100644 --- a/qutebrowser/completion/models/histcategory.py +++ b/qutebrowser/completion/models/histcategory.py @@ -74,7 +74,8 @@ class HistoryCategory(QSqlQueryModel): # build a where clause to match all of the words in any order # given the search term "a b", the WHERE clause would be: - # ((url || title) LIKE '%a%') AND ((url || title) LIKE '%b%') + # ((url || ' ' || title) LIKE '%a%') AND + # ((url || ' ' || title) LIKE '%b%') where_clause = ' AND '.join( "(url || ' ' || title) LIKE :{} escape '\\'".format(i) for i in range(len(words)))