3

我的文章正文是纺织格式的文本。我用 sphinx 进行全文搜索,我想在结果中突出显示查询。狮身人面像给我这样的东西

A *simple* _<span class="highlight">example</span>_.

我想删除所有纺织格式但保存突出显示标签,像这样

A simple <span class="highlight">example</span>.

红布宝石可以吗?

4

2 回答 2

3

您可以使用 RedCloth 处理内容,然后剥离所有标签的结果。所以像:

strip_tags (RedCloth.new(simple_input).to_html)

strip_tags 在 ActionView::Helpers::TextHelper 模块中可用。http://apidock.com/rails/ActionView/Helpers/TextHelper/strip_tags了解更多信息。

于 2011-08-06T15:11:53.730 回答
0

尚未使用 Sphinx,但从您的问题来看,似乎<span class="highlight">..</span>是 Sphinx 在将文本输出为搜索结果时添加的。

我目前不知道 RedCloth 中的任何方法,但Vidibus-Textile Gem(基于 RedCloth)添加了一个to_text方法,这可能对您的情况有用。

Ofc 你需要确保在Sphinx 添加标签之前调用它。span

于 2012-06-19T16:14:20.193 回答