Skip to content

feat: Infix filtering support #2685#2813

Draft
mdhaduk wants to merge 1 commit intotypesense:v31from
mdhaduk:feat/2685-infix-filtering-support
Draft

feat: Infix filtering support #2685#2813
mdhaduk wants to merge 1 commit intotypesense:v31from
mdhaduk:feat/2685-infix-filtering-support

Conversation

@mdhaduk
Copy link

@mdhaduk mdhaduk commented Mar 4, 2026


feat: infix filtering support (field:value) #2685

Closes #2685


Typesense supports exact (field:value) and prefix (field:value*) filtering on string fields, but had no way to filter by substring , users couldn't express "give me all docs where this field contains this value."

This PR adds field:value syntax to filter_by, enabling infix/contains filtering on string and string array fields that have infix: true in their schema.

Changes:

  • Detection (filter_result_iterator.cpp): value is now detected as an infix pattern before the existing prefix (value*) check, avoiding misidentification.
  • Validation: Returns a 400 error if the field does not have infix: true... the infix index is only built when explicitly enabled.
  • Lookup: Reuses the existing Index::search_infix() function (already used for query-time infix search). For multi-token filter values (e.g. Chris P), results
    are intersected (AND). Multiple filter values in a list (e.g. [foo, bar]) are OR'd together.
  • Result assembly: Results are stored as a flat filter_result_t (sorted uint32_t[]) -> the same pattern used by numeric and geo filters. Mixed infix + exact/prefix in a single OR list is handled by flattening posting lists and OR'ing with infix results before returning.

Tesing (CollectionFilteringTest.InfixFilterOnTextFields)

  • Basic single-token infix on string[] field (ris matches "Chris Evans", "Chris Parnell", "Chris Pine")
  • Infix on string field
  • No matches case
  • OR of multiple infix values ([ris, art])
  • Error on field without infix: true (400 response)
  • Mixed infix + exact in OR ([ris, Martin])
  • Mixed infix + prefix in OR ([ris, Ma*])
  • Infix combined with AND on another field (cast: ris && points: >60)

@tharropoulos
Copy link
Contributor

CC: @kishorenc

@tharropoulos
Copy link
Contributor

Is this ready for review?

@mdhaduk
Copy link
Author

mdhaduk commented Mar 10, 2026

New contributor, so I just wanted a review of this draft before submitting as PR in case of any obvious pitfalls

Let me know if I should just submit as PR, I think repo does not run clean build on issue of draft PR

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.

[Feature Request] Infix filtering support

2 participants