-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from molgen/add-search-patch
Add wagtail patch for partial search
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
patches/documents-and-images-support-partial-matches.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
From 1a1251cfb19cc49d94dfd71a8b84171916060c9b Mon Sep 17 00:00:00 2001 | ||
From: Donald Buczek <buczek@molgen.mpg.de> | ||
Date: Fri, 15 Nov 2019 17:22:38 +0100 | ||
Subject: [PATCH] documents/images: Support partial match on search | ||
|
||
The postgres_search backend currently doesn't support partial searches | ||
in its search() method. The index and the autocomplete method, however | ||
do. | ||
|
||
Enable partial matches for wagtails backend view and chooser by using | ||
.autocomplete instead of .search. | ||
|
||
This is a workaround and should be replaced by a cleaner approach. | ||
--- | ||
lib/python3.7/site-packages/wagtail/documents/views/chooser.py | 2 +- | ||
.../site-packages/wagtail/documents/views/documents.py | 2 +- | ||
lib/python3.7/site-packages/wagtail/images/views/chooser.py | 2 +- | ||
lib/python3.7/site-packages/wagtail/images/views/images.py | 2 +- | ||
4 files changed, 4 insertions(+), 4 deletions(-) | ||
|
||
diff --git a/lib/python3.7/site-packages/wagtail/documents/views/chooser.py b/lib/python3.7/site-packages/wagtail/documents/views/chooser.py | ||
index f5d6331..a13378b 100644 | ||
--- a/lib/python3.7/site-packages/wagtail/documents/views/chooser.py | ||
+++ b/lib/python3.7/site-packages/wagtail/documents/views/chooser.py | ||
@@ -68,7 +68,7 @@ def chooser(request): | ||
if searchform.is_valid(): | ||
q = searchform.cleaned_data['q'] | ||
|
||
- documents = documents.search(q) | ||
+ documents = documents.autocomplete(q) | ||
is_searching = True | ||
else: | ||
documents = documents.order_by('-created_at') | ||
diff --git a/lib/python3.7/site-packages/wagtail/documents/views/documents.py b/lib/python3.7/site-packages/wagtail/documents/views/documents.py | ||
index 36966e9..41ae754 100644 | ||
--- a/lib/python3.7/site-packages/wagtail/documents/views/documents.py | ||
+++ b/lib/python3.7/site-packages/wagtail/documents/views/documents.py | ||
@@ -51,7 +51,7 @@ def index(request): | ||
form = SearchForm(request.GET, placeholder=_("Search documents")) | ||
if form.is_valid(): | ||
query_string = form.cleaned_data['q'] | ||
- documents = documents.search(query_string) | ||
+ documents = documents.autocomplete(query_string) | ||
else: | ||
form = SearchForm(placeholder=_("Search documents")) | ||
|
||
diff --git a/lib/python3.7/site-packages/wagtail/images/views/chooser.py b/lib/python3.7/site-packages/wagtail/images/views/chooser.py | ||
index cba82d8..c565385 100644 | ||
--- a/lib/python3.7/site-packages/wagtail/images/views/chooser.py | ||
+++ b/lib/python3.7/site-packages/wagtail/images/views/chooser.py | ||
@@ -94,7 +94,7 @@ def chooser(request): | ||
if searchform.is_valid(): | ||
q = searchform.cleaned_data['q'] | ||
|
||
- images = images.search(q) | ||
+ images = images.autocomplete(q) | ||
is_searching = True | ||
else: | ||
is_searching = False | ||
diff --git a/lib/python3.7/site-packages/wagtail/images/views/images.py b/lib/python3.7/site-packages/wagtail/images/views/images.py | ||
index a42958b..ed388f9 100644 | ||
--- a/lib/python3.7/site-packages/wagtail/images/views/images.py | ||
+++ b/lib/python3.7/site-packages/wagtail/images/views/images.py | ||
@@ -40,7 +40,7 @@ def index(request): | ||
if form.is_valid(): | ||
query_string = form.cleaned_data['q'] | ||
|
||
- images = images.search(query_string) | ||
+ images = images.autocomplete(query_string) | ||
else: | ||
form = SearchForm(placeholder=_("Search images")) | ||
|
||
-- | ||
2.22.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
From d1f371bdcb803d06447999e1cf3e934da9297168 Mon Sep 17 00:00:00 2001 | ||
From: Donald Buczek <buczek@molgen.mpg.de> | ||
Date: Tue, 19 Nov 2019 15:27:16 +0100 | ||
Subject: [PATCH] Hack snippets chooser to use autocomplete | ||
|
||
Users wanted to have partial search when Contacts are selected by the | ||
Chooser. The Chooser doesn't have the feature to use partial matches and | ||
our postgres_search doesn't support it in its search() method anyway. | ||
Try to get away with changing the Chooserd to use autocomplete(). | ||
--- | ||
lib/python3.7/site-packages/wagtail/snippets/views/chooser.py | 2 +- | ||
1 file changed, 1 insertion(+), 1 deletion(-) | ||
|
||
diff --git a/lib/python3.7/site-packages/wagtail/snippets/views/chooser.py b/lib/python3.7/site-packages/wagtail/snippets/views/chooser.py | ||
index adffdef..74de073 100644 | ||
--- a/lib/python3.7/site-packages/wagtail/snippets/views/chooser.py | ||
+++ b/lib/python3.7/site-packages/wagtail/snippets/views/chooser.py | ||
@@ -34,7 +34,7 @@ def choose(request, app_label, model_name): | ||
search_query = search_form.cleaned_data['q'] | ||
|
||
search_backend = get_search_backend() | ||
- items = search_backend.search(search_query, items) | ||
+ items = search_backend.autocomplete(search_query, items) | ||
is_searching = True | ||
|
||
else: | ||
-- | ||
2.22.0 | ||
|