Improve the search results view

This commit is contained in:
James Mills
2021-02-02 23:34:18 +10:00
parent 867b7b141d
commit 4c02ee5afc
5 changed files with 20 additions and 392 deletions

View File

@@ -3,6 +3,7 @@ package internal
import (
"html/template"
"net/http"
"time"
log "github.com/sirupsen/logrus"
"github.com/vcraescu/go-paginator"
@@ -52,6 +53,8 @@ type Context struct {
Title string
Meta Meta
Matches uint64
Duration time.Duration
Results Results
Pager *paginator.Paginator

View File

@@ -5,6 +5,7 @@ import (
"html/template"
"net/http"
"strings"
"time"
rice "github.com/GeertJohan/go.rice"
"github.com/gomarkdown/markdown"
@@ -184,6 +185,8 @@ func (s *Server) SearchHandler() httprouter.Handle {
ctx.SearchQuery = q
ctx.Results = results
ctx.Matches = searchResults.Total
ctx.Duration = searchResults.Took.Truncate(time.Nanosecond)
s.render("search", w, ctx)
}

View File

@@ -47,6 +47,7 @@ func (i *indexer) Search(q string) (*bleve.SearchResult, error) {
query := bleve.NewMatchQuery(q)
searchRequest := bleve.NewSearchRequest(query)
searchRequest.Fields = []string{"URL", "Title", "Author", "Summary", "Length"}
searchRequest.Highlight = bleve.NewHighlight()
searchResults, err := i.idx.Search(searchRequest)
if err != nil {
log.WithError(err).Error("error searching index")

File diff suppressed because one or more lines are too long

View File

@@ -8,18 +8,19 @@
</button>
</form>
</div>
<article class="container">
<div class="container">
<p>Found {{ $.Matches }} matches in {{ $.Duration }}</p>
{{ with $.Results }}
<ol>
{{ range . }}
<li><a href="{{ .URL }}">{{ .Title }}</a>
<article>
<h3><a href="{{ .URL }}">{{ .Title }}</a></h3>
<p{{ if .Summary }}>{{ .Summary }}{{ else }} class="placeholder">No summary available{{ end }}</p>
<p class="small"><a href="{{ .URL }}">{{ .URL }}</a> {{ .Length }} <a href="/cache?id={{ .ID }}">View cached</a></p>
{{ end }}
</ol>
<p>If your page appears here and you do not want it to, please contact <a href="/support">Support</a>.</p>
<footer><a href="{{ .URL }}">{{ .URL }}</a> {{ .Length }} <a href="/cache/{{ .ID }}">View cached</a></footer>
</article>
{{ else }}
<p>No search results</p>
{{ end }}
</article>
{{ end }}
<small>If your page appears here and you do not want it to, please contact <a href="/support">Support</a></small>
</div>
{{end}}