我想用SearchHeadline突出显示搜索词。我的代码是这样的:
query = SearchQuery('cat')
vector = SearchVector('caption')
Post.objects.annotate(
search=vector
headline=SearchHeadline(
'caption',
query
)
).filter(search=query)
此代码运行良好,例如,第一个结果的标题是:
'My <b>cat</b> breed is Persian. Persian cats are the most beautiful breed.'
如您所见cat
高亮显示,但cats
未高亮显示,我想高亮显示标题中的所有cat
字符串,如下所示:
'My <b>cat</b> breed is Persian. Persian <b>cat</b>s are the most beautiful breed.'
您可以使用icontains在单词和句子中搜索特定术语
相关问题 更多 >
编程相关推荐