Skip to content

Comments

Pass filter arrays natively to addok API#9

Merged
jdesboeufs merged 1 commit intomainfrom
feat/native-array-filters
Nov 13, 2025
Merged

Pass filter arrays natively to addok API#9
jdesboeufs merged 1 commit intomainfrom
feat/native-array-filters

Conversation

@jdesboeufs
Copy link
Member

This PR updates the filter handling to pass array values directly to the addok Python API instead of concatenating them with + separators.

Changes

JavaScript side (lib/params.js):

  • Array filter values are now preserved as arrays instead of being joined with +
  • Merged formatFilterValue into validateFilters (no formatting needed anymore)
  • Empty arrays are filtered out from validated filters

Python side (lib/pyshell/bridge.py):

  • Removed prepare_filters function (unnecessary pass-through)
  • Filter values (strings or arrays) are passed directly via **filters to addok's search() and reverse() functions

Backward compatibility:

  • Single string values continue to work as before
  • Tests updated to reflect new behavior
  • All 50 tests passing

Documentation:

  • Updated README to clarify that arrays are passed natively
  • Added note about requiring addok version with new filter API support

Example

// Before: ['75001', '75002'] was converted to '75001+75002'
// Now: ['75001', '75002'] is passed as an array to addok
const params = {
  q: 'rue de la paix',
  filters: {
    type: 'street',
    postcode: ['75001', '75002', '75003']
  }
}

Note: This requires addok to support native array values in filter parameters.

- Remove filter value concatenation with '+' separator
- Pass array filter values directly to addok Python API
- Simplify bridge.py by removing prepare_filters function
- Merge formatFilterValue into validateFilters
- Filter out empty arrays from validated filters
- Update documentation to clarify new behavior
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors filter handling to pass array values natively to the addok Python API instead of joining them with + separators, enabling more efficient multi-value filtering with OR logic.

  • Removed formatFilterValue function that was joining arrays with +
  • Updated validateFilters to preserve array values as-is while filtering out empty arrays
  • Comprehensive test coverage for edge cases (empty arrays, single-item arrays, mixed string/array filters)

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
lib/params.js Removed formatFilterValue function; inlined validation logic in validateFilters to preserve arrays natively and skip empty arrays
test/params.js Removed formatFilterValue tests; updated test expectations to verify arrays are preserved; added edge case tests for empty arrays and single-item arrays
README.md Added note about requiring addok version with native array filter support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jdesboeufs jdesboeufs merged commit 87b2d8f into main Nov 13, 2025
8 of 9 checks passed
@jdesboeufs jdesboeufs deleted the feat/native-array-filters branch November 13, 2025 09:27
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