cmd/golangorg: delete index support code

Now that search is turned off, all the index code can be deleted.

For golang/go#41102.

Change-Id: Idb82f2b80cadb5a2d209b5e5995d38c35ffaf8db
Reviewed-on: https://go-review.googlesource.com/c/website/+/293412
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/golangorg/Dockerfile.prod b/cmd/golangorg/Dockerfile.prod
index 763ad4e..6c22980 100644
--- a/cmd/golangorg/Dockerfile.prod
+++ b/cmd/golangorg/Dockerfile.prod
@@ -3,9 +3,6 @@
 
 FROM golang:1.12 AS build
 
-RUN apt-get update && apt-get install -y \
-      zip # required for generate-index.bash
-
 # Check out the desired version of Go, both to build the golangorg binary and serve
 # as the goroot for content serving.
 ARG GO_REF
@@ -23,7 +20,6 @@
 COPY . /website
 
 WORKDIR /website/cmd/golangorg
-RUN GOLANGORG_DOCSET=/goroot ./generate-index.bash
 
 RUN go build -o /golangorg -tags=golangorg golang.org/x/website/cmd/golangorg
 
@@ -56,7 +52,4 @@
 COPY --from=build /goroot /goroot
 ENV GOROOT /goroot
 
-COPY --from=build /website/cmd/golangorg/index.split.* /app/
-ENV GOLANGORG_INDEX_GLOB index.split.*
-
 CMD ["/app/golangorg"]
