Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added highlighting to the search

  • Loading branch information...
commit d088d46c604e3f0d1dfa4d2881a092960da52430 1 parent 4de38e5
@jettro authored
View
8 grails-app/controllers/SearchController.groovy
@@ -24,6 +24,14 @@ class SearchController {
}
try {
+ params.withHighlighter = {highlighter, index, sr ->
+ if (!sr.highlights) {
+ sr.highlights = []
+ }
+ def matchedFragment = highlighter.fragment("content")
+ sr.highlights[index] = "..." + (matchedFragment ?:"") + "..."
+ }
+
def searchResult = Comment.search (query,params)
return [searchResult:searchResult]
} catch (e) {
View
5 grails-app/views/search/search.gsp
@@ -36,10 +36,13 @@
</g:form>
<g:if test="${searchResult?.results}">
- <g:each var="result" in="${searchResult.results}">
+ <g:each var="result" in="${searchResult.results}" status="hitNum">
<div class="searchComment">
<g:link controller="comment" action="show" id="${result.id}">${result.name}</g:link><br/>
${result.content}
+ <p>
+ ${searchResult.highlights[hitNum]}
+ </p>
</div>
</g:each>
</g:if>
Please sign in to comment.
Something went wrong with that request. Please try again.