2

I used the suffix _html in my RTEs for solr's indexing functionality. However, when I display my search result, I need the html tags rather than the plain text. Is there a work around to do this?

Edit: I use a map, matches = [:], to store the results of my solr query. I need to get the content_html from each document results and display them. Here's my progress so far:

Groovy:

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++
}

1 Answers1

2

One approach is to simply lookup the HTML you need from your result using the siteItemService:

Groovy:

// 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")
Russ Danner
  • 693
  • 3
  • 11
  • This lookup is really fast. It's almost always a memory-based operation on every call after the first time an item is loaded. – Russ Danner Jul 23 '18 at 13:18
  • This works perfectly. How do I do it with a map? I have a search result from solr which I stored in a map and needs to extract the `content_html` from each document result. I tried to use a for loop but it only gets one `content_html` – Cleon Greyjoy Jul 24 '18 at 09:47
  • Why do you need the content a map? The problem of creating a map is that each key must be different. You can do something like `"contentHtml@" + aResult.localId` for the keys, but you would still need to iterate the map later. – Alfonso Vasquez Jul 24 '18 at 22:20
  • 1
    Yes I realized I don't need the map. I used Russ' code in my freemarker inside the `<#list matches.faqs as faq>` loop. It works now. Cheers. – Cleon Greyjoy Jul 25 '18 at 03:49