#community-help

Issue with Optional Filtering and Id Field

TLDR Stefan encounters a bug with optional filtering on the id field, where _eval sort criteria doesn't show expected results. Kishore Nallan confirms it might be a bug. An issue is created on GitHub.

Powered by Struct AI
Mar 13, 2023 (7 months ago)
Stefan
Photo of md5-d6c265b4792dbf0a1d6ae378f39d8736
Stefan
01:51 PM
Hi there,
I am having an issue with the new optional filtering, I would expect that if I put the "_eval" sort criteria first that documents that match this expressions are shown first no matter the other sort criteria, but that doesn't seem to be the case:
---------- Search parameters
{'q': '*', 'query_by': 'name', 'sort_by': '_eval(id:1):asc,pop:desc'}
---------- Query output
{'facet_counts': [],
 'found': 2,
 'hits': [{'document': {'id': '0', 'name': 'a', 'pop': 1},
           'highlight': {},
           'highlights': []},
          {'document': {'id': '1', 'name': 'b', 'pop': 0},
           'highlight': {},
           'highlights': []}],
 'out_of': 2,
 'page': 1,
 'request_params': {'collection_name': 'test_collection',
                    'per_page': 10,
                    'q': '*'},
 'search_cutoff': False,
 'search_time_ms': 0}

So in the case above I'd expect name: 'b' to be the first document, because it matches the _eval() condition, and 'a' the second, but that doesn't seem to be the case.

Am I misunderstanding the feature? Changing _eval(xxx):asc to desc doesn't change the output.

I made a little reproduction repo so you can see the exact configuration: https://github.com/reinoldus/typesense-reproduction-repo
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:53 PM
Is this a problem only for id field? Or are other fields affected as well?
Stefan
Photo of md5-d6c265b4792dbf0a1d6ae378f39d8736
Stefan
01:56 PM
let me check
01:58
Stefan
01:58 PM
Seems to be only related to the id field:
---------- Search parameters
{'q': '*',
 'query_by': 'name',
 'sort_by': '_eval(other_field:test):desc,pop:desc'}
---------- Query output
{'facet_counts': [],
 'found': 2,
 'hits': [{'document': {'id': '1',
                        'name': 'b',
                        'other_field': 'test',
                        'pop': 0},
           'highlight': {},
           'highlights': []},
          {'document': {'id': '0',
                        'name': 'a',
                        'other_field': 'not_test',
                        'pop': 1},
           'highlight': {},
           'highlights': []}],
 'out_of': 2,
 'page': 1,
 'request_params': {'collection_name': 'test_collection',
                    'per_page': 10,
                    'q': '*'},
 'search_cutoff': False,
 'search_time_ms': 0}

Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:59 PM
Yup so there's probably a bug there specific to id
Stefan
Photo of md5-d6c265b4792dbf0a1d6ae378f39d8736
Stefan
02:06 PM
Shall I create an issue?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:19 PM
Yes please