Commit d76c4a52 authored by Robert Griesemer's avatar Robert Griesemer

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
parent 957fd575
......@@ -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)
......
......@@ -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
......
......@@ -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 == "" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment