]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: support for complete index serialization
authorRobert Griesemer <gri@golang.org>
Thu, 15 Sep 2011 03:46:03 +0000 (20:46 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 15 Sep 2011 03:46:03 +0000 (20:46 -0700)
- 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
src/cmd/godoc/index.go
src/cmd/godoc/main.go

index baba53fa6f15b1dd8d267da9d6b19afe782303e6..8c93425f387879bca6ff469c213dcd4759875e17 100644 (file)
@@ -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: <hostname>: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)
 
index fa2dbf12611fe6df02876c66780149baab5a7b9f..c70ca4b86e49091ebb72dce94947147e273a57b7 100644 (file)
@@ -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
index 8585895f5e4b0f28ea6cead3ece5a24648ebb390..15d70c49bd837c617610408a26f23ccf0d2514ba 100644 (file)
@@ -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 == "" {