I’m using Django’s full text search features, and want it to search through a model called Row, which has a JSONfield .data that has a value like:
[["A1", 87, 987, "blue"], ["B1", null, null, "white"]]
Code to do the search:
search_vector = SearchVector('data')
search_query = SearchQuery(query)
search_headline_data = SearchHeadline('data', search_query, highlight_all=True)
results = Row.objects.all()
.annotate(search=search_vector)
.annotate(headline_data=search_headline_data)
When query=”blue”, the match is a string, and highlighted correctly:
[["A1", 87, 987, "<b>blue</b>"], ["B1", null, null, "white"]]
But when query=”87″ so there’s a match with an integer, the match is not highlighted.
[["A1", 87, 987, "blue"], ["B1", null, null, "white"]]
This makes me want to cast all values in the .data JSONField to a string, but I can’t find out how to do this through annotation.