gddo-server: Remove the gae_search flag.

Use app engine's main function to start the server by default. GAE
search is also enabled by default. API search is also using the new
search algorithm.

Developers will need to install Google Cloud SDK to use dev_appserver
in order to run the search api locally. The development setup will be
updated as soon as this CL is submitted.

Change-Id: Idae7a88949b2757977d0ab33628564451a1dddd3
Reviewed-on: https://go-review.googlesource.com/25360
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
diff --git a/database/database.go b/database/database.go
index 1a82e02..9f721a5 100644
--- a/database/database.go
+++ b/database/database.go
@@ -85,7 +85,6 @@
 	RedisServer      = "redis://127.0.0.1:6379" // URL of Redis server
 	RedisIdleTimeout = 250 * time.Second        // Close Redis connections after remaining idle for this duration.
 	RedisLog         = false                    // Log database commands
-	GAESearch        = false                    // Use GAE Search API in the search function.
 )
 
 func dialDb() (c redis.Conn, err error) {
@@ -274,28 +273,26 @@
 		return err
 	}
 
-	if GAESearch {
-		id, n, err := pkgIDAndImportCount(c, pdoc.ImportPath)
-		if err != nil {
-			return err
+	id, n, err := pkgIDAndImportCount(c, pdoc.ImportPath)
+	if err != nil {
+		return err
+	}
+	ctx := bgCtx()
+
+	if score > 0 {
+		if err := PutIndex(ctx, pdoc, id, score, n); err != nil {
+			log.Printf("Cannot put %q in index: %v", pdoc.ImportPath, err)
 		}
-		ctx := bgCtx()
 
-		if score > 0 {
-			if err := PutIndex(ctx, pdoc, id, score, n); err != nil {
-				log.Printf("Cannot put %q in index: %v", pdoc.ImportPath, err)
-			}
-
-			if old != nil {
-				if err := updateImportsIndex(c, ctx, old, pdoc); err != nil {
-					return err
-				}
-			}
-		} else {
-			if err := deleteIndex(ctx, id); err != nil {
+		if old != nil {
+			if err := updateImportsIndex(c, ctx, old, pdoc); err != nil {
 				return err
 			}
 		}
+	} else {
+		if err := deleteIndex(ctx, id); err != nil {
+			return err
+		}
 	}
 
 	if nextCrawl.IsZero() {
@@ -607,21 +604,19 @@
 	c := db.Pool.Get()
 	defer c.Close()
 
-	if GAESearch {
-		ctx := bgCtx()
-		id, err := redis.String(c.Do("HGET", "ids", path))
-		if err == redis.ErrNil {
-			return nil
-		}
-		if err != nil {
-			return err
-		}
-		if err := deleteIndex(ctx, id); err != nil {
-			return err
-		}
+	ctx := bgCtx()
+	id, err := redis.String(c.Do("HGET", "ids", path))
+	if err == redis.ErrNil {
+		return nil
+	}
+	if err != nil {
+		return err
+	}
+	if err := deleteIndex(ctx, id); err != nil {
+		return err
 	}
 
-	_, err := deleteScript.Do(c, path)
+	_, err = deleteScript.Do(c, path)
 	return err
 }
 
diff --git a/gddo-server/assets/templates/common.html b/gddo-server/assets/templates/common.html
index bcbf071..d472e00 100644
--- a/gddo-server/assets/templates/common.html
+++ b/gddo-server/assets/templates/common.html
@@ -51,11 +51,11 @@
       <tr><td>
         {{if .Path|isValidImportPath}}
         <a href="/{{.Path}}">{{.Path|importPath}}</a>
-          {{if gaeSearch}}<ul class="list-inline">
+          <ul class="list-inline">
             <li class="additional-info">{{.ImportCount}} imports</li>
             {{if .Fork}}<li class="additional-info">· fork</li>{{end}}
             {{if .Stars}}<li class="additional-info">· {{.Stars}} stars</li>{{end}}
-          </ul>{{end}}
+          </ul>
         {{else}}{{.Path|importPath}}</td>
         {{end}}
       <td class="synopsis">{{.Synopsis|importPath}}</td></tr>
diff --git a/gddo-server/main.go b/gddo-server/main.go
index e0f62e6..bffe2da 100644
--- a/gddo-server/main.go
+++ b/gddo-server/main.go
@@ -583,16 +583,8 @@
 		}
 	}
 
-	var (
-		pkgs []database.Package
-		err  error
-	)
-	if database.GAESearch {
-		ctx := appengine.NewContext(req)
-		pkgs, err = database.Search(ctx, q)
-	} else {
-		pkgs, err = db.Query(q)
-	}
+	ctx := appengine.NewContext(req)
+	pkgs, err := database.Search(ctx, q)
 	if err != nil {
 		return err
 	}
@@ -651,7 +643,8 @@
 
 	if pkgs == nil {
 		var err error
-		pkgs, err = db.Query(q)
+		ctx := appengine.NewContext(req)
+		pkgs, err = database.Search(ctx, q)
 		if err != nil {
 			return err
 		}
@@ -883,7 +876,6 @@
 	flag.StringVar(&database.RedisServer, "db-server", database.RedisServer, "URI of Redis server.")
 	flag.DurationVar(&database.RedisIdleTimeout, "db-idle-timeout", database.RedisIdleTimeout, "Close Redis connections after remaining idle for this duration.")
 	flag.BoolVar(&database.RedisLog, "db-log", database.RedisLog, "Log database commands")
-	flag.BoolVar(&database.GAESearch, "gae_search", database.GAESearch, "Use GAE Search API in the search function.")
 }
 
 func main() {
@@ -1038,10 +1030,6 @@
 		gceLogger = newGCELogger(logc)
 	}
 
-	if database.GAESearch {
-		http.Handle("/", root)
-		appengine.Main()
-	} else {
-		log.Fatal(http.ListenAndServe(*httpAddr, root))
-	}
+	http.Handle("/", root)
+	appengine.Main()
 }
diff --git a/gddo-server/template.go b/gddo-server/template.go
index d9032ac..99a4733 100644
--- a/gddo-server/template.go
+++ b/gddo-server/template.go
@@ -25,7 +25,6 @@
 	ttemp "text/template"
 	"time"
 
-	"github.com/golang/gddo/database"
 	"github.com/golang/gddo/doc"
 	"github.com/golang/gddo/gosrc"
 	"github.com/golang/gddo/httputil"
@@ -477,10 +476,6 @@
 	return gaAccount
 }
 
-func gaeSearchFn() bool {
-	return database.GAESearch
-}
-
 func noteTitleFn(s string) string {
 	return strings.Title(strings.ToLower(s))
 }
@@ -535,7 +530,6 @@
 			"comment":           commentFn,
 			"equal":             reflect.DeepEqual,
 			"gaAccount":         gaAccountFn,
-			"gaeSearch":         gaeSearchFn,
 			"host":              hostFn,
 			"htmlComment":       htmlCommentFn,
 			"importPath":        importPathFn,