From d76c4a52e7bf584b5a32807da7e76e621a800149 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 14 Sep 2011 20:46:03 -0700 Subject: [PATCH] godoc: support for complete index serialization - now fulltext index information is saved/restored - minor updates to appinit.go R=rsc CC=golang-dev https://golang.org/cl/5024043 --- src/cmd/godoc/appinit.go | 13 +++++++------ src/cmd/godoc/index.go | 26 +++++++++++++++++++++----- src/cmd/godoc/main.go | 5 ----- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/cmd/godoc/appinit.go b/src/cmd/godoc/appinit.go index baba53fa6f..8c93425f38 100644 --- a/src/cmd/godoc/appinit.go +++ b/src/cmd/godoc/appinit.go @@ -4,8 +4,9 @@ // To run godoc under app engine, substitute main.go with // this file (appinit.go), provide a .zip file containing -// the file system to serve, and adjust the configuration -// parameters in appconfig.go accordingly. +// the file system to serve, the index file (or files) +// containing the pre-computed search index and adjust +// the configuration parameters in appconfig.go accordingly. // // The current app engine SDK may be based on an older Go // release version. To correct for version skew, copy newer @@ -17,7 +18,7 @@ // // The directory structure should look as follows: // -// godoc // directory containing the app engine app +// godoc-app // directory containing the app engine app // alt // alternative packages directory to // // correct for version skew // strings // never version of the strings package @@ -32,9 +33,8 @@ // // To run app the engine emulator locally: // -// dev_appserver.py -a 0 godoc +// dev_appserver.py -a 0 godoc-app // -// godoc is the top-level "goroot" directory. // The godoc home page is served at: :8080 and localhost:8080. package main @@ -63,7 +63,7 @@ func init() { *goroot = path.Join("/", zipGoroot) // fsHttp paths are relative to '/' *indexEnabled = true *indexFiles = indexFilenames - *maxResults = 0 // save space for now + *maxResults = 100 // reduce latency by limiting the number of fulltext search results *indexThrottle = 0.3 // in case *indexFiles is empty (and thus the indexer is run) // read .zip file and set up file systems @@ -72,6 +72,7 @@ func init() { if err != nil { log.Fatalf("%s: %s\n", zipfile, err) } + // rc is never closed (app running forever) fs = NewZipFS(rc) fsHttp = NewHttpZipFS(rc, *goroot) diff --git a/src/cmd/godoc/index.go b/src/cmd/godoc/index.go index fa2dbf1261..c70ca4b86e 100644 --- a/src/cmd/godoc/index.go +++ b/src/cmd/godoc/index.go @@ -833,7 +833,8 @@ func NewIndex(dirnames <-chan string, fulltextIndex bool, throttle float64) *Ind return &Index{x.fset, suffixes, words, alts, x.snippets, x.stats} } -type FileIndex struct { +type fileIndex struct { + Sources []byte Words map[string]*LookupResult Alts map[string]*AltWords Snippets []*Snippet @@ -841,23 +842,38 @@ type FileIndex struct { // Write writes the index x to w. func (x *Index) Write(w io.Writer) os.Error { + var sources []byte if x.suffixes != nil { - panic("no support for writing full text index yet") + // fulltext index present + sources = x.suffixes.Bytes() } - fx := FileIndex{ + fx := fileIndex{ + sources, // indicates if fulltext index is present or not x.words, x.alts, x.snippets, } - return gob.NewEncoder(w).Encode(fx) + err := gob.NewEncoder(w).Encode(fx) + if err == nil && sources != nil { + err = x.fset.Write(w) + } + return err } // Read reads the index from r into x; x must not be nil. func (x *Index) Read(r io.Reader) os.Error { - var fx FileIndex + var fx fileIndex if err := gob.NewDecoder(r).Decode(&fx); err != nil { return err } + if fx.Sources != nil { + // fulltext index is present + x.fset = token.NewFileSet() + if err := x.fset.Read(r); err != nil { + return err + } + x.suffixes = suffixarray.New(fx.Sources) + } x.words = fx.Words x.alts = fx.Alts x.snippets = fx.Snippets diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go index 8585895f5e..15d70c49bd 100644 --- a/src/cmd/godoc/main.go +++ b/src/cmd/godoc/main.go @@ -257,11 +257,6 @@ func main() { readTemplates() initHandlers() - if (*indexEnabled || *writeIndex) && *indexFiles != "" && *maxResults > 0 { - log.Println("warning: no support for full-text index yet (setting -maxresults to 0)") - *maxResults = 0 - } - if *writeIndex { // Write search index and exit. if *indexFiles == "" { -- 2.48.1