Merge pull request #366 from taigaio/issue/2584/global-search-with-partial-words
Add support for partial words on global searchesremotes/origin/enhancement/email-actions
commit
4a9eb9b7d3
|
@ -25,9 +25,10 @@ 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(coalesce(userstories_userstory.subject) || ' ' || "
|
||||||
"coalesce(userstories_userstory.ref) || ' ' || "
|
"coalesce(userstories_userstory.ref) || ' ' || "
|
||||||
"coalesce(userstories_userstory.description)) @@ plainto_tsquery(%s)")
|
"coalesce(userstories_userstory.description)) @@ to_tsquery(%s)")
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
|
text += ":*"
|
||||||
return (model_cls.objects.extra(where=[where_clause], params=[text])
|
return (model_cls.objects.extra(where=[where_clause], params=[text])
|
||||||
.filter(project_id=project.pk)[:MAX_RESULTS])
|
.filter(project_id=project.pk)[:MAX_RESULTS])
|
||||||
|
|
||||||
|
@ -38,9 +39,10 @@ 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(coalesce(tasks_task.subject, '') || ' ' || "
|
||||||
"coalesce(tasks_task.ref) || ' ' || "
|
"coalesce(tasks_task.ref) || ' ' || "
|
||||||
"coalesce(tasks_task.description, '')) @@ plainto_tsquery(%s)")
|
"coalesce(tasks_task.description, '')) @@ to_tsquery(%s)")
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
|
text += ":*"
|
||||||
return (model_cls.objects.extra(where=[where_clause], params=[text])
|
return (model_cls.objects.extra(where=[where_clause], params=[text])
|
||||||
.filter(project_id=project.pk)[:MAX_RESULTS])
|
.filter(project_id=project.pk)[:MAX_RESULTS])
|
||||||
|
|
||||||
|
@ -51,9 +53,10 @@ 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(coalesce(issues_issue.subject) || ' ' || "
|
||||||
"coalesce(issues_issue.ref) || ' ' || "
|
"coalesce(issues_issue.ref) || ' ' || "
|
||||||
"coalesce(issues_issue.description)) @@ plainto_tsquery(%s)")
|
"coalesce(issues_issue.description)) @@ to_tsquery(%s)")
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
|
text += ":*"
|
||||||
return (model_cls.objects.extra(where=[where_clause], params=[text])
|
return (model_cls.objects.extra(where=[where_clause], params=[text])
|
||||||
.filter(project_id=project.pk)[:MAX_RESULTS])
|
.filter(project_id=project.pk)[:MAX_RESULTS])
|
||||||
|
|
||||||
|
@ -63,9 +66,10 @@ 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(coalesce(wiki_wikipage.slug) || ' ' || coalesce(wiki_wikipage.content)) "
|
||||||
"@@ plainto_tsquery(%s)")
|
"@@ to_tsquery(%s)")
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
|
text += ":*"
|
||||||
return (model_cls.objects.extra(where=[where_clause], params=[text])
|
return (model_cls.objects.extra(where=[where_clause], params=[text])
|
||||||
.filter(project_id=project.pk)[:MAX_RESULTS])
|
.filter(project_id=project.pk)[:MAX_RESULTS])
|
||||||
|
|
||||||
|
|
|
@ -74,11 +74,11 @@ def searches_initial_data():
|
||||||
m.tsk2 = f.TaskFactory.create(project=m.project1)
|
m.tsk2 = f.TaskFactory.create(project=m.project1)
|
||||||
m.tsk3 = f.TaskFactory.create(project=m.project1, subject="Back to the future")
|
m.tsk3 = f.TaskFactory.create(project=m.project1, subject="Back to the future")
|
||||||
|
|
||||||
m.iss1 = f.IssueFactory.create(project=m.project1, subject="Backend and Frontend")
|
m.iss1 = f.IssueFactory.create(project=m.project1, subject="Design and Frontend")
|
||||||
m.iss2 = f.IssueFactory.create(project=m.project2)
|
m.iss2 = f.IssueFactory.create(project=m.project2)
|
||||||
m.iss3 = f.IssueFactory.create(project=m.project1)
|
m.iss3 = f.IssueFactory.create(project=m.project1, subject="Green Frog")
|
||||||
|
|
||||||
m.wiki1 = f.WikiPageFactory.create(project=m.project1)
|
m.wiki1 = f.WikiPageFactory.create(project=m.project1, content="Final Frontier")
|
||||||
m.wiki2 = f.WikiPageFactory.create(project=m.project1, content="Frontend, future")
|
m.wiki2 = f.WikiPageFactory.create(project=m.project1, content="Frontend, future")
|
||||||
m.wiki3 = f.WikiPageFactory.create(project=m.project2)
|
m.wiki3 = f.WikiPageFactory.create(project=m.project2)
|
||||||
|
|
||||||
|
@ -131,6 +131,20 @@ def test_search_text_query_in_my_project(client, searches_initial_data):
|
||||||
assert len(response.data["wikipages"]) == 0
|
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):
|
def test_search_text_query_with_an_invalid_project_id(client, searches_initial_data):
|
||||||
data = searches_initial_data
|
data = searches_initial_data
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue