Tests to demonstrate the bug

This commit is contained in:
Matt Molyneaux 2018-04-26 23:01:08 +01:00
parent 7b8f3fca4f
commit 6d9d03b5c0
1 changed files with 21 additions and 0 deletions

View File

@ -23,6 +23,7 @@ from django.conf import settings
from django.contrib.auth.models import User
from django import template
from django.utils.encoding import force_text
from django.db.models import Case, When, Value, IntegerField
from watson import search as watson
from watson.models import SearchEntry
@ -527,6 +528,26 @@ class SearchTest(SearchTestBase):
)
).get().title, "title model1 instance11")
def testReferencingWatsonRankInAnnotations(self):
"""We should be able to reference watson_rank from annotate expressions"""
entries = watson.search("model1").annotate(
relevant=Case(
When(watson_rank__gt=1.0, then=Value(1)),
default_value=Value(0),
output_field=IntegerField()
)
)
# watson_rank does not return the same value across backends, so we
# can't hard code what those will be. In some cases (e.g. the regex
# backend) all ranking is hard coded to 1.0. That doesn't matter - we
# just want to make sure that Django is able to construct a valid query
for entry in entries:
if entry.watson_rank > 1.0:
self.assertTrue(entry.relevant)
else:
self.assertFalse(entry.relevant)
class LiveFilterSearchTest(SearchTest):