]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: added -index flag to enable/disable search index
authorRobert Griesemer <gri@golang.org>
Mon, 2 May 2011 20:28:02 +0000 (13:28 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 2 May 2011 20:28:02 +0000 (13:28 -0700)
Fixes #1647.

R=adg, rsc1, r2, rsc, r
CC=golang-dev
https://golang.org/cl/4444083

lib/godoc/godoc.html
src/cmd/godoc/doc.go
src/cmd/godoc/godoc.go
src/cmd/godoc/main.go

index 837f53c483e2e62334753b2c16ad77b212d8f81a..24fce22cdc7a520a2b5cbc6d3621f0eb5bbaa201 100644 (file)
@@ -33,7 +33,9 @@
         <a href="/pkg/">Packages</a> <span class="sep">|</span>
         <a href="/cmd/">Commands</a> <span class="sep">|</span>
         <a href="/doc/go_spec.html">Specification</a>
+       {.section SearchBox}
         <input id="search" type="search" name="q" value="{.section Query}{Query|html-esc}{.end}" class="{.section Query}{.or}inactive{.end}" placeholder="code search" results="0" />
+       {.end}
         </form>
       </div>
     </div>
index f0006e750ec42b255a1ef8576bc1e26d6f54990d..26d436d724ff9aa0f0092f8987b1deaa8cf7cdce 100644 (file)
@@ -47,6 +47,9 @@ The flags are:
                width of tabs in units of spaces
        -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)
        -maxresults=10000
                maximum number of full text search results shown
                (no full text index is built if maxresults <= 0)
index b8e9dbc92672fd8d83d301576c2fec901831fb43..f97c764f9794ad8c70fc51f5fd1196d75116c729 100644 (file)
@@ -64,9 +64,12 @@ var (
        // layout control
        tabwidth       = flag.Int("tabwidth", 4, "tab width")
        showTimestamps = flag.Bool("timestamps", true, "show timestamps with directory listings")
-       maxResults     = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
        templateDir    = flag.String("templates", "", "directory containing alternate template files")
 
+       // search index
+       indexEnabled = flag.Bool("index", false, "enable search index")
+       maxResults   = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
+
        // file system mapping
        fsMap      Mapping // user-defined mapping
        fsTree     RWValue // *Directory tree of packages, updated with each sync
@@ -687,17 +690,19 @@ func readTemplates() {
 
 func servePage(w http.ResponseWriter, title, subtitle, query string, content []byte) {
        d := struct {
-               Title    string
-               Subtitle string
-               PkgRoots []string
-               Query    string
-               Version  string
-               Menu     []byte
-               Content  []byte
+               Title     string
+               Subtitle  string
+               PkgRoots  []string
+               SearchBox bool
+               Query     string
+               Version   string
+               Menu      []byte
+               Content   []byte
        }{
                title,
                subtitle,
                fsMap.PrefixList(),
+               *indexEnabled,
                query,
                runtime.Version(),
                nil,
@@ -1174,11 +1179,15 @@ func lookup(query string) (result SearchResult) {
        }
 
        // is the result accurate?
-       if _, ts := fsModified.get(); timestamp < ts {
-               // The index is older than the latest file system change
-               // under godoc's observation. Indexing may be in progress
-               // or start shortly (see indexer()).
-               result.Alert = "Indexing in progress: result may be inaccurate"
+       if *indexEnabled {
+               if _, ts := fsModified.get(); timestamp < ts {
+                       // The index is older than the latest file system change
+                       // under godoc's observation. Indexing may be in progress
+                       // or start shortly (see indexer()).
+                       result.Alert = "Indexing in progress: result may be inaccurate"
+               }
+       } else {
+               result.Alert = "Search index disabled: no results available"
        }
 
        return
index e426626b3b8821741bdeb5da42fd6071a9568c07..2138267078ccb0a91e1289a79bdc9d199d21f1cb 100644 (file)
@@ -246,8 +246,13 @@ func main() {
                        log.Printf("address = %s", *httpAddr)
                        log.Printf("goroot = %s", *goroot)
                        log.Printf("tabwidth = %d", *tabwidth)
-                       if *maxResults > 0 {
-                               log.Printf("maxresults = %d (full text index enabled)", *maxResults)
+                       switch {
+                       case !*indexEnabled:
+                               log.Print("search index disabled")
+                       case *maxResults > 0:
+                               log.Printf("full text index enabled (maxresults = %d)", *maxResults)
+                       default:
+                               log.Print("identifier search index enabled")
                        }
                        if !fsMap.IsEmpty() {
                                log.Print("user-defined mapping:")
@@ -284,7 +289,9 @@ func main() {
                }
 
                // Start indexing goroutine.
-               go indexer()
+               if *indexEnabled {
+                       go indexer()
+               }
 
                // Start http server.
                if err := http.ListenAndServe(*httpAddr, handler); err != nil {