summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornavanchauhan <navanchauhan@gmail.com>2022-10-15 20:46:26 -0600
committernavanchauhan <navanchauhan@gmail.com>2022-10-15 20:46:26 -0600
commit47c4143081176b08af8793524287710a9a0e7290 (patch)
tree0869d4ff0a135ff8635dd5081b5a885bd5a2c2a7
parent2d3b467780adea466050232f0673d4af8c09ce19 (diff)
unesacpe html and highlight
-rw-r--r--main.go25
-rw-r--r--results.gtpl2
2 files changed, 26 insertions, 1 deletions
diff --git a/main.go b/main.go
index 44f5bdc..6302b6a 100644
--- a/main.go
+++ b/main.go
@@ -57,7 +57,19 @@ func main() {
t.Execute(w, nil)
})
- searchResTemplate := template.Must(template.ParseFiles("results.gtpl"))
+ funcMap := template.FuncMap{
+ "unescapeHTML": func(s string) template.HTML {
+ return template.HTML(s)
+ },
+ }
+
+ //searchResTemplate := template.Must(template.ParseFiles("results.gtpl"))
+ searchResTemplate := template.Must(template.New("results.gtpl").Funcs(funcMap).ParseFiles("results.gtpl"))
+
+ if err != nil {
+ fmt.Println("Error parsing template")
+ os.Exit(1)
+ }
http.HandleFunc("/search", func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
@@ -84,6 +96,17 @@ func main() {
res, err := index.Search(query.Query, &meilisearch.SearchRequest{
Limit: query.MaxResults,
Offset: query.Offset,
+ AttributesToRetrieve: []string{
+ "title",
+ "applicant",
+ "submission_date",
+ "predicates",
+ "id",
+ },
+ AttributesToCrop: []string{"full_text"},
+ AttributesToHighlight: []string{"full_text"},
+ HighlightPreTag: "<mark>",
+ HighlightPostTag: "</mark>",
})
if err != nil {
diff --git a/results.gtpl b/results.gtpl
index 39e2a32..a68b122 100644
--- a/results.gtpl
+++ b/results.gtpl
@@ -10,6 +10,7 @@
<th>510(k) Number</th>
<th>Title</th>
<th>Applicant</th>
+ <th>Hit Details</th>
<th>Submission Date</th>
<th>Predicates</th>
</tr>
@@ -18,6 +19,7 @@
<td><a href="https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfPMN/pmn.cfm?ID={{.id}}">{{ .id }}</a></td>
<td>{{ .title }}</td>
<td>{{ .applicant }}</td>
+ <td>{{unescapeHTML ._formatted.full_text}}</td>
<td>{{ .submission_date }}</td>
<td>{{ range .predicates}}
<a href="https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfPMN/pmn.cfm?ID={{.}}">{{ . }}</a>,