首页 > 解决方案 > CrafterCMS:如何输出由 solr 索引的 html 正文?

问题描述

我在我的 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++
}

标签: groovysolrcrafter-cms

解决方案


一种方法是使用 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")

推荐阅读