// 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
//
// 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
//
// 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
*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
if err != nil {
log.Fatalf("%s: %s\n", zipfile, err)
}
+ // rc is never closed (app running forever)
fs = NewZipFS(rc)
fsHttp = NewHttpZipFS(rc, *goroot)
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
// 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