[Django] #28528: Can't combine 2 SearchVector-s with different configs

43 views
Skip to first unread message

Django

unread,
Aug 25, 2017, 3:35:55 AM8/25/17
to django-...@googlegroups.com
#28528: Can't combine 2 SearchVector-s with different configs
-------------------------------------+-------------------------------------
Reporter: M1ha Shvn | Owner: (none)
Type: Bug | Status: new
Component: | Version: 1.10
contrib.postgres | Keywords: SearchQueries
Severity: Normal | PostgreSQL FullTextSearch
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hey!
I'm trying to make a fulltext search on 2 languages: russian and english.
I've created GIN index for 2 languages in PostgreSQL and select query
works fine using an index:

{{{
CREATE INDEX CONCURRENTLY messages_conversationpart_body ON
messages_conversationpart USING gin((to_tsvector('russian', body) ||
to_tsvector('english', body)));
SELECT id, body FROM messages_conversationpart WHERE
(to_tsvector('russian', body) || to_tsvector('english', body)) @@
(to_tsquery('russian', 'cats') || to_tsquery('english', 'cats')) LIMIT 20;
}}}

Then I've found
[https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/search/ this]
article and desided to form this query using django. Here's the result:

{{{
from django.contrib.postgres.search import SearchVector, SearchQuery
from messages.models import ConversationPart
qs = ConversationPart.objects.\
annotate(search=SearchVector('body', config='russian') +
SearchVector('body', config='english')).\
filter(search=SearchQuery(search_phrase, config='russian') |
SearchQuery(search_phrase, config='english'))
qs = qs[:20]
}}}

But attempt to execute this query returns TypeError: SearchVector can only
be combined with other SearchVectors
The reason is
[https://docs.djangoproject.com/id/1.10/_modules/django/contrib/postgres/search/
here]:

{{{
class SearchVectorCombinable(object):
ADD = '||'

def _combine(self, other, connector, reversed, node=None):
if not isinstance(other, SearchVectorCombinable) or not
self.config == other.config:
raise TypeError('SearchVector can only be combined with other
SearchVectors')
if reversed:
return CombinedSearchVector(other, connector, self,
self.config)
return CombinedSearchVector(self, connector, other, self.config)
}}}

So, what is the reason for config equality control?

--
Ticket URL: <https://code.djangoproject.com/ticket/28528>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 28, 2017, 10:36:15 AM8/28/17
to django-...@googlegroups.com
#28528: Can't combine 2 SearchVector-s with different configs
-------------------------------------+-------------------------------------
Reporter: M1ha Shvn | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:
Keywords: SearchQueries | Triage Stage:
PostgreSQL FullTextSearch | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* cc: Marc Tamlyn (added)


Comment:

Marc, can you say if that restriction could be removed?

--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:1>

Django

unread,
Sep 28, 2017, 2:10:37 PM9/28/17
to django-...@googlegroups.com
#28528: Allow combining SearchVectors with different configs

-------------------------------------+-------------------------------------
Reporter: M1ha Shvn | Owner: (none)
Type: | Status: new
Cleanup/optimization |

Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:
Keywords: SearchQueries | Triage Stage: Accepted
PostgreSQL FullTextSearch |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted
* type: Bug => Cleanup/optimization


Comment:

Tentatively accepting -- someone more knowledgeable than I is welcome to
close it if it's infeasible.

--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:2>

Django

unread,
Nov 9, 2017, 10:04:17 AM11/9/17
to django-...@googlegroups.com
#28528: Allow combining SearchVectors with different configs

-------------------------------------+-------------------------------------
Reporter: M1ha Shvn | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:
Keywords: SearchQueries | Triage Stage: Accepted
PostgreSQL FullTextSearch |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Paolo Melchiorre):

* cc: Paolo Melchiorre (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:3>

Django

unread,
Nov 19, 2018, 10:38:31 AM11/19/18
to django-...@googlegroups.com
#28528: Allow combining SearchVectors with different configs

-------------------------------------+-------------------------------------
Reporter: M1ha Shvn | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:
Keywords: SearchQueries | Triage Stage: Accepted
PostgreSQL FullTextSearch |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jaap Roes):

The same restriction is applied to `SearchQueryCombinable` with a more
specific error message `TypeError("SearchQuery configs don't match.")`.

I'm not sure if this restriction makes sense. In sql it seems to be
allowed `SELECT to_tsquery('simple', 'working') || to_tsquery('english',
'working')` > `'working' | 'work'`

--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:4>

Django

unread,
Nov 19, 2018, 10:42:57 AM11/19/18
to django-...@googlegroups.com
#28528: Allow combining SearchVectors with different configs

-------------------------------------+-------------------------------------
Reporter: M1ha Shvn | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:
Keywords: SearchQueries | Triage Stage: Accepted
PostgreSQL FullTextSearch |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jaap Roes):

* cc: Jaap Roes (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:5>

Django

unread,
Feb 5, 2020, 1:46:38 AM2/5/20
to django-...@googlegroups.com
#28528: Allow combining SearchVectors with different configs
-------------------------------------+-------------------------------------
Reporter: M1ha Shvn | Owner: adamb70
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.postgres | Version: master

Severity: Normal | Resolution:
Keywords: SearchQueries | Triage Stage: Accepted
PostgreSQL FullTextSearch |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* owner: (none) => adamb70
* status: new => assigned
* has_patch: 0 => 1
* version: 1.10 => master
* needs_tests: 0 => 1


Comment:

[https://github.com/django/django/pull/12418 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:6>

Django

unread,
Feb 6, 2020, 1:57:03 AM2/6/20
to django-...@googlegroups.com
#28528: Allow combining SearchVectors with different configs.
-------------------------------------+-------------------------------------

Reporter: M1ha Shvn | Owner: adamb70
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: SearchQueries | Triage Stage: Ready for
PostgreSQL FullTextSearch | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:7>

Django

unread,
Feb 6, 2020, 2:20:31 AM2/6/20
to django-...@googlegroups.com
#28528: Allow combining SearchVectors with different configs.
-------------------------------------+-------------------------------------
Reporter: M1ha Shvn | Owner: adamb70
Type: | Status: closed

Cleanup/optimization |
Component: contrib.postgres | Version: master
Severity: Normal | Resolution: fixed

Keywords: SearchQueries | Triage Stage: Ready for
PostgreSQL FullTextSearch | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"4c6ab1f2aa2a99d17ab308c0156f971a13d3fcaf" 4c6ab1f]:
{{{
#!CommitTicketReference repository=""
revision="4c6ab1f2aa2a99d17ab308c0156f971a13d3fcaf"
Fixed #28528 -- Allowed combining SearchVectors with different configs.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:8>

Reply all
Reply to author
Forward
0 new messages