mirror of
https://github.com/golang/go
synced 2024-11-24 21:10:04 -07:00
godoc: enable qualified identifiers ("math.Sin") as query strings again
A query string of the form ident.ident will be used both as a qualified identifier for identifier search and as a regular expression. Qualified identifier lookup got broken accidentally when introducing regexp full text search. Cleaned up surrounding logic a bit. R=rsc CC=golang-dev https://golang.org/cl/3984042
This commit is contained in:
parent
c52ad23461
commit
4e3f389476
@ -1159,36 +1159,33 @@ type SearchResult struct {
|
|||||||
func lookup(query string) (result SearchResult) {
|
func lookup(query string) (result SearchResult) {
|
||||||
result.Query = query
|
result.Query = query
|
||||||
|
|
||||||
// determine identifier lookup string and full text regexp
|
|
||||||
lookupStr := ""
|
|
||||||
lookupRx, err := regexp.Compile(query)
|
|
||||||
if err != nil {
|
|
||||||
result.Alert = "Error in query regular expression: " + err.String()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if prefix, complete := lookupRx.LiteralPrefix(); complete {
|
|
||||||
// otherwise we lookup "" (with no result) because
|
|
||||||
// identifier lookup doesn't support regexp search
|
|
||||||
lookupStr = prefix
|
|
||||||
}
|
|
||||||
|
|
||||||
index, timestamp := searchIndex.get()
|
index, timestamp := searchIndex.get()
|
||||||
if index != nil {
|
if index != nil {
|
||||||
// identifier search
|
|
||||||
index := index.(*Index)
|
index := index.(*Index)
|
||||||
result.Hit, result.Alt, err = index.Lookup(lookupStr)
|
|
||||||
|
// identifier search
|
||||||
|
var err os.Error
|
||||||
|
result.Hit, result.Alt, err = index.Lookup(query)
|
||||||
if err != nil && !*fulltextIndex {
|
if err != nil && !*fulltextIndex {
|
||||||
// ignore the error if there is full text search
|
// ignore the error if full text search is enabled
|
||||||
// since it accepts that query 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()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// textual search
|
// full text search
|
||||||
// TODO(gri) should max be a flag?
|
if *fulltextIndex {
|
||||||
const max = 10000 // show at most this many fulltext results
|
rx, err := regexp.Compile(query)
|
||||||
result.Found, result.Textual = index.LookupRegexp(lookupRx, max+1)
|
if err != nil {
|
||||||
result.Complete = result.Found <= max
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// is the result accurate?
|
// is the result accurate?
|
||||||
|
Loading…
Reference in New Issue
Block a user