Permalink
Browse files

added highlighting to the search

  • Loading branch information...
1 parent 4de38e5 commit d088d46c604e3f0d1dfa4d2881a092960da52430 @jettro committed Dec 16, 2009
Showing with 12 additions and 1 deletion.
  1. +8 −0 grails-app/controllers/SearchController.groovy
  2. +4 −1 grails-app/views/search/search.gsp
@@ -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) {
@@ -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>

0 comments on commit d088d46

Please sign in to comment.