Browse Source

[GinS] Extended search introduced

adds the ability for fuzzy and exact term matching
cgars 7 years ago
parent
commit
09c892dabd

+ 16 - 4
routes/search.go

@@ -9,6 +9,8 @@ import (
 	"io/ioutil"
 	"github.com/G-Node/gogs/pkg/setting"
 	"fmt"
+	"strconv"
+	"github.com/Sirupsen/logrus"
 )
 
 const (
@@ -16,7 +18,7 @@ const (
 	EXPLORE_COMMITS = "explore/commits"
 )
 
-func Search(c *context.Context, keywords string) ([]byte, error) {
+func Search(c *context.Context, keywords string, sType int64) ([]byte, error) {
 	if ! c.IsLogged {
 		c.Status(http.StatusUnauthorized)
 		return nil, fmt.Errorf("User nor logged in")
@@ -26,7 +28,7 @@ func Search(c *context.Context, keywords string) ([]byte, error) {
 		return nil, fmt.Errorf("Extended search not implemented")
 	}
 	ireq := gindex.SearchRequest{Token: c.GetCookie(setting.SessionConfig.CookieName), UserID: c.User.ID,
-		Querry: keywords, CsrfT: c.GetCookie(setting.CSRFCookieName)}
+		Querry: keywords, CsrfT: c.GetCookie(setting.CSRFCookieName), SType: sType}
 	data, err := json.Marshal(ireq)
 	if err != nil {
 		c.Status(http.StatusInternalServerError)
@@ -53,7 +55,12 @@ func ExploreData(c *context.Context) {
 	c.Data["PageIsExploreData"] = true
 
 	keywords := c.Query("q")
-	data, err := Search(c, keywords)
+	sType, err := strconv.ParseInt(c.Query("stype"), 10, 0)
+	if err != nil {
+		logrus.Errorf("Serach type not understood:%+v", err)
+		sType = 0
+	}
+	data, err := Search(c, keywords, sType)
 
 	if err != nil {
 		c.Handle(http.StatusInternalServerError, "Could nor querry", err)
@@ -76,7 +83,12 @@ func ExploreCommits(c *context.Context) {
 	c.Data["PageIsExploreCommits"] = true
 
 	keywords := c.Query("q")
-	data, err := Search(c, keywords)
+	sType, err := strconv.ParseInt(c.Query("stype"), 10, 0)
+	if err != nil {
+		logrus.Errorf("Serach type not understood:%+v", err)
+		sType = 0
+	}
+	data, err := Search(c, keywords, sType)
 
 	if err != nil {
 		c.Handle(http.StatusInternalServerError, "Could nor querry", err)

+ 1 - 1
templates/explore/data.tmpl

@@ -4,7 +4,7 @@
 		<div class="ui grid">
 			{{template "explore/navbar" .}}
 			<div class="twelve wide column content">
-				{{template "explore/search" .}}
+				{{template "explore/search_ext" .}}
 				{{template "explore/blob_list" .}}
 				{{template "explore/page" .}}
 			</div>

+ 1 - 1
templates/explore/search.tmpl

@@ -1,6 +1,6 @@
 <form class="ui form">
 	<div class="ui fluid action input">
-		<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
+		<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr " explore.search"}}..." autofocus>
 		<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
 	</div>
 </form>

+ 12 - 0
templates/explore/search_ext.tmpl

@@ -0,0 +1,12 @@
+<form class="ui form">
+	<div class="ui fluid action input">
+		<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr " explore.search"}}..." autofocus>
+		<select class="ui dropdown" name="stype" id="search-type-select">
+			<option value="0">Match</option>
+			<option value="1">Fuzzy</option>
+			<option value="2">Exact</option>
+		</select>
+		<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
+	</div>
+</form>
+<div class="ui divider"></div>

+ 1 - 0
vendor/github.com/G-Node/gin-dex/gindex/gindex.go

@@ -5,6 +5,7 @@ type SearchRequest struct {
 	CsrfT  string
 	UserID int64
 	Querry string
+	SType  int64
 }
 
 type IndexRequest struct {