in internal/search/grpc.go [44:114]
func (searcher *Searcher) DoSearch(ctx context.Context, r *SearchRequest, c *Conn) ZoektResponse {
conn, err := searcher.getGrpcConn(c.Endpoint)
if err != nil {
return ZoektResponse{
Error: fmt.Errorf("failed to create gRPC connection: %w", err),
Endpoint: c.Endpoint,
}
}
client := zproto.NewWebserverServiceClient(conn)
ctx = withForwardedHeaders(ctx, r)
endpointInfo, parseErr := parseEndpoint(c.Endpoint)
if parseErr != nil {
return ZoektResponse{
Error: fmt.Errorf("failed to parse endpoint: %w", parseErr),
Endpoint: c.Endpoint,
}
}
if endpointInfo.Path != "" {
ctx = metadata.AppendToOutgoingContext(ctx, "x-forwarded-path", endpointInfo.Path)
}
textQuery, err := zquery.Parse(r.Query)
if err != nil {
return ZoektResponse{Error: fmt.Errorf("query parse failed: %w", err)}
}
var children []*zproto.Q
children = append(children, zquery.QToProto(textQuery))
bitmap := roaring.NewBitmap()
for _, id := range c.RepoIds {
bitmap.Add(id)
}
var buf bytes.Buffer
if _, writeErr := bitmap.WriteTo(&buf); writeErr != nil {
return ZoektResponse{
Error: fmt.Errorf("failed to serialize repo IDs: %w", writeErr),
Endpoint: c.Endpoint,
}
}
children = append(children, &zproto.Q{
Query: &zproto.Q_RepoIds{
RepoIds: &zproto.RepoIds{
Repos: buf.Bytes(),
},
},
})
finalQuery := &zproto.Q{
Query: &zproto.Q_And{
And: &zproto.And{Children: children},
},
}
searchReq := &zproto.SearchRequest{
Query: finalQuery,
Opts: &zproto.SearchOptions{
NumContextLines: int64(r.Options.NumContextLines),
TotalMaxMatchCount: int64(r.Options.TotalMaxMatchCount),
},
}
stream, err := client.StreamSearch(ctx, &zproto.StreamSearchRequest{Request: searchReq})
if err != nil {
return ZoektResponse{Error: err}
}
return handleGrpcSearchStream(ctx, stream, c.Endpoint)
}