Opened 8 years ago

Closed 6 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: dev
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 by Simon Charette, 8 years ago

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

comment:2 by Andrii Soldatenko, 8 years ago

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

comment:3 by Andrii Soldatenko, 8 years ago

Has patch: set

comment:4 by Mads Jensen, 8 years ago

Needs documentation: set
Patch needs improvement: set

Release notes and documentation needed.

comment:5 by Andrii Soldatenko, 8 years ago

Owner: changed from nobody to Andrii Soldatenko
Status: newassigned

comment:6 by Andrii Soldatenko, 8 years ago

Needs documentation: unset

Added docs and tests.

comment:7 by Andrii Soldatenko, 7 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:8 by Tim Graham, 7 years ago

Triage Stage: Ready for checkinAccepted

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

comment:9 by Andrii Soldatenko, 7 years ago

Sorry for that. Thanks for the link!

comment:10 by François Freitag, 7 years ago

Patch needs improvement: set

comment:11 by Greg Allensworth, 6 years ago

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 6 years ago by Greg Allensworth (previous) (diff)

comment:12 by Andrii Soldatenko, 6 years ago

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 by Greg Allensworth, 6 years ago

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 by Andrii Soldatenko, 6 years ago

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

comment:15 by Greg Allensworth, 6 years ago

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 by Greg Allensworth, 6 years ago

comment:17 by Claude Paroz, 6 years ago

Patch needs improvement: unset

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

comment:18 by Claude Paroz, 6 years ago

Needs tests: set

However tests are missing.

comment:19 by Claude Paroz, 6 years ago

Needs tests: unset

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

comment:20 by Tim Graham, 6 years ago

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 by Claude Paroz, 6 years ago

Patch needs improvement: unset

comment:22 by Tim Graham <timograham@…>, 6 years ago

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