Solr、晒伤 (python) 和突出显示:操作方法?
将 sunburnt 的突出显示响应实现到应用程序(在本例中基于 django)的最佳方法是什么?
此链接显示了响应的结构。
正如他们所说
结果显示为字典的字典
,这是足够容易理解的。我不明白的是:
文本用 HTML 突出显示,并且片段应该适合直接放入搜索模板
我如何“将片段放入模板中”?在示例中,他们确实突出显示了“游戏”一词。我如何使用这些突出显示的片段?我是否必须对我的文本执行“搜索并替换正则表达式”?还有另一种(希望更聪明的)方法来处理这个问题吗?
这次我真的很困惑,想不出任何解决办法。 预先感谢大家。
What's the best way to implement sunburnt's highlight response into an application (django based, in this case)?
This link shows how's the response structured.
As they say
The results are shown as a dictionary of dictionaries
which is fair understandable enough. What i don't understand is this:
The text is highlighted with HTML, and the fragments should be suitable for dropping straight into a search template
How can i "drop the fragments in the template"? In the example they do highlight the word "Game". How can I use those highlighted fragments? Do i have to do a "search-and-replace regex" on my text? Is there another (hopefully smarter) way to deal with this?
I'm really stuck this time, and cannot come up with any solution.
Thanks all in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要突出显示的文本已被 包围。标签。因此,如果您按原样呈现结果文本(在发送的响应 HTML 中),突出显示的单词将以粗体显示(因为它们周围有 标签)。
如果您希望以不同方式突出显示,可以使用 CSS 来实现。例如:
在你的 CSS 中,会以黄色突出显示匹配项。
The text to be highlighted is already surrounded by <em> tags. So, if you render the result text as is (in the response HTML that's sent across), highlighted words would appear in bold (because of the <em> tag surrounding them).
If you'd like it to be highlighted differently, you can do that with CSS. Something like:
in your css, would highlight the matches in yellow, for example.