---
# Ride Search Feature Specification

## Overview
Extend the existing park search infrastructure to support searching rides. This follows the established:  
- Authentication-first  
- BaseAutocomplete pattern  
- HTMX + AlpineJS frontend  

Rides are related to parks via a ForeignKey. Search results must reference both ride and parent park.

## Technical Specification

### Models & Filters
- Model: `Ride` in [`rides/models.py`](rides/models.py:1) with fields `name`, `park` (ForeignKey → Park), `duration`, `thrill_rating`, etc.  
- Filter: `RideFilter` in [`search/filters.py`](search/filters.py:1) (create if missing) supporting `min_thrill`, `max_duration`, and `park__id`.

### Autocomplete
- Class [`RideAutocomplete`](search/mixins.py:1) extends [`BaseAutocomplete`](core/forms.py:1).  
- Query: `Ride.objects.filter(name__icontains=query)` limited to 10 results.

### Search Form
- Class [`RideSearchForm`](search/forms.py:1) uses autocomplete widget bound to [`RideAutocomplete`](search/mixins.py:1).  
- Fields: `query` (CharField), `park` (HiddenField or Select), `min_thrill`, `max_duration`.

### Views & Templates
- View [`RideSearchView`](rides/views.py:1) decorated with `@login_required`.  
- URL route `'search/rides/'` in [`search/urls.py`](search/urls.py:1).  
- Partial template [`search/templates/search/partials/_ride_search.html`](search/templates/search/partials/_ride_search.html:1) with HTMX attributes (`hx-get`, `hx-trigger="input changed delay:300ms"`).

## File & Component Structure
- memory-bank/features/search/rides.md  
- search/mixins.py – add [`RideAutocomplete`](search/mixins.py:1)  
- search/forms.py – add [`RideSearchForm`](search/forms.py:1)  
- search/urls.py – register ride endpoints (`autocomplete/`, `results/`)  
- rides/views.py – add [`RideSearchView`](rides/views.py:1)  
- search/templates/search/partials/_ride_search.html  
- rides/templates/rides/partials/ride_results.html  

## Integration Points
- Combined search component toggles between park and ride modes.  
- Ride result links to [`ParkDetailView`](parks/views.py:1) for context.  
- Shared styles and layout from [`search/templates/search/layouts/base.html`](search/templates/search/layouts/base.html:1).

## Database Query Optimization
- Add DB index on `Ride.name` and `Ride.park_id`.  
- Use `select_related('park')` in view/queryset.  
- Limit autocomplete to top 10 for responsiveness.

## Frontend Component Design
- HTMX: `<input>` with `hx-get="/search/rides/autocomplete/"`, update target container.  
- AlpineJS: manage local state for selection, clearing on blur.  
- Reuse CSS classes from park search for unified UX.

## Testing Strategy
- Unit tests for [`RideAutocomplete`](search/tests/test_autocomplete.py).  
- Form tests for [`RideSearchForm`](search/tests/test_forms.py).  
- View tests (`login_required`, filter logic) in [`rides/tests/test_search_view.py`].  
- HTMX integration: AJAX responses include expected HTML using pytest-django + django-htmx.  
- Performance: benchmark large resultset to ensure truncation and quick response.