Updated search functionality to limit form interactions
This commit is contained in:
parent
eab06cc1ef
commit
54d846c6c8
2 changed files with 4 additions and 4 deletions
|
@ -102,9 +102,9 @@ type SearchPage struct {
|
||||||
// The search handler of the webui
|
// The search handler of the webui
|
||||||
func searchHandler(w http.ResponseWriter, r *http.Request) error {
|
func searchHandler(w http.ResponseWriter, r *http.Request) error {
|
||||||
p := SearchPage{
|
p := SearchPage{
|
||||||
Query: strings.ToLower(r.FormValue("query")),
|
Query: r.FormValue("query"),
|
||||||
}
|
}
|
||||||
if p.Query != "" {
|
if p.Query != "" && len(p.Query) >= 3 && len(p.Query) <= 64 {
|
||||||
log.Printf("searching for: %s", p.Query)
|
log.Printf("searching for: %s", p.Query)
|
||||||
// First we reset the search options status
|
// First we reset the search options status
|
||||||
p.SearchTitle = r.FormValue("searchTitle") == "true"
|
p.SearchTitle = r.FormValue("searchTitle") == "true"
|
||||||
|
@ -112,7 +112,7 @@ func searchHandler(w http.ResponseWriter, r *http.Request) error {
|
||||||
p.SearchDescription = r.FormValue("searchDescription") == "true"
|
p.SearchDescription = r.FormValue("searchDescription") == "true"
|
||||||
p.SearchContent = r.FormValue("searchContent") == "true"
|
p.SearchContent = r.FormValue("searchContent") == "true"
|
||||||
// Then we walk the index
|
// Then we walk the index
|
||||||
words := normalizeWords(strings.Fields(p.Query))
|
words := normalizeWords(strings.Fields(strings.ToLower(p.Query)))
|
||||||
scores := make(Pairs, 0)
|
scores := make(Pairs, 0)
|
||||||
for i := 0; i < len(jsonIndex); i++ {
|
for i := 0; i < len(jsonIndex); i++ {
|
||||||
score := 0
|
score := 0
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{ define "search" }}
|
{{ define "search" }}
|
||||||
<form action="/search/" method="post">
|
<form action="/search/" method="post">
|
||||||
<input class="fullwidth" type="text" placeholder="Enter your search terms here" name="query" value="{{ .Query }}" required autofocus><br>
|
<input class="fullwidth" type="text" placeholder="Enter your search terms here" name="query" value="{{ .Query }}" minlength="3" maxlength="64" required autofocus><br>
|
||||||
<input type="checkbox" id="searchTitle" name="searchTitle" value="true"{{ if .SearchTitle }} checked{{ end }}><label for="searchTitle">Titles</label>
|
<input type="checkbox" id="searchTitle" name="searchTitle" value="true"{{ if .SearchTitle }} checked{{ end }}><label for="searchTitle">Titles</label>
|
||||||
<input type="checkbox" id="searchTags" name="searchTags" value="true"{{ if .SearchTags }} checked{{ end }}><label for="searchTags">Tags</label>
|
<input type="checkbox" id="searchTags" name="searchTags" value="true"{{ if .SearchTags }} checked{{ end }}><label for="searchTags">Tags</label>
|
||||||
<input type="checkbox" id="searchDescription" name="searchDescription" value="true"{{ if .SearchDescription }} checked{{ end }}><label for="searchDescription">Descriptions</label>
|
<input type="checkbox" id="searchDescription" name="searchDescription" value="true"{{ if .SearchDescription }} checked{{ end }}><label for="searchDescription">Descriptions</label>
|
||||||
|
|
Loading…
Add table
Reference in a new issue