diff -r --unified a/django/contrib/postgres/search.py b/django/contrib/postgres/search.py
a
|
b
|
|
179 | 179 | _output_field = FloatField() |
180 | 180 | |
181 | 181 | def __init__(self, vector, query, **extra): |
182 | | if not hasattr(vector, 'resolve_expression'): |
183 | | vector = SearchVector(vector) |
184 | 182 | if not hasattr(query, 'resolve_expression'): |
185 | 183 | query = SearchQuery(query) |
186 | 184 | weights = extra.get('weights') |
… |
… |
|
203 | 201 | ) |
204 | 202 | return sql, extra_params + params |
205 | 203 | |
| 204 | def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False): |
| 205 | resolved = super(SearchRank, self).resolve_expression(query, allow_joins, reuse, summarize, for_save) |
| 206 | resolved_source_expressions = resolved.get_source_expressions() |
| 207 | if not isinstance(resolved_source_expressions[0].output_field, SearchVectorField): |
| 208 | vector_resolved_expression = SearchVector(self.get_source_expressions()[0]).resolve_expression(query, allow_joins, reuse, summarize) |
| 209 | resolved.set_source_expressions([vector_resolved_expression] + resolved_source_expressions[1:]) |
| 210 | return resolved |
206 | 211 | |
207 | 212 | SearchVectorField.register_lookup(SearchVectorExact) |
208 | 213 | |
diff -r --unified a/tests/postgres_tests/test_search.py b/tests/postgres_tests/test_search.py
a
|
b
|
|
112 | 112 | searched = Line.objects.filter(dialogue_search_vector=SearchQuery('cadeaux', config='french')) |
113 | 113 | self.assertSequenceEqual(searched, [self.french]) |
114 | 114 | |
| 115 | def test_existing_vector_ranking(self): |
| 116 | Line.objects.update(dialogue_search_vector=SearchVector('dialogue')) |
| 117 | searched = Line.objects.filter(character=self.minstrel).annotate( |
| 118 | rank=SearchRank('dialogue_search_vector', SearchQuery('brave sir robin')), |
| 119 | ).order_by('rank') |
| 120 | self.assertSequenceEqual(searched, [self.verse2, self.verse1, self.verse0]) |
| 121 | |
115 | 122 | |
116 | 123 | class MultipleFieldsTest(GrailTestData, PostgreSQLTestCase): |
117 | 124 | |