1
0
mirror of https://github.com/golang/go synced 2024-11-22 03:44:39 -07:00

godoc: added -index flag to enable/disable search index

Fixes #1647.

R=adg, rsc1, r2, rsc, r
CC=golang-dev
https://golang.org/cl/4444083
This commit is contained in:
Robert Griesemer 2011-05-02 13:28:02 -07:00
parent f279a93929
commit c783e68ff5
4 changed files with 37 additions and 16 deletions

View File

@ -33,7 +33,9 @@
<a href="/pkg/">Packages</a> <span class="sep">|</span> <a href="/pkg/">Packages</a> <span class="sep">|</span>
<a href="/cmd/">Commands</a> <span class="sep">|</span> <a href="/cmd/">Commands</a> <span class="sep">|</span>
<a href="/doc/go_spec.html">Specification</a> <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" /> <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> </form>
</div> </div>
</div> </div>

View File

@ -47,6 +47,9 @@ The flags are:
width of tabs in units of spaces width of tabs in units of spaces
-timestamps=true -timestamps=true
show timestamps with directory listings 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 -maxresults=10000
maximum number of full text search results shown maximum number of full text search results shown
(no full text index is built if maxresults <= 0) (no full text index is built if maxresults <= 0)

View File

@ -64,9 +64,12 @@ var (
// layout control // layout control
tabwidth = flag.Int("tabwidth", 4, "tab width") tabwidth = flag.Int("tabwidth", 4, "tab width")
showTimestamps = flag.Bool("timestamps", true, "show timestamps with directory listings") 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") 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 // file system mapping
fsMap Mapping // user-defined mapping fsMap Mapping // user-defined mapping
fsTree RWValue // *Directory tree of packages, updated with each sync 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) { func servePage(w http.ResponseWriter, title, subtitle, query string, content []byte) {
d := struct { d := struct {
Title string Title string
Subtitle string Subtitle string
PkgRoots []string PkgRoots []string
Query string SearchBox bool
Version string Query string
Menu []byte Version string
Content []byte Menu []byte
Content []byte
}{ }{
title, title,
subtitle, subtitle,
fsMap.PrefixList(), fsMap.PrefixList(),
*indexEnabled,
query, query,
runtime.Version(), runtime.Version(),
nil, nil,
@ -1174,11 +1179,15 @@ func lookup(query string) (result SearchResult) {
} }
// is the result accurate? // is the result accurate?
if _, ts := fsModified.get(); timestamp < ts { if *indexEnabled {
// The index is older than the latest file system change if _, ts := fsModified.get(); timestamp < ts {
// under godoc's observation. Indexing may be in progress // The index is older than the latest file system change
// or start shortly (see indexer()). // under godoc's observation. Indexing may be in progress
result.Alert = "Indexing in progress: result may be inaccurate" // or start shortly (see indexer()).
result.Alert = "Indexing in progress: result may be inaccurate"
}
} else {
result.Alert = "Search index disabled: no results available"
} }
return return

View File

@ -246,8 +246,13 @@ func main() {
log.Printf("address = %s", *httpAddr) log.Printf("address = %s", *httpAddr)
log.Printf("goroot = %s", *goroot) log.Printf("goroot = %s", *goroot)
log.Printf("tabwidth = %d", *tabwidth) log.Printf("tabwidth = %d", *tabwidth)
if *maxResults > 0 { switch {
log.Printf("maxresults = %d (full text index enabled)", *maxResults) 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() { if !fsMap.IsEmpty() {
log.Print("user-defined mapping:") log.Print("user-defined mapping:")
@ -284,7 +289,9 @@ func main() {
} }
// Start indexing goroutine. // Start indexing goroutine.
go indexer() if *indexEnabled {
go indexer()
}
// Start http server. // Start http server.
if err := http.ListenAndServe(*httpAddr, handler); err != nil { if err := http.ListenAndServe(*httpAddr, handler); err != nil {