mirror of
https://github.com/golang/go
synced 2024-11-21 23:24:41 -07:00
godoc: enable fulltext index by default
- 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
This commit is contained in:
parent
4e3f389476
commit
a441037f3f
@ -79,6 +79,10 @@
|
|||||||
{.repeated section Lines}
|
{.repeated section Lines}
|
||||||
<a href="/{Filename|url-src}?h={Query|urlquery-esc}#L{@|html-esc}">{@|html-esc}</a>
|
<a href="/{Filename|url-src}?h={Query|urlquery-esc}#L{@|html-esc}">{@|html-esc}</a>
|
||||||
{.end}
|
{.end}
|
||||||
|
{.section Complete}
|
||||||
|
{.or}
|
||||||
|
...
|
||||||
|
{.end}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{.end}
|
{.end}
|
||||||
|
@ -47,8 +47,9 @@ The flags are:
|
|||||||
width of tabs in units of spaces
|
width of tabs in units of spaces
|
||||||
-timestamps=true
|
-timestamps=true
|
||||||
show timestamps with directory listings
|
show timestamps with directory listings
|
||||||
-fulltext=false
|
-maxresults=10000
|
||||||
build full text index for regular expression queries
|
maximum number of full text search results shown
|
||||||
|
(no full text index is built if maxresults <= 0)
|
||||||
-path=""
|
-path=""
|
||||||
additional package directories (colon-separated)
|
additional package directories (colon-separated)
|
||||||
-html
|
-html
|
||||||
|
@ -64,7 +64,7 @@ var (
|
|||||||
// layout control
|
// layout control
|
||||||
tabwidth = flag.Int("tabwidth", 4, "tab width")
|
tabwidth = flag.Int("tabwidth", 4, "tab width")
|
||||||
showTimestamps = flag.Bool("timestamps", true, "show timestamps with directory listings")
|
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
|
// file system mapping
|
||||||
fsMap Mapping // user-defined mapping
|
fsMap Mapping // user-defined mapping
|
||||||
@ -1166,7 +1166,7 @@ func lookup(query string) (result SearchResult) {
|
|||||||
// identifier search
|
// identifier search
|
||||||
var err os.Error
|
var err os.Error
|
||||||
result.Hit, result.Alt, err = index.Lookup(query)
|
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
|
// ignore the error if full text search is enabled
|
||||||
// since the query may be a valid regular expression
|
// since the query may be a valid regular expression
|
||||||
result.Alert = "Error in query string: " + err.String()
|
result.Alert = "Error in query string: " + err.String()
|
||||||
@ -1174,17 +1174,21 @@ func lookup(query string) (result SearchResult) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// full text search
|
// full text search
|
||||||
if *fulltextIndex {
|
if *maxResults > 0 && query != "" {
|
||||||
rx, err := regexp.Compile(query)
|
rx, err := regexp.Compile(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Alert = "Error in query regular expression: " + err.String()
|
result.Alert = "Error in query regular expression: " + err.String()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// If we get maxResults+1 results we know that there are more than
|
||||||
// TODO(gri) should max be a flag?
|
// maxResults results and thus the result may be incomplete (to be
|
||||||
const max = 10000 // show at most this many fulltext results
|
// precise, we should remove one result from the result set, but
|
||||||
result.Found, result.Textual = index.LookupRegexp(rx, max+1)
|
// nobody is going to count the results on the result page).
|
||||||
result.Complete = result.Found <= max
|
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...")
|
log.Printf("updating index...")
|
||||||
}
|
}
|
||||||
start := time.Nanoseconds()
|
start := time.Nanoseconds()
|
||||||
index := NewIndex(fsDirnames(), *fulltextIndex)
|
index := NewIndex(fsDirnames(), *maxResults > 0)
|
||||||
stop := time.Nanoseconds()
|
stop := time.Nanoseconds()
|
||||||
searchIndex.set(index)
|
searchIndex.set(index)
|
||||||
if *verbose {
|
if *verbose {
|
||||||
|
@ -242,8 +242,8 @@ func main() {
|
|||||||
log.Printf("address = %s", *httpAddr)
|
log.Printf("address = %s", *httpAddr)
|
||||||
log.Printf("goroot = %s", *goroot)
|
log.Printf("goroot = %s", *goroot)
|
||||||
log.Printf("tabwidth = %d", *tabwidth)
|
log.Printf("tabwidth = %d", *tabwidth)
|
||||||
if *fulltextIndex {
|
if *maxResults > 0 {
|
||||||
log.Print("full text index enabled")
|
log.Printf("maxresults = %d (full text index enabled)", *maxResults)
|
||||||
}
|
}
|
||||||
if !fsMap.IsEmpty() {
|
if !fsMap.IsEmpty() {
|
||||||
log.Print("user-defined mapping:")
|
log.Print("user-defined mapping:")
|
||||||
|
Loading…
Reference in New Issue
Block a user