【问题标题】:CrafterCMS: How to output html body indexed by solr?CrafterCMS:如何输出由 solr 索引的 html 正文?
【发布时间】:2018-07-24 19:26:35
【问题描述】:

我在我的 RTE 中使用后缀 _html 来实现 solr 的索引功能。 但是,当我显示我的搜索结果时,我需要 html 标签而不是纯文本。有解决办法吗?

编辑:我使用地图matches = [:] 来存储我的 solr 查询的结果。我需要从每个文档结果中获取content_html 并显示它们。这是我到目前为止的进展:

时髦的:

def contents = [:]
def index = 0
// solr search results are stored in matches.faqs
for (item in matches.faqs) {
    // with a solr result document
    def aResult = executedQuery.response.documents[index]
    // look up the item
    def myContentItem = siteItemService.getSiteItem(aResult.localId)
    // get the markup you want
    contents.put('contentHtml', myContentItem.queryValue("content_html"))
    index++
}

【问题讨论】:

    标签: groovy solr crafter-cms


    【解决方案1】:

    一种方法是使用 siteItemService 从结果中简单地查找所需的 HTML:

    时髦的:

    // with a solr result document
    def aResult = executedQuery.response.documents[0]
    
    // look up the item
    def myContentItem = siteItemService.getSiteItem(aResult.localId)
    
    // get the markup you want
    def rteHtml = myContentItem.queryValue("theRTEField_html")
    

    【讨论】:

    • 这个查找速度非常快。在第一次加载项目后,每次调用几乎都是基于内存的操作。
    • 这非常有效。我如何用地图做到这一点?我有一个来自 solr 的搜索结果,它存储在地图中,需要从每个文档结果中提取 content_html。我尝试使用 for 循环,但它只得到一个 content_html
    • 为什么需要地图的内容?创建地图的问题是每个键必须不同。您可以对键执行"contentHtml@" + aResult.localId 之类的操作,但您仍然需要稍后迭代地图。
    • 是的,我意识到我不需要地图。我在<#list matches.faqs as faq> 循环内的freemarker 中使用了Russ 的代码。现在可以了。干杯。
    猜你喜欢
    • 2013-01-20
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    • 2017-10-22
    • 2018-04-26
    • 1970-01-01
    相关资源
    最近更新 更多