diff --git a/web/api.go b/web/api.go index 8eca3458..398613bb 100644 --- a/web/api.go +++ b/web/api.go @@ -107,7 +107,8 @@ type Repository struct { // PrintInput is provided to the server.Print template. type PrintInput struct { - Repo, Name string - Lines []string - Last LastInput + Repo, Name string + Lines []string + Last LastInput + FileMatches []*FileMatch } diff --git a/web/server.go b/web/server.go index ef08e989..897e57f1 100644 --- a/web/server.go +++ b/web/server.go @@ -42,6 +42,28 @@ var Funcmap = template.FuncMap{ "More": func(orig int) int { return orig * 3 }, + "IsLangFilterChecked": func(query, lang string) bool { + return strings.Contains(query, "lang:"+lang) + }, + "IsRepoFilterChecked": func(query, repo string) bool { + return strings.Contains(query, "r:"+repo) + }, + "Repos": func(fileMatches []*FileMatch) map[string]int { + repos := make(map[string]int) + for _, fileMatch := range fileMatches { + repos[fileMatch.Repo]++ + } + + return repos + }, + "Languages": func(fileMatches []*FileMatch) map[string]int { + languages := make(map[string]int) + for _, fileMatch := range fileMatches { + languages[fileMatch.Language]++ + } + + return languages + }, "HumanUnit": func(orig int64) string { b := orig suffix := "" @@ -542,6 +564,11 @@ func (s *Server) servePrintErr(w http.ResponseWriter, r *http.Request) error { strLines = append(strLines, string(l)) } + fileMatches, err := s.formatResults(result, queryStr, s.Print) + if err != nil { + return err + } + d := PrintInput{ Name: f.FileName, Repo: f.Repository, @@ -551,6 +578,7 @@ func (s *Server) servePrintErr(w http.ResponseWriter, r *http.Request) error { Num: num, AutoFocus: false, }, + FileMatches: fileMatches, } var buf bytes.Buffer diff --git a/web/templates.go b/web/templates.go index 310101f1..51221b1a 100644 --- a/web/templates.go +++ b/web/templates.go @@ -75,6 +75,13 @@ var TemplateText = map[string]string{ padding: unset; overflow: unset; } + + .info-count { + margin-bottom: 0.5rem; + display: flex; + justify-content: space-between; + } + :target { background-color: #ccf; } table tbody tr td { border: none !important; padding: 2px !important; } @@ -122,15 +129,61 @@ var TemplateText = map[string]string{
Max Results
- +
- + + + @@ -205,49 +258,70 @@ var TemplateText = map[string]string{ window.location.href = "/search?q=" + escape("{{.QueryStr}}" + " " + atom) + "&" + "num=" + {{.Last.Num}}; } + + function addFilter(filter) { + var searchBox = document.getElementById("navsearchbox"); + var search = document.querySelector(".btn.btn-primary"); + + var oldQuery = searchBox.value.trim(); + + if (oldQuery.includes(filter)) { + searchBox.value = oldQuery.replace(filter, ''); + search.click(); + return; + } + + searchBox.value = (oldQuery + ' ' + filter).trim(); + search.click(); + } + + - {{template "navbar" .Last}} -
-
- {{if .Stats.Crashes}}
{{.Stats.Crashes}} shards crashed
{{end}} - {{ $fileCount := len .FileMatches }} - Found {{.Stats.MatchCount}} results in {{.Stats.FileCount}} files{{if or (lt $fileCount .Stats.FileCount) (or (gt .Stats.ShardsSkipped 0) (gt .Stats.FilesSkipped 0)) }}, - showing top {{ $fileCount }} files (show more). - {{else}}.{{end}} -
- {{range .FileMatches}} - - - - - - - {{if not .DuplicateID}} - - {{range .Matches}} - - - + {{template "navbar" .}} +
+
+
+ {{if .Stats.Crashes}}
{{.Stats.Crashes}} shards crashed
{{end}} + {{ $fileCount := len .FileMatches }} + Found {{.Stats.MatchCount}} results in {{.Stats.FileCount}} files{{if or (lt $fileCount .Stats.FileCount) (or (gt .Stats.ShardsSkipped 0) (gt .Stats.FilesSkipped 0)) }}, + showing top {{ $fileCount }} files (show more). + {{else}}.{{end}} +
+ {{range .FileMatches}} +
- {{if .URL}}{{else}}{{end}} - - {{.Repo}}:{{.FileName}}: - [ {{if .Branches}}{{range .Branches}}{{.}},{{end}}{{end}} ] - {{if .Language}}{{end}} - {{if .DuplicateID}}Duplicate result{{end}} - -
-
{{if .URL}}{{end}}{{.LineNum}}{{if .URL}}{{end}}: {{range .Fragments}}{{LimitPre 100 .Pre}}{{.Match}}{{LimitPost 100 .Post}}{{end}}
-
+ + + + + + {{if not .DuplicateID}} + + {{range .Matches}} + + + + {{end}} + {{end}} - +
+ {{if .URL}}{{else}}{{end}} + + {{.Repo}}:{{.FileName}}: + [ {{if .Branches}}{{range .Branches}}{{.}},{{end}}{{end}} ] + {{if .Language}}{{end}} + {{if .DuplicateID}}Duplicate result{{end}} + +
+
{{if .URL}}{{end}}{{.LineNum}}{{if .URL}}{{end}}: {{range .Fragments}}{{LimitPre 100 .Pre}}{{.Match}}{{LimitPost 100 .Post}}{{end}}
+
{{end}} - - {{end}} +
+ - {{ template "jsdep"}} `, - "repolist": ` {{template "head"}}
- {{template "navbar" .Last}} + {{template "navbar" .}}
Found {{.Stats.Repos}} repositories ({{.Stats.Documents}} files, {{HumanUnit .Stats.ContentBytes}}b content)
@@ -321,7 +393,7 @@ var TemplateText = map[string]string{ {{template "head"}} {{.Repo}}:{{.Name}} - {{template "navbar" .Last}} + {{template "navbar" .}}
{{ range $index, $ln := .Lines}}