Skip to content

Conversation

@GautamGunecha
Copy link

@GautamGunecha GautamGunecha commented Oct 11, 2025

Feat: Implement Full-Text Search with q Parameter

Problem

The q parameter for full-text search was documented and expected by users but was not actually implemented in the codebase. When users tried to search with queries like GET /posts?q=title, they received empty results instead of filtered data.

Root Cause

The current filtering logic in src/service.ts only handled:

  • Exact matches (item=value)
  • Comparison operators (item_gt, item_lt, etc.)
  • Special parameters (_embed, _sort, etc.)

The q parameter was treated as a regular field name, which didn't exist in the data, resulting in no matches.

Solution

Implemented comprehensive full-text search functionality:

Features Added

  • Case-insensitive search: q=sushi and q=Sushi both work
  • Substring matching: q=aliment finds "Alimentação"
  • Multi-field search: Searches across all string properties
  • Nested object support: Searches within nested objects and arrays
  • Backward compatible: Doesn't break existing functionality

Technical Implementation

  • Added special handling for q parameter in Service.find() method
  • Implemented #searchInItem() and #searchInObject() methods for recursive search
  • Search runs before other filters and is excluded from regular query processing
  • Added comprehensive test coverage (7 new test cases)

Code Changes

  • Modified: src/service.ts - Added search functionality
  • Modified: src/service.test.ts - Added test coverage
  • Lines changed: +85 insertions, 0 deletions

Testing

  • All existing tests pass (87/87)
  • Added 7 new test cases for search functionality
  • Verified with real-world data:
    # Before fix
    GET /transactions?q=Sushi → []
    
    # After fix  
    GET /transactions?q=Sushi → [{"id": 2, "description": "Sushi", ...}]

Usage Examples

# Search across all string fields
GET /posts?q=title
GET /users?q=john

# Case-insensitive and substring matching
GET /posts?q=json     # finds "JSON Server"
GET /posts?q=server  # finds "JSON Server"

🔗 Related Issues

This fixes the commonly reported issue where users expected the q parameter to work for full-text search but it returned empty results.

Checklist

  • Code follows existing style guidelines
  • Self-review completed
  • Tests added/updated and passing
  • Documentation updated (if applicable)
  • No breaking changes
  • Backward compatible

Impact

  • User Experience: Users can now search their data as expected
  • Performance: Minimal overhead, search runs before other filters
  • Compatibility: No breaking changes to existing functionality
  • Testing: Comprehensive test coverage ensures reliability

- Add support for q parameter to perform full-text search across all string properties
- Implement case-insensitive substring matching
- Support nested objects and arrays in search
- Add comprehensive test coverage for search functionality
- Maintain backward compatibility with existing filtering

Fixes the issue where q parameter was not working as expected.
Users can now search across all string fields with queries like:
- GET /posts?q=title
- GET /transactions?q=Sushi

Resolves search functionality that was documented but not implemented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant