#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.6d5a9d54daed1dcc425fb7ce5b2d282e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to