{{{
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.
* 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>
* 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>
* cc: Paolo Melchiorre (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:3>
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>
* cc: Jaap Roes (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:5>
* 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>
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28528#comment:7>
* 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>