summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-09-14 20:46:03 -0700
committerRobert Griesemer <gri@golang.org>2011-09-14 20:46:03 -0700
commitd6b06b7508f4d0ab28a3f581c5ab49c4ddf58dae (patch)
tree7e4919331ac430d4c3250df6acc0473e05cdc301
parent1fbd7e00b845d60c1b280eea463c84cddee1d870 (diff)
downloadgo-d6b06b7508f4d0ab28a3f581c5ab49c4ddf58dae.tar.gz
godoc: support for complete index serialization
- now fulltext index information is saved/restored - minor updates to appinit.go R=rsc CC=golang-dev http://codereview.appspot.com/5024043
-rw-r--r--src/cmd/godoc/appinit.go13
-rw-r--r--src/cmd/godoc/index.go26
-rw-r--r--src/cmd/godoc/main.go5
3 files changed, 28 insertions, 16 deletions
diff --git a/src/cmd/godoc/appinit.go b/src/cmd/godoc/appinit.go
index baba53fa6..8c93425f3 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: <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)
diff --git a/src/cmd/godoc/index.go b/src/cmd/godoc/index.go
index fa2dbf126..c70ca4b86 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 8585895f5..15d70c49b 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 == "" {