diff --git a/cmd/golangorg/appinit.go b/cmd/golangorg/appinit.go
index 7b9242f..9dc4076 100644
--- a/cmd/golangorg/appinit.go
+++ b/cmd/golangorg/appinit.go
@@ -11,14 +11,12 @@
 // See README.md for details.
 
 import (
-	"archive/zip"
 	"context"
 	"go/build"
 	"io"
 	"log"
 	"net/http"
 	"os"
-	"path"
 	"regexp"
 	"runtime"
 	"strings"
@@ -26,7 +24,6 @@
 	"golang.org/x/tools/godoc"
 	"golang.org/x/tools/godoc/vfs"
 	"golang.org/x/tools/godoc/vfs/gatefs"
-	"golang.org/x/tools/godoc/vfs/zipfs"
 	"golang.org/x/website"
 	"golang.org/x/website/internal/dl"
 	"golang.org/x/website/internal/proxy"
@@ -40,40 +37,14 @@
 func main() {
 	log.SetFlags(log.Lshortfile | log.LstdFlags)
 
-	var (
-		// .zip filename
-		zipFilename = os.Getenv("GOLANGORG_ZIP")
-
-		// goroot directory in .zip file
-		zipGoroot = os.Getenv("GOLANGORG_ZIP_PREFIX")
-
-		// glob pattern describing search index files
-		// (if empty, the index is built at run-time)
-		indexFilenames = os.Getenv("GOLANGORG_INDEX_GLOB")
-	)
-
 	playEnabled = true
 
 	log.Println("initializing golang.org server ...")
-	log.Printf(".zip file   = %s", zipFilename)
-	log.Printf(".zip GOROOT = %s", zipGoroot)
-	log.Printf("index files = %s", indexFilenames)
 
 	fsGate := make(chan bool, 20)
 
-	if zipFilename != "" {
-		goroot := path.Join("/", zipGoroot) // fsHttp paths are relative to '/'
-		// read .zip file and set up file systems
-		rc, err := zip.OpenReader(zipFilename)
-		if err != nil {
-			log.Fatalf("%s: %s\n", zipFilename, err)
-		}
-		// rc is never closed (app running forever)
-		fs.Bind("/", zipfs.New(rc, zipFilename), goroot, vfs.BindReplace)
-	} else {
-		rootfs := gatefs.New(vfs.OS(runtime.GOROOT()), fsGate)
-		fs.Bind("/", rootfs, "/", vfs.BindReplace)
-	}
+	rootfs := gatefs.New(vfs.OS(runtime.GOROOT()), fsGate)
+	fs.Bind("/", rootfs, "/", vfs.BindReplace)
 
 	// Try serving files in /doc from a local copy before trying the main
 	// go repository. This lets us update some documentation outside the
@@ -88,18 +59,11 @@
 	corpus := godoc.NewCorpus(fs)
 	corpus.Verbose = false
 	corpus.MaxResults = 10000 // matches flag default in main.go
-	corpus.IndexEnabled = true
-	corpus.IndexFiles = indexFilenames
+	corpus.IndexEnabled = false
 	if err := corpus.Init(); err != nil {
 		log.Fatal(err)
 	}
-	corpus.IndexDirectory = indexDirectoryDefault
 	corpus.InitVersionInfo()
-	if indexFilenames != "" {
-		corpus.RunIndexer()
-	} else {
-		go corpus.RunIndexer()
-	}
 
 	pres = godoc.NewPresentation(corpus)
 	pres.ShowPlayground = true
diff --git a/cmd/golangorg/doc.go b/cmd/golangorg/doc.go
index 3ece91f..4c8c2c5 100644
--- a/cmd/golangorg/doc.go
+++ b/cmd/golangorg/doc.go
@@ -21,30 +21,10 @@
 		verbose mode
 	-timestamps=true
 		show timestamps with directory listings
-	-index
-		enable identifier and full text search index
-		(no search box is shown if -index is not set)
-	-index_files=""
-		glob pattern specifying index files; if not empty,
-		the index is read from these files in sorted order
-	-index_throttle=0.75
-		index throttle value; a value of 0 means no time is allocated
-		to the indexer (the indexer will never finish), a value of 1.0
-		means that index creation is running at full throttle (other
-		goroutines may get no time while the index is built)
-	-index_interval=0
-		interval of indexing; a value of 0 sets it to 5 minutes, a
-		negative value indexes only once at startup
 	-play=false
 		enable playground
 	-links=true
 		link identifiers to their declarations
-	-write_index=false
-		write index to a file; the file name must be specified with
-		-index_files
-	-maxresults=10000
-		maximum number of full text search results shown
-		(no full text index is built if maxresults <= 0)
 	-notes="BUG"
 		regular expression matching note markers to show
 		(e.g., "BUG|TODO", ".*")
@@ -56,21 +36,11 @@
 		directory containing alternate template files; if set,
 		the directory may provide alternative template files
 		for the files in $GOROOT/lib/godoc
-	-zip=""
-		zip file providing the file system to serve; disabled if empty
 
 By default, godoc looks at the packages it finds via $GOROOT and $GOPATH (if set).
 This behavior can be altered by providing an alternative $GOROOT with the -goroot
 flag.
 
-When the -index flag is set, a search index is maintained.
-The index is created at startup.
-
-The index contains both identifier and full text search information (searchable
-via regular expressions). The maximum number of full text search results shown
-can be set with the -maxresults flag; if set to 0, no full text results are
-shown, and only an identifier index but no full text search index is created.
-
 By default, godoc uses the system's GOOS/GOARCH. You can provide the URL parameters
 "GOOS" and "GOARCH" to set the output on the web page for the target system.
 
@@ -85,18 +55,7 @@
 For instance, https://golang.org/pkg/math/big/?m=all shows the documentation
 for all (not just the exported) declarations of package big.
 
-By default, godoc serves files from the file system of the underlying OS.
-Instead, a .zip file may be provided via the -zip flag, which contains
-the file system to serve. The file paths stored in the .zip file must use
-slash ('/') as path separator; and they must be unrooted. $GOROOT (or -goroot)
-must be set to the .zip file directory path containing the Go root directory.
-For instance, for a .zip file created by the command:
-
-	zip -r go.zip $HOME/go
-
-one may run godoc as follows:
-
-	godoc -http=:6060 -zip=go.zip -goroot=$HOME/go
+Godoc serves files from the file system of the underlying OS.
 
 Godoc documentation is converted to HTML or to text using the go/doc package;
 see https://golang.org/pkg/go/doc/#ToHTML for the exact rules.
diff --git a/cmd/golangorg/generate-index.bash b/cmd/golangorg/generate-index.bash
deleted file mode 100755
index ee0857a..0000000
--- a/cmd/golangorg/generate-index.bash
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/usr/bin/env bash
-
-# Copyright 2011 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-# This script creates a .zip file representing the $GOROOT file system
-# and computes the corresponding search index files.
-#
-# These are used in production (see app.prod.yaml)
-
-set -e -u -x
-
-ZIPFILE=golangorg.zip
-INDEXFILE=golangorg.index
-SPLITFILES=index.split.
-
-error() {
-	echo "error: $1"
-	exit 2
-}
-
-install() {
-	go install
-}
-
-getArgs() {
-	if [ ! -v GOLANGORG_DOCSET ]; then
-		GOLANGORG_DOCSET="$(go env GOROOT)"
-		echo "GOLANGORG_DOCSET not set explicitly, using GOROOT instead"
-	fi
-
-	# safety checks
-	if [ ! -d "$GOLANGORG_DOCSET" ]; then
-		error "$GOLANGORG_DOCSET is not a directory"
-	fi
-
-	# reporting
-	echo "GOLANGORG_DOCSET = $GOLANGORG_DOCSET"
-}
-
-makeZipfile() {
-	echo "*** make $ZIPFILE"
-	rm -f $ZIPFILE goroot
-	ln -s "$GOLANGORG_DOCSET" goroot
-	zip -q -r $ZIPFILE goroot/* # glob to ignore dotfiles (like .git)
-	rm goroot
-}
-
-makeIndexfile() {
-	echo "*** make $INDEXFILE"
-	golangorg=$(go env GOPATH)/bin/golangorg
-	# Run golangorg with GOPATH set to an empty directory, otherwise third-party packages will be in the index.
-	GOPATH=$(mktemp -d) $golangorg -write_index -goroot goroot -index_files=$INDEXFILE -zip=$ZIPFILE
-}
-
-splitIndexfile() {
-	echo "*** split $INDEXFILE"
-	rm -f $SPLITFILES*
-	split -b 8m -a 8 $INDEXFILE $SPLITFILES
-}
-
-cd $(dirname $0)
-
-install
-getArgs "$@"
-makeZipfile
-makeIndexfile
-splitIndexfile
-rm $INDEXFILE
-
-echo "*** setup complete"
diff --git a/cmd/golangorg/godoc_test.go b/cmd/golangorg/godoc_test.go
index 8c0bf5f..6afe551 100644
--- a/cmd/golangorg/godoc_test.go
+++ b/cmd/golangorg/godoc_test.go
@@ -139,19 +139,11 @@
 
 // Basic integration test for godoc HTTP interface.
 func TestWeb(t *testing.T) {
-	testWeb(t, false)
+	testWeb(t)
 }
 
 // Basic integration test for godoc HTTP interface.
-func TestWebIndex(t *testing.T) {
-	if testing.Short() {
-		t.Skip("skipping test in -short mode")
-	}
-	testWeb(t, true)
-}
-
-// Basic integration test for godoc HTTP interface.
-func testWeb(t *testing.T, withIndex bool) {
+func testWeb(t *testing.T) {
 	if runtime.GOOS == "plan9" {
 		t.Skip("skipping on plan9; fails to start up quickly enough")
 	}
@@ -159,9 +151,6 @@
 	defer cleanup()
 	addr := serverAddress(t)
 	args := []string{fmt.Sprintf("-http=%s", addr)}
-	if withIndex {
-		args = append(args, "-index", "-index_interval=-1s")
-	}
 	cmd := exec.Command(bin, args...)
 	cmd.Stdout = os.Stderr
 	cmd.Stderr = os.Stderr
@@ -170,7 +159,7 @@
 	// Set GOPATH variable to non-existing path
 	// and GOPROXY=off to disable module fetches.
 	// We cannot just unset GOPATH variable because godoc would default it to ~/go.
-	// (We don't want the indexer looking at the local workspace during tests.)
+	// (We don't want the server looking at the local workspace during tests.)
 	cmd.Env = append(os.Environ(),
 		"GOPATH=does_not_exist",
 		"GOPROXY=off",
@@ -181,19 +170,14 @@
 	}
 	defer killAndWait(cmd)
 
-	if withIndex {
-		waitForSearchReady(t, addr)
-	} else {
-		waitForServerReady(t, addr)
-		waitUntilScanComplete(t, addr)
-	}
+	waitForServerReady(t, addr)
+	waitUntilScanComplete(t, addr)
 
 	tests := []struct {
 		path        string
 		contains    []string // substring
 		match       []string // regexp
 		notContains []string
-		needIndex   bool
 		releaseTag  string // optional release tag that must be in go/build.ReleaseTags
 	}{
 		{
@@ -235,16 +219,6 @@
 			},
 		},
 		{
-			path: "/search?q=ListenAndServe",
-			contains: []string{
-				"/src",
-			},
-			notContains: []string{
-				"/pkg/bootstrap",
-			},
-			needIndex: true,
-		},
-		{
 			path: "/pkg/strings/",
 			contains: []string{
 				`href="/src/strings/strings.go"`,
@@ -294,9 +268,6 @@
 		},
 	}
 	for _, test := range tests {
-		if test.needIndex && !withIndex {
-			continue
-		}
 		url := fmt.Sprintf("http://%s%s", addr, test.path)
 		resp, err := http.Get(url)
 		if err != nil {
diff --git a/cmd/golangorg/index.go b/cmd/golangorg/index.go
deleted file mode 100644
index f84b29a..0000000
--- a/cmd/golangorg/index.go
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-import "strings"
-
-func indexDirectoryDefault(dir string) bool {
-	return dir != "/pkg" && !strings.HasPrefix(dir, "/pkg/")
-}
diff --git a/cmd/golangorg/main.go b/cmd/golangorg/main.go
index 8722f6d..d6534fe 100644
--- a/cmd/golangorg/main.go
+++ b/cmd/golangorg/main.go
@@ -24,7 +24,6 @@
 package main
 
 import (
-	"archive/zip"
 	_ "expvar" // to serve /debug/vars
 	"flag"
 	"fmt"
@@ -40,20 +39,12 @@
 	"golang.org/x/tools/godoc"
 	"golang.org/x/tools/godoc/vfs"
 	"golang.org/x/tools/godoc/vfs/gatefs"
-	"golang.org/x/tools/godoc/vfs/zipfs"
 	"golang.org/x/website"
 )
 
 const defaultAddr = "localhost:6060" // default webserver address
 
 var (
-	// file system to serve
-	// (with e.g.: zip -r go.zip $GOROOT -i \*.go -i \*.html -i \*.css -i \*.js -i \*.txt -i \*.c -i \*.h -i \*.s -i \*.png -i \*.jpg -i \*.sh -i favicon.ico)
-	zipfile = flag.String("zip", "", "zip file providing the file system to serve; disabled if empty")
-
-	// file-based index
-	writeIndex = flag.Bool("write_index", false, "write index to a file; the file name must be specified with -index_files")
-
 	// network
 	httpAddr = flag.String("http", defaultAddr, "HTTP service address")
 
@@ -70,13 +61,6 @@
 	showPlayground = flag.Bool("play", false, "enable playground")
 	declLinks      = flag.Bool("links", true, "link identifiers to their declarations")
 
-	// search index
-	indexEnabled  = flag.Bool("index", false, "enable search index")
-	indexFiles    = flag.String("index_files", "", "glob pattern specifying index files; if not empty, the index is read from these files in sorted order")
-	indexInterval = flag.Duration("index_interval", 0, "interval of indexing; 0 for default (5m), negative to only index once at startup")
-	maxResults    = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
-	indexThrottle = flag.Float64("index_throttle", 0.75, "index throttle value; 0.0 = no time allocated, 1.0 = full throttle")
-
 	// source code notes
 	notesRx = flag.String("notes", "BUG", "regular expression matching note markers to show")
 )
@@ -140,8 +124,8 @@
 		fmt.Fprintln(os.Stderr, "Unexpected arguments.")
 		usage()
 	}
-	if *httpAddr == "" && !*writeIndex {
-		fmt.Fprintln(os.Stderr, "At least one of -http or -write_index must be set to a non-zero value.")
+	if *httpAddr == "" {
+		fmt.Fprintln(os.Stderr, "-http must be set")
 		usage()
 	}
 
@@ -151,19 +135,8 @@
 	fsGate := make(chan bool, 20)
 
 	// Determine file system to use.
-	if *zipfile == "" {
-		// use file system of underlying OS
-		rootfs := gatefs.New(vfs.OS(*goroot), fsGate)
-		fs.Bind("/", rootfs, "/", vfs.BindReplace)
-	} else {
-		// use file system specified via .zip file (path separator must be '/')
-		rc, err := zip.OpenReader(*zipfile)
-		if err != nil {
-			log.Fatalf("%s: %s\n", *zipfile, err)
-		}
-		defer rc.Close() // be nice (e.g., -writeIndex mode)
-		fs.Bind("/", zipfs.New(rc, *zipfile), *goroot, vfs.BindReplace)
-	}
+	rootfs := gatefs.New(vfs.OS(*goroot), fsGate)
+	fs.Bind("/", rootfs, "/", vfs.BindReplace)
 	// Try serving files in /doc from a local copy before trying the main
 	// go repository. This lets us update some documentation outside the
 	// Go release cycle. This includes root.html, which redirects to "/".
@@ -187,22 +160,8 @@
 
 	corpus := godoc.NewCorpus(fs)
 	corpus.Verbose = *verbose
-	corpus.MaxResults = *maxResults
-	corpus.IndexEnabled = *indexEnabled
-	if *maxResults == 0 {
-		corpus.IndexFullText = false
-	}
-	corpus.IndexFiles = *indexFiles
-	corpus.IndexDirectory = indexDirectoryDefault
-	corpus.IndexThrottle = *indexThrottle
-	corpus.IndexInterval = *indexInterval
-	if *writeIndex {
-		corpus.IndexThrottle = 1.0
-		corpus.IndexEnabled = true
-		initCorpus(corpus)
-	} else {
-		go initCorpus(corpus)
-	}
+
+	go initCorpus(corpus)
 
 	// Initialize the version info before readTemplates, which saves
 	// the map value in a method value.
@@ -219,55 +178,16 @@
 	readTemplates(pres)
 	registerHandlers(pres)
 
-	if *writeIndex {
-		// Write search index and exit.
-		if *indexFiles == "" {
-			log.Fatal("no index file specified")
-		}
-
-		log.Println("initialize file systems")
-		*verbose = true // want to see what happens
-
-		corpus.UpdateIndex()
-
-		log.Println("writing index file", *indexFiles)
-		f, err := os.Create(*indexFiles)
-		if err != nil {
-			log.Fatal(err)
-		}
-		index, _ := corpus.CurrentIndex()
-		_, err = index.WriteTo(f)
-		if err != nil {
-			log.Fatal(err)
-		}
-
-		log.Println("done")
-		return
-	}
-
 	var handler http.Handler = http.DefaultServeMux
 	if *verbose {
 		log.Printf("golang.org server:")
 		log.Printf("\tversion = %s", runtime.Version())
 		log.Printf("\taddress = %s", *httpAddr)
 		log.Printf("\tgoroot = %s", *goroot)
-		switch {
-		case !*indexEnabled:
-			log.Print("\tsearch index disabled")
-		case *maxResults > 0:
-			log.Printf("\tfull text index enabled (maxresults = %d)", *maxResults)
-		default:
-			log.Print("\tidentifier search index enabled")
-		}
 		fs.Fprint(os.Stderr)
 		handler = loggingHandler(handler)
 	}
 
-	// Initialize search index.
-	if *indexEnabled {
-		go corpus.RunIndexer()
-	}
-
 	// Start http server.
 	fmt.Fprintf(os.Stderr, "serving http://%s\n", *httpAddr)
 	if err := http.ListenAndServe(*httpAddr, handler); err != nil {