Improve the search results view
This commit is contained in:
@@ -3,6 +3,7 @@ package internal
|
|||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/vcraescu/go-paginator"
|
"github.com/vcraescu/go-paginator"
|
||||||
@@ -52,6 +53,8 @@ type Context struct {
|
|||||||
Title string
|
Title string
|
||||||
Meta Meta
|
Meta Meta
|
||||||
|
|
||||||
|
Matches uint64
|
||||||
|
Duration time.Duration
|
||||||
Results Results
|
Results Results
|
||||||
Pager *paginator.Paginator
|
Pager *paginator.Paginator
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
rice "github.com/GeertJohan/go.rice"
|
rice "github.com/GeertJohan/go.rice"
|
||||||
"github.com/gomarkdown/markdown"
|
"github.com/gomarkdown/markdown"
|
||||||
@@ -184,6 +185,8 @@ func (s *Server) SearchHandler() httprouter.Handle {
|
|||||||
|
|
||||||
ctx.SearchQuery = q
|
ctx.SearchQuery = q
|
||||||
ctx.Results = results
|
ctx.Results = results
|
||||||
|
ctx.Matches = searchResults.Total
|
||||||
|
ctx.Duration = searchResults.Took.Truncate(time.Nanosecond)
|
||||||
|
|
||||||
s.render("search", w, ctx)
|
s.render("search", w, ctx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ func (i *indexer) Search(q string) (*bleve.SearchResult, error) {
|
|||||||
query := bleve.NewMatchQuery(q)
|
query := bleve.NewMatchQuery(q)
|
||||||
searchRequest := bleve.NewSearchRequest(query)
|
searchRequest := bleve.NewSearchRequest(query)
|
||||||
searchRequest.Fields = []string{"URL", "Title", "Author", "Summary", "Length"}
|
searchRequest.Fields = []string{"URL", "Title", "Author", "Summary", "Length"}
|
||||||
|
searchRequest.Highlight = bleve.NewHighlight()
|
||||||
searchResults, err := i.idx.Search(searchRequest)
|
searchResults, err := i.idx.Search(searchRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("error searching index")
|
log.WithError(err).Error("error searching index")
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -8,18 +8,19 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<article class="container">
|
<div class="container">
|
||||||
|
<p>Found {{ $.Matches }} matches in {{ $.Duration }}</p>
|
||||||
{{ with $.Results }}
|
{{ with $.Results }}
|
||||||
<ol>
|
|
||||||
{{ range . }}
|
{{ 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{{ 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>
|
<footer><a href="{{ .URL }}">{{ .URL }}</a> {{ .Length }} <a href="/cache/{{ .ID }}">View cached</a></footer>
|
||||||
{{ end }}
|
</article>
|
||||||
</ol>
|
|
||||||
<p>If your page appears here and you do not want it to, please contact <a href="/support">Support</a>.</p>
|
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<p>No search results</p>
|
<p>No search results</p>
|
||||||
{{ end }}
|
{{ 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}}
|
{{end}}
|
||||||
|
|||||||
Reference in New Issue
Block a user