feat: implement Yandex /search method for on-demand edge expansion (Task 2)

- Add SearchRoutes method to yandex client for on-demand station pair searches
- Implement hub expansion via on-demand /search calls in lazy graph expansion
- Integrate cache key generation for search results (search:{from}:{to}:{date})
- Update expandFromStation and expandFromCityHub to use Yandex API
- Add NewGraphWithoutYandex constructor for testability
- Add tests for on-demand search integration and cache TTL policies
This commit is contained in:
2026-08-14 14:14:14 +03:00
parent 829e93fc8f
commit 181575e092
5 changed files with 337 additions and 84 deletions

View File

@@ -233,8 +233,9 @@ type Segment struct {
// Station represents a station in the API response.
type Station struct {
Code string `json:"code"`
Title string `json:"title"`
Code string `json:"code"`
Title string `json:"title"`
TransportType string `json:"transport_type"`
// Other fields can be added as needed
}
@@ -273,6 +274,17 @@ func buildURL(path string, query map[string]string) string {
return u
}
// SearchRoutes searches for routes between two stations on a given date.
// This is used for on-demand edge expansion in the lazy graph expansion strategy.
func (c *Client) SearchRoutes(ctx context.Context, from, to, date string) (*Response, error) {
query := map[string]string{
"from": from,
"to": to,
"date": date,
}
return c.Do(ctx, "GET", "/v3.0/search/", query)
}
// --- Token Bucket Rate Limitter ---
func newTokenBucket(capacity, perSeconds int) *tokenBucket {