Add search functionality (Issue #3)

Backend changes:
- Added search query parameter (q) to /api/posts endpoint
- Search filters posts by title, content, author, and source
- Case-insensitive search with substring matching

Frontend changes:
- Made search bar functional with Enter key and click support
- Added performSearch() function to trigger searches
- Added Clear Search button that appears during active search
- Search results update feed title to show query
- Integrated search with existing pagination and filtering
- Preserves anonymous/authenticated feed title when clearing search

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-11 19:47:04 -05:00
parent 5d6da930df
commit c7bd634ad6
2 changed files with 75 additions and 4 deletions

17
app.py
View File

@@ -348,6 +348,7 @@ def api_posts():
per_page = int(request.args.get('per_page', DEFAULT_PAGE_SIZE))
community = request.args.get('community', '')
platform = request.args.get('platform', '')
search_query = request.args.get('q', '').lower().strip()
# Use cached data for better performance
cached_posts, cached_comments = _load_posts_cache()
@@ -363,7 +364,21 @@ def api_posts():
# Apply platform filter
if platform and post_data.get('platform', '').lower() != platform.lower():
continue
# Apply search filter
if search_query:
# Search in title, content, author, and source
title = post_data.get('title', '').lower()
content = post_data.get('content', '').lower()
author = post_data.get('author', '').lower()
source = post_data.get('source', '').lower()
if not (search_query in title or
search_query in content or
search_query in author or
search_query in source):
continue
# Get comment count from cache
comment_count = len(cached_comments.get(post_uuid, []))