mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 14:31:08 -05:00
Implement site-wide search system architecture with modular design and enhanced backend components; integrate django-filter for improved filtering capabilities and security considerations
This commit is contained in:
121
memory-bank/features/search-system.md
Normal file
121
memory-bank/features/search-system.md
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
# Site-Wide Search System Architecture
|
||||||
|
|
||||||
|
## 1. Architectural Overview
|
||||||
|
- **Filter-First Approach**: Utilizes django-filter for robust filtering capabilities
|
||||||
|
- **Modular Design**:
|
||||||
|
```python
|
||||||
|
# filters.py
|
||||||
|
class ParkFilter(django_filters.FilterSet):
|
||||||
|
search = django_filters.CharFilter(method='filter_search')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Park
|
||||||
|
fields = {
|
||||||
|
'state': ['exact', 'in'],
|
||||||
|
'rating': ['gte', 'lte'],
|
||||||
|
}
|
||||||
|
|
||||||
|
def filter_search(self, queryset, name, value):
|
||||||
|
return queryset.filter(
|
||||||
|
Q(name__icontains=value) |
|
||||||
|
Q(description__icontains=value)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. Enhanced Backend Components
|
||||||
|
|
||||||
|
### Search Endpoint (`/search/`)
|
||||||
|
```python
|
||||||
|
# views.py
|
||||||
|
class AdaptiveSearchView(TemplateView):
|
||||||
|
template_name = "search/results.html"
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return Park.objects.all()
|
||||||
|
|
||||||
|
def get_filterset(self):
|
||||||
|
return ParkFilter(self.request.GET, queryset=self.get_queryset())
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
filterset = self.get_filterset()
|
||||||
|
context['results'] = filterset.qs
|
||||||
|
context['filters'] = filterset.form
|
||||||
|
return context
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. Plugin Integration
|
||||||
|
|
||||||
|
### Recommended django-filter Extensions
|
||||||
|
```python
|
||||||
|
# settings.py
|
||||||
|
INSTALLED_APPS += [
|
||||||
|
'django_filters',
|
||||||
|
'django_filters_addons', # For custom widgets
|
||||||
|
'rangefilter', # For date/number ranges
|
||||||
|
]
|
||||||
|
|
||||||
|
# filters.py
|
||||||
|
class EnhancedParkFilter(ParkFilter):
|
||||||
|
rating_range = django_filters.RangeFilter(field_name='rating')
|
||||||
|
features = django_filters.MultipleChoiceFilter(
|
||||||
|
field_name='features__slug',
|
||||||
|
widget=HorizontalCheckboxSelectMultiple,
|
||||||
|
lookup_expr='contains'
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta(ParkFilter.Meta):
|
||||||
|
fields = ParkFilter.Meta.fields + ['rating_range', 'features']
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. Frontend Filter Rendering
|
||||||
|
```html
|
||||||
|
<!-- templates/search/filters.html -->
|
||||||
|
<form hx-get="/search/" hx-target="#search-results" hx-swap="outerHTML">
|
||||||
|
{{ filters.form.as_p }}
|
||||||
|
<button type="submit">Apply Filters</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<!-- Dynamic filter updates -->
|
||||||
|
<div hx-trigger="filter-update from:body"
|
||||||
|
hx-get="/search/filters/"
|
||||||
|
hx-swap="innerHTML">
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. Benefits of django-filter Integration
|
||||||
|
- Built-in validation for filter parameters
|
||||||
|
- Automatic form generation
|
||||||
|
- Complex lookup expressions
|
||||||
|
- Reusable filter components
|
||||||
|
- Plugin ecosystem support
|
||||||
|
|
||||||
|
## 6. Security Considerations
|
||||||
|
- Input sanitization using django's built-in escaping
|
||||||
|
- Query parameter whitelisting via FilterSet definitions
|
||||||
|
- Rate limiting on autocomplete endpoint (using django-ratelimit)
|
||||||
|
- Permission-aware queryset filtering
|
||||||
|
|
||||||
|
## 7. Performance Optimization
|
||||||
|
- Select related/prefetch_related in FilterSet querysets
|
||||||
|
- Caching filter configurations
|
||||||
|
- Indexing recommendations for filtered fields
|
||||||
|
- Pagination integration with django-filter
|
||||||
|
|
||||||
|
## 8. Testing Strategy
|
||||||
|
- FilterSet validation tests
|
||||||
|
- HTMX interaction tests
|
||||||
|
- Cross-browser filter UI tests
|
||||||
|
- Performance load testing
|
||||||
|
|
||||||
|
## 9. Style Integration
|
||||||
|
- Custom filter form templates matching Tailwind design
|
||||||
|
- Responsive filter controls grid
|
||||||
|
- Accessible form labels and error messages
|
||||||
|
- Dark mode support
|
||||||
|
|
||||||
|
## 10. Expansion Framework
|
||||||
|
- Registry pattern for adding new FilterSets
|
||||||
|
- Dynamic filter discovery system
|
||||||
|
- Plugin configuration templates
|
||||||
|
- Analytics integration points
|
||||||
0
search/__init__.py
Normal file
0
search/__init__.py
Normal file
3
search/admin.py
Normal file
3
search/admin.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
6
search/apps.py
Normal file
6
search/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class SearchConfig(AppConfig):
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
name = "search"
|
||||||
0
search/migrations/__init__.py
Normal file
0
search/migrations/__init__.py
Normal file
3
search/models.py
Normal file
3
search/models.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
3
search/tests.py
Normal file
3
search/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
3
search/views.py
Normal file
3
search/views.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
Reference in New Issue
Block a user