Opened 4 years ago

Closed 2 years ago

#27899 closed New feature (fixed)

Phrase search query for Postgres full text search

Reported by: Ilya Semenov Owned by: Greg Allensworth
Component: contrib.postgres Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Postgres 9.6 now supports phrase search with ... @@ phraseto_tsquery('hello world'). It would be great if Django supported it natively.

Currently, django.contrib.postgres.search.SearchQuery hard-codes SQL lookup formatting:

class SearchQuery(SearchQueryCombinable, Value):
    def as_sql(self, compiler, connection):
        ...
            template = 'plainto_tsquery({}::regconfig, %s)'.format(config_sql)

I believe the lookup function should be taken from a class level variable instead, and two more classes should be introduced: PhraseSearchQuery using phraseto_tsquery, and RawSearchQuery using to_tsquery.

Change History (22)

comment:1 Changed 4 years ago by Simon Charette

Component: Uncategorizedcontrib.postgres
Triage Stage: UnreviewedAccepted
Version: 1.10master

comment:2 Changed 4 years ago by Andrii Soldatenko

I need also this feature in my project, I'm going to start working on PR.

comment:3 Changed 3 years ago by Andrii Soldatenko

Has patch: set

comment:4 Changed 3 years ago by Mads Jensen

Needs documentation: set
Patch needs improvement: set

Release notes and documentation needed.

comment:5 Changed 3 years ago by Andrii Soldatenko

Owner: changed from nobody to Andrii Soldatenko
Status: newassigned

comment:6 Changed 3 years ago by Andrii Soldatenko

Needs documentation: unset

Added docs and tests.

comment:7 Changed 3 years ago by Andrii Soldatenko

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:8 Changed 3 years ago by Tim Graham

Triage Stage: Ready for checkinAccepted

"Ready for checkin" is set by a patch reviewer, not the patch author (see Triaging tickets).

comment:9 Changed 3 years ago by Andrii Soldatenko

Sorry for that. Thanks for the link!

comment:10 Changed 3 years ago by François Freitag

Patch needs improvement: set

comment:11 Changed 2 years ago by Greg Allensworth

Hello. I wanted to check in on the status of this patch, to support phraseto_tsquery()

I ask because this one has been idle for about 14 months, in a "needs improvement" state.

I have come up with a much simpler approach to allowing phrase searching, which is smaller code changes and less code -- a simple phrase=True flag to the SearchVector

Last edited 2 years ago by Greg Allensworth (previous) (diff)

comment:12 Changed 2 years ago by Andrii Soldatenko

Sorry I don't have a free time for a long time, yes sure you can reuse my PR or create you own, if you need any help please let me know.

comment:13 Changed 2 years ago by Greg Allensworth

Owner: changed from Andrii Soldatenko to Greg Allensworth

My own internal note: I have a copy of the patched version here. https://github.com/GreenInfo-Network/Django-PostgreSQL-SearchVector

comment:14 Changed 2 years ago by Andrii Soldatenko

You need to adopt your patch to django style and create docs and tests.

comment:15 Changed 2 years ago by Greg Allensworth

Thanks, Andrii. Do you want to go ahead and close PR 8491 https://github.com/django/django/pull/8491 ?

I will open a new one later today, or tomorrow.

comment:16 Changed 2 years ago by Greg Allensworth

comment:17 Changed 2 years ago by Claude Paroz

Patch needs improvement: unset

Unchecking Patch needs improvement so your patch is back in the review queue.

comment:18 Changed 2 years ago by Claude Paroz

Needs tests: set

However tests are missing.

comment:19 Changed 2 years ago by Claude Paroz

Needs tests: unset

I added a test to Greg's patch in this PR.

comment:20 Changed 2 years ago by Tim Graham

Patch needs improvement: set

The patch may need a small change to support "to_tsquery" which is a part of PR 8491. Maybe a multivalued argument called something like search_type with values like "raw", "phrase", "plain" would be appropriate.

comment:21 Changed 2 years ago by Claude Paroz

Patch needs improvement: unset

comment:22 Changed 2 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In f5e347a:

Fixed #27899 -- Added support for phrase/raw searching in SearchQuery.

Thanks Tim Graham, Nick Pope, and Claude Paroz for contribution and review.

Note: See TracTickets for help on using tickets.
Back to Top