]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: enable fulltext index by default
authorRobert Griesemer <gri@golang.org>
Wed, 19 Jan 2011 22:33:05 +0000 (14:33 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 19 Jan 2011 22:33:05 +0000 (14:33 -0800)
- added flag -maxresults (default: 10000) to limit the max.
  number of full text results shown
- removed flag -fulltext; use -maxresults=0 to disable fulltext
  index
- better indication on result page if not all results are shown
  (... after line list)

R=rsc, gri1
CC=golang-dev
https://golang.org/cl/4049042

lib/godoc/search.html
src/cmd/godoc/doc.go
src/cmd/godoc/godoc.go
src/cmd/godoc/main.go

index 3d3dd19582b3d9eab8185fcc15671bebba3e74cc..58a933fef0ead4b039bea8be2e7c9d1413bdadc2 100644 (file)
                {.repeated section Lines}
                        <a href="/{Filename|url-src}?h={Query|urlquery-esc}#L{@|html-esc}">{@|html-esc}</a>
                {.end}
+               {.section Complete}
+               {.or}
+                       ...
+               {.end}
                </td>
                </tr>
        {.end}
index 02779384c5b92d0cc59dbd2fbf67fa5e77520a84..f0006e750ec42b255a1ef8576bc1e26d6f54990d 100644 (file)
@@ -47,8 +47,9 @@ The flags are:
                width of tabs in units of spaces
        -timestamps=true
                show timestamps with directory listings
-       -fulltext=false
-               build full text index for regular expression queries
+       -maxresults=10000
+               maximum number of full text search results shown
+               (no full text index is built if maxresults <= 0)
        -path=""
                additional package directories (colon-separated)
        -html
index c53e04eba955d10a207682b666599cc404eb3911..7cee541f988ba56777bd42a4b8fce60c287519b1 100644 (file)
@@ -64,7 +64,7 @@ var (
        // layout control
        tabwidth       = flag.Int("tabwidth", 4, "tab width")
        showTimestamps = flag.Bool("timestamps", true, "show timestamps with directory listings")
-       fulltextIndex  = flag.Bool("fulltext", false, "build full text index for regular expression queries")
+       maxResults     = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
 
        // file system mapping
        fsMap      Mapping // user-defined mapping
@@ -1166,7 +1166,7 @@ func lookup(query string) (result SearchResult) {
                // identifier search
                var err os.Error
                result.Hit, result.Alt, err = index.Lookup(query)
-               if err != nil && !*fulltextIndex {
+               if err != nil && *maxResults <= 0 {
                        // ignore the error if full text search is enabled
                        // since the query may be a valid regular expression
                        result.Alert = "Error in query string: " + err.String()
@@ -1174,17 +1174,21 @@ func lookup(query string) (result SearchResult) {
                }
 
                // full text search
-               if *fulltextIndex {
+               if *maxResults > 0 && query != "" {
                        rx, err := regexp.Compile(query)
                        if err != nil {
                                result.Alert = "Error in query regular expression: " + err.String()
                                return
                        }
-
-                       // TODO(gri) should max be a flag?
-                       const max = 10000 // show at most this many fulltext results
-                       result.Found, result.Textual = index.LookupRegexp(rx, max+1)
-                       result.Complete = result.Found <= max
+                       // If we get maxResults+1 results we know that there are more than
+                       // maxResults results and thus the result may be incomplete (to be
+                       // precise, we should remove one result from the result set, but
+                       // nobody is going to count the results on the result page).
+                       result.Found, result.Textual = index.LookupRegexp(rx, *maxResults+1)
+                       result.Complete = result.Found <= *maxResults
+                       if !result.Complete {
+                               result.Found-- // since we looked for maxResults+1
+                       }
                }
        }
 
@@ -1280,7 +1284,7 @@ func indexer() {
                                log.Printf("updating index...")
                        }
                        start := time.Nanoseconds()
-                       index := NewIndex(fsDirnames(), *fulltextIndex)
+                       index := NewIndex(fsDirnames(), *maxResults > 0)
                        stop := time.Nanoseconds()
                        searchIndex.set(index)
                        if *verbose {
index fe3d22fb930e90c7d690a20df3d6189c0eae4b30..20e2e82108ce7f65875e4aea6e0008a77f4db594 100644 (file)
@@ -242,8 +242,8 @@ func main() {
                        log.Printf("address = %s", *httpAddr)
                        log.Printf("goroot = %s", *goroot)
                        log.Printf("tabwidth = %d", *tabwidth)
-                       if *fulltextIndex {
-                               log.Print("full text index enabled")
+                       if *maxResults > 0 {
+                               log.Printf("maxresults = %d (full text index enabled)", *maxResults)
                        }
                        if !fsMap.IsEmpty() {
                                log.Print("user-defined mapping:")