Commit 6c8fdbe8 authored by Robert Griesemer's avatar Robert Griesemer

godoc: line numbers for all remote search results

Instead of returning the index lookup result via
RPC which has to be corrected for the client,
simply render it on the server and return the
final output.

R=rsc, r
CC=golang-dev
https://golang.org/cl/669041
parent e8fb0b01
QUERY = {Query} QUERY
{Query}
{.section Accurate} {.section Accurate}
{.or} {.or}
......
...@@ -746,8 +746,9 @@ func infoLineFmt(w io.Writer, x interface{}, format string) { ...@@ -746,8 +746,9 @@ func infoLineFmt(w io.Writer, x interface{}, format string) {
line = index.(*Index).Snippet(line).Line line = index.(*Index).Snippet(line).Line
} else { } else {
// no line information available because // no line information available because
// we don't have an index // we don't have an index - this should
// TODO(gri) Fix this for remote search // never happen; be conservative and don't
// crash
line = 0 line = 0
} }
} }
...@@ -1392,10 +1393,15 @@ type Query struct { ...@@ -1392,10 +1393,15 @@ type Query struct {
} }
type Result struct {
Result []byte
}
type IndexServer struct{} type IndexServer struct{}
func (s *IndexServer) Lookup(query *Query, result *SearchResult) os.Error { func (s *IndexServer) Lookup(query *Query, result *Result) os.Error {
*result = lookup(query.Query) result.Result = applyTemplate(searchText, "searchText", lookup(query.Query))
return nil return nil
} }
...@@ -158,7 +158,7 @@ func loggingHandler(h http.Handler) http.Handler { ...@@ -158,7 +158,7 @@ func loggingHandler(h http.Handler) http.Handler {
} }
func remoteLookup(query string) (result *SearchResult, err os.Error) { func remoteLookup(query string) (result *Result, err os.Error) {
var client *rpc.Client var client *rpc.Client
if *serverAddr != "" { if *serverAddr != "" {
// try server only // try server only
...@@ -178,7 +178,7 @@ func remoteLookup(query string) (result *SearchResult, err os.Error) { ...@@ -178,7 +178,7 @@ func remoteLookup(query string) (result *SearchResult, err os.Error) {
} }
} }
result = new(SearchResult) result = new(Result)
err = client.Call("IndexServer.Lookup", &Query{query}, result) err = client.Call("IndexServer.Lookup", &Query{query}, result)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -281,9 +281,7 @@ func main() { ...@@ -281,9 +281,7 @@ func main() {
if err != nil { if err != nil {
log.Exitf("remoteLookup: %s", err) log.Exitf("remoteLookup: %s", err)
} }
if err := searchText.Execute(result, os.Stdout); err != nil { os.Stdout.Write(result.Result)
log.Exitf("searchText.Execute: %s", err)
}
} }
return return
} }
......
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