From 0adc0ebf9e02522fa782372fd609f588e811bf81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Mon, 3 Aug 2015 14:38:43 +0200 Subject: [PATCH 1/3] Return an empty list even in bad searchs --- taiga/searches/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/taiga/searches/api.py b/taiga/searches/api.py index befe539b..9fec9bb8 100644 --- a/taiga/searches/api.py +++ b/taiga/searches/api.py @@ -56,11 +56,12 @@ class SearchViewSet(viewsets.ViewSet): futures_list.append(wiki_pages_future) for future in futures.as_completed(futures_list): + data = [] try: data = future.result() except Exception as exc: print('%s generated an exception: %s' % (future.result_key, exc)) - else: + finally: result[future.result_key] = data result["count"] = sum(map(lambda x: len(x), result.values())) From a251761b1800c0f4105d756a44e39f5764cd6f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Mon, 3 Aug 2015 14:44:08 +0200 Subject: [PATCH 2/3] Revert "Add support for partial words on global searches" This reverts commit 9cbecd9b7edf82749761361454827575a0a19586. --- taiga/searches/services.py | 14 +++++--------- tests/integration/test_searches.py | 20 +++----------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/taiga/searches/services.py b/taiga/searches/services.py index ccea5c19..9d7d0529 100644 --- a/taiga/searches/services.py +++ b/taiga/searches/services.py @@ -25,10 +25,9 @@ def search_user_stories(project, text): model_cls = apps.get_model("userstories", "UserStory") where_clause = ("to_tsvector('simple', coalesce(userstories_userstory.subject, '') || ' ' || " "coalesce(userstories_userstory.ref) || ' ' || " - "coalesce(userstories_userstory.description, '')) @@ to_tsquery(%s)") + "coalesce(userstories_userstory.description, '')) @@ plainto_tsquery(%s)") if text: - text += ":*" return (model_cls.objects.extra(where=[where_clause], params=[text]) .filter(project_id=project.pk)[:MAX_RESULTS]) @@ -39,10 +38,9 @@ def search_tasks(project, text): model_cls = apps.get_model("tasks", "Task") where_clause = ("to_tsvector('simple', coalesce(tasks_task.subject, '') || ' ' || " "coalesce(tasks_task.ref) || ' ' || " - "coalesce(tasks_task.description, '')) @@ to_tsquery(%s)") + "coalesce(tasks_task.description, '')) @@ plainto_tsquery(%s)") if text: - text += ":*" return (model_cls.objects.extra(where=[where_clause], params=[text]) .filter(project_id=project.pk)[:MAX_RESULTS]) @@ -53,10 +51,9 @@ def search_issues(project, text): model_cls = apps.get_model("issues", "Issue") where_clause = ("to_tsvector('simple', coalesce(issues_issue.subject) || ' ' || " "coalesce(issues_issue.ref) || ' ' || " - "coalesce(issues_issue.description)) @@ to_tsquery(%s)") + "coalesce(issues_issue.description, '')) @@ plainto_tsquery(%s)") if text: - text += ":*" return (model_cls.objects.extra(where=[where_clause], params=[text]) .filter(project_id=project.pk)[:MAX_RESULTS]) @@ -65,11 +62,10 @@ def search_issues(project, text): def search_wiki_pages(project, text): model_cls = apps.get_model("wiki", "WikiPage") - where_clause = ("to_tsvector('simple', coalesce(wiki_wikipage.slug) || ' ' || coalesce(wiki_wikipage.content)) " - "@@ to_tsquery(%s)") + where_clause = ("to_tsvector('simple', coalesce(wiki_wikipage.slug) || ' ' || " + "coalesce(wiki_wikipage.content, '')) @@ plainto_tsquery(%s)") if text: - text += ":*" return (model_cls.objects.extra(where=[where_clause], params=[text]) .filter(project_id=project.pk)[:MAX_RESULTS]) diff --git a/tests/integration/test_searches.py b/tests/integration/test_searches.py index f6a26cc1..ec6743ad 100644 --- a/tests/integration/test_searches.py +++ b/tests/integration/test_searches.py @@ -74,11 +74,11 @@ def searches_initial_data(): m.tsk2 = f.TaskFactory.create(project=m.project1) m.tsk3 = f.TaskFactory.create(project=m.project1, subject="Back to the future") - m.iss1 = f.IssueFactory.create(project=m.project1, subject="Design and Frontend") + m.iss1 = f.IssueFactory.create(project=m.project1, subject="Backend and Frontend") m.iss2 = f.IssueFactory.create(project=m.project2) - m.iss3 = f.IssueFactory.create(project=m.project1, subject="Green Frog") + m.iss3 = f.IssueFactory.create(project=m.project1) - m.wiki1 = f.WikiPageFactory.create(project=m.project1, content="Final Frontier") + m.wiki1 = f.WikiPageFactory.create(project=m.project1) m.wiki2 = f.WikiPageFactory.create(project=m.project1, content="Frontend, future") m.wiki3 = f.WikiPageFactory.create(project=m.project2) @@ -131,20 +131,6 @@ def test_search_text_query_in_my_project(client, searches_initial_data): assert len(response.data["wikipages"]) == 0 -def test_search_partial_text_query_in_my_project(client, searches_initial_data): - data = searches_initial_data - - client.login(data.member1.user) - - response = client.get(reverse("search-list"), {"project": data.project1.id, "text": "fron"}) - assert response.status_code == 200 - assert response.data["count"] == 3 - assert len(response.data["userstories"]) == 0 - assert len(response.data["tasks"]) == 0 - assert len(response.data["issues"]) == 1 - assert len(response.data["wikipages"]) == 2 - - def test_search_text_query_with_an_invalid_project_id(client, searches_initial_data): data = searches_initial_data From 84f517559a99446be61e1af1f6952431fd9d76a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Mon, 3 Aug 2015 16:57:22 +0200 Subject: [PATCH 3/3] Revert "Add full-text index to the search app" This reverts commit b4a30f64afbedb2ff9cab3b60d800c5509457627. --- taiga/searches/migrations/0001_initial.py | 41 ----------------------- taiga/searches/migrations/__init__.py | 0 taiga/searches/services.py | 16 +++++---- 3 files changed, 9 insertions(+), 48 deletions(-) delete mode 100644 taiga/searches/migrations/0001_initial.py delete mode 100644 taiga/searches/migrations/__init__.py diff --git a/taiga/searches/migrations/0001_initial.py b/taiga/searches/migrations/0001_initial.py deleted file mode 100644 index b30cfa4d..00000000 --- a/taiga/searches/migrations/0001_initial.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('wiki', '0001_initial'), - ('userstories', '0009_remove_userstory_is_archived'), - ('issues', '0005_auto_20150623_1923'), - ('tasks', '0006_auto_20150623_1923'), - ] - - operations = [ - migrations.RunSQL( - """ - CREATE INDEX "userstories_full_text_idx" ON userstories_userstory USING gin(to_tsvector('simple', coalesce(subject, '') || ' ' || coalesce(ref) || ' ' || coalesce(description, ''))); - """, - reverse_sql="""DROP INDEX IF EXISTS "userstories_full_text_idx";""" - ), - migrations.RunSQL( - """ - CREATE INDEX "tasks_full_text_idx" ON tasks_task USING gin(to_tsvector('simple', coalesce(subject, '') || ' ' || coalesce(ref) || ' ' || coalesce(description, ''))); - """, - reverse_sql="""DROP INDEX IF EXISTS "tasks_full_text_idx";""" - ), - migrations.RunSQL( - """ - CREATE INDEX "issues_full_text_idx" ON issues_issue USING gin(to_tsvector('simple', coalesce(subject, '') || ' ' || coalesce(ref) || ' ' || coalesce(description, ''))); - """, - reverse_sql="""DROP INDEX IF EXISTS "issues_full_text_idx";""" - ), - migrations.RunSQL( - """ - CREATE INDEX "wikipages_full_text_idx" ON wiki_wikipage USING gin(to_tsvector('simple', coalesce(slug, '') || ' ' || coalesce(content, ''))); - """, - reverse_sql="""DROP INDEX IF EXISTS "wikipages_full_text_idx";""" - ), - ] diff --git a/taiga/searches/migrations/__init__.py b/taiga/searches/migrations/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/taiga/searches/services.py b/taiga/searches/services.py index 9d7d0529..495e298d 100644 --- a/taiga/searches/services.py +++ b/taiga/searches/services.py @@ -23,9 +23,10 @@ MAX_RESULTS = getattr(settings, "SEARCHES_MAX_RESULTS", 150) def search_user_stories(project, text): model_cls = apps.get_model("userstories", "UserStory") - where_clause = ("to_tsvector('simple', coalesce(userstories_userstory.subject, '') || ' ' || " - "coalesce(userstories_userstory.ref) || ' ' || " - "coalesce(userstories_userstory.description, '')) @@ plainto_tsquery(%s)") + where_clause = ("to_tsvector(coalesce(userstories_userstory.subject) || ' ' || " + "coalesce(userstories_userstory.ref) || ' ' || " + "coalesce(userstories_userstory.description, '')) " + "@@ plainto_tsquery(%s)") if text: return (model_cls.objects.extra(where=[where_clause], params=[text]) @@ -36,7 +37,7 @@ def search_user_stories(project, text): def search_tasks(project, text): model_cls = apps.get_model("tasks", "Task") - where_clause = ("to_tsvector('simple', coalesce(tasks_task.subject, '') || ' ' || " + where_clause = ("to_tsvector(coalesce(tasks_task.subject, '') || ' ' || " "coalesce(tasks_task.ref) || ' ' || " "coalesce(tasks_task.description, '')) @@ plainto_tsquery(%s)") @@ -49,7 +50,7 @@ def search_tasks(project, text): def search_issues(project, text): model_cls = apps.get_model("issues", "Issue") - where_clause = ("to_tsvector('simple', coalesce(issues_issue.subject) || ' ' || " + where_clause = ("to_tsvector(coalesce(issues_issue.subject) || ' ' || " "coalesce(issues_issue.ref) || ' ' || " "coalesce(issues_issue.description, '')) @@ plainto_tsquery(%s)") @@ -62,8 +63,9 @@ def search_issues(project, text): def search_wiki_pages(project, text): model_cls = apps.get_model("wiki", "WikiPage") - where_clause = ("to_tsvector('simple', coalesce(wiki_wikipage.slug) || ' ' || " - "coalesce(wiki_wikipage.content, '')) @@ plainto_tsquery(%s)") + where_clause = ("to_tsvector(coalesce(wiki_wikipage.slug) || ' ' || " + "coalesce(wiki_wikipage.content, '')) " + "@@ plainto_tsquery(%s)") if text: return (model_cls.objects.extra(where=[where_clause], params=[text])