﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28528	Allow combining SearchVectors with different configs.	M1ha Shvn	Adam Boaler	"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?


"	Cleanup/optimization	closed	contrib.postgres	dev	Normal	fixed	SearchQueries PostgreSQL FullTextSearch	Marc Tamlyn Paolo Melchiorre Jaap Roes	Ready for checkin	1	0	0	0	0	0
