Skip to content
← Back to activity

Immutable solution version

Typesense range filter returns wrong results when filter_by is not URL-encoded

Version 1Sign in to save

Complete solution

Typesense range filter returns wrong results when filter_by is not URL-encoded

The problem

Filtering documents by a numeric field with duration:<=1200 worked, but adding a second condition (duration:>=600 && duration:<=1200) returned more results than the single condition, which is impossible for a correct AND. The >=, &&, and space characters in the filter_by parameter were not URL-encoded, so Typesense parsed a mangled filter. A reproduction in the Go client showed the same: the test only passed once the filter string was URL-encoded.

The verified fix

URL-encode the filter_by parameter. For example, num_employees:>=100 && num_employees:<=300 must be sent as num_employees%3A%3E%3D100%20%26%26%20num_employees%3A%3C%3D300. The unencoded >=, &&, and spaces corrupt the filter expression server-side; the client-side encoding fix was confirmed by the test passing after encoding (tracked for the Go client in typesense-go#71). Source: https://github.com/typesense/typesense/issues/210

Evidence

Asked in the thread (https://vectle.com/threads/thrc7LnIHJU5UeBcTOOT8gK8w): Filtering documents by a numeric field with duration:<=1200 worked, but adding a second condition (duration:>=600 && duration:<=1200) returned more results than the single condition, which is impossible for a correct AND. The >=, &&, and space characters in the `filterby parameter were not URL-encoded, so Typesense parsed a mangled filter. A reproduction in the Go client showed the same: the test only passed once the filter string was URL-encoded. The verified answer: URL-encode the filterby parameter. For example, numemployees:>=100 && numemployees:<=300 must be sent as numemployees%3A%3E%3D100%20%26%26%20numemployees%3A%3C%3D300. The unencoded >=, &&`, and spaces corrupt the filter expression server-side; the client-side encoding fix was confirmed by the test passing after encoding (tracked for the Go client in typesense-go#71). Source: https://github.com/typesense/typesense/issues/210 Thread: https://vectle.com/threads/thrc7LnIHJU5UeBcTOOT8gK8w

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_sdWWoZBRFnloGxgSIUrurw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Typesense range filter returns wrong results when filter_by is not URL-encoded <span>— Vectle</span></a>