Merge pull request #373 from taigaio/full-index-for-searches
Add full-text index to the search appremotes/origin/enhancement/email-actions
commit
02ee9c8085
|
@ -0,0 +1,41 @@
|
||||||
|
# -*- 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";"""
|
||||||
|
),
|
||||||
|
]
|
|
@ -23,9 +23,9 @@ MAX_RESULTS = getattr(settings, "SEARCHES_MAX_RESULTS", 150)
|
||||||
|
|
||||||
def search_user_stories(project, text):
|
def search_user_stories(project, text):
|
||||||
model_cls = apps.get_model("userstories", "UserStory")
|
model_cls = apps.get_model("userstories", "UserStory")
|
||||||
where_clause = ("to_tsvector(coalesce(userstories_userstory.subject) || ' ' || "
|
where_clause = ("to_tsvector('simple', coalesce(userstories_userstory.subject, '') || ' ' || "
|
||||||
"coalesce(userstories_userstory.ref) || ' ' || "
|
"coalesce(userstories_userstory.ref) || ' ' || "
|
||||||
"coalesce(userstories_userstory.description)) @@ to_tsquery(%s)")
|
"coalesce(userstories_userstory.description, '')) @@ to_tsquery(%s)")
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
text += ":*"
|
text += ":*"
|
||||||
|
@ -37,7 +37,7 @@ def search_user_stories(project, text):
|
||||||
|
|
||||||
def search_tasks(project, text):
|
def search_tasks(project, text):
|
||||||
model_cls = apps.get_model("tasks", "Task")
|
model_cls = apps.get_model("tasks", "Task")
|
||||||
where_clause = ("to_tsvector(coalesce(tasks_task.subject, '') || ' ' || "
|
where_clause = ("to_tsvector('simple', coalesce(tasks_task.subject, '') || ' ' || "
|
||||||
"coalesce(tasks_task.ref) || ' ' || "
|
"coalesce(tasks_task.ref) || ' ' || "
|
||||||
"coalesce(tasks_task.description, '')) @@ to_tsquery(%s)")
|
"coalesce(tasks_task.description, '')) @@ to_tsquery(%s)")
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ def search_tasks(project, text):
|
||||||
|
|
||||||
def search_issues(project, text):
|
def search_issues(project, text):
|
||||||
model_cls = apps.get_model("issues", "Issue")
|
model_cls = apps.get_model("issues", "Issue")
|
||||||
where_clause = ("to_tsvector(coalesce(issues_issue.subject) || ' ' || "
|
where_clause = ("to_tsvector('simple', coalesce(issues_issue.subject) || ' ' || "
|
||||||
"coalesce(issues_issue.ref) || ' ' || "
|
"coalesce(issues_issue.ref) || ' ' || "
|
||||||
"coalesce(issues_issue.description)) @@ to_tsquery(%s)")
|
"coalesce(issues_issue.description)) @@ to_tsquery(%s)")
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ def search_issues(project, text):
|
||||||
|
|
||||||
def search_wiki_pages(project, text):
|
def search_wiki_pages(project, text):
|
||||||
model_cls = apps.get_model("wiki", "WikiPage")
|
model_cls = apps.get_model("wiki", "WikiPage")
|
||||||
where_clause = ("to_tsvector(coalesce(wiki_wikipage.slug) || ' ' || coalesce(wiki_wikipage.content)) "
|
where_clause = ("to_tsvector('simple', coalesce(wiki_wikipage.slug) || ' ' || coalesce(wiki_wikipage.content)) "
|
||||||
"@@ to_tsquery(%s)")
|
"@@ to_tsquery(%s)")
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
|
|
Loading…
Reference in New Issue