Skip to content

Commit f65a51b

Browse files
committed
Remove index_empty for geo and numerics tags and update tests
1 parent 31ed67e commit f65a51b

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

redisvl/schema/fields.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,9 @@ def as_redis_field(self) -> RedisField:
490490
field = RedisNumericField(name, **kwargs)
491491

492492
# Normalize suffix ordering to satisfy RediSearch parser expectations.
493-
# Canonical order: [INDEXEMPTY] [INDEXMISSING] [SORTABLE [UNF]] [NOINDEX]
494-
canonical_order = ["INDEXEMPTY", "INDEXMISSING", "SORTABLE", "UNF", "NOINDEX"]
493+
# Canonical order: [INDEXMISSING] [SORTABLE [UNF]] [NOINDEX]
494+
# Note: INDEXEMPTY is not supported for NUMERIC fields
495+
canonical_order = ["INDEXMISSING", "SORTABLE", "UNF", "NOINDEX"]
495496
want_unf = self.attrs.unf and self.attrs.sortable # type: ignore
496497
_normalize_field_modifiers(field, canonical_order, want_unf)
497498

@@ -526,8 +527,9 @@ def as_redis_field(self) -> RedisField:
526527
field = RedisGeoField(name, **kwargs)
527528

528529
# Normalize suffix ordering to satisfy RediSearch parser expectations.
529-
# Canonical order: [INDEXEMPTY] [INDEXMISSING] [SORTABLE] [NOINDEX]
530-
canonical_order = ["INDEXEMPTY", "INDEXMISSING", "SORTABLE", "NOINDEX"]
530+
# Canonical order: [INDEXMISSING] [SORTABLE] [NOINDEX]
531+
# Note: INDEXEMPTY is not supported for GEO fields
532+
canonical_order = ["INDEXMISSING", "SORTABLE", "NOINDEX"]
531533
_normalize_field_modifiers(field, canonical_order)
532534

533535
return field

tests/integration/test_field_modifier_ordering_integration.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,83 @@ def test_indexmissing_enables_ismissing_query(self, client, redis_url, worker_id
365365
f"ismiss_{worker_id}:3",
366366
)
367367
index.delete(drop=True)
368+
369+
370+
class TestFieldTypeModifierSupport:
371+
"""Test that field types only support their documented modifiers."""
372+
373+
def test_numeric_field_does_not_support_index_empty(
374+
self, client, redis_url, worker_id
375+
):
376+
"""Verify that NumericField does not have index_empty attribute.
377+
378+
INDEXEMPTY is only supported for TEXT and TAG fields according to
379+
RediSearch documentation. NumericFieldAttributes should not have
380+
an index_empty attribute.
381+
"""
382+
import inspect
383+
384+
from redisvl.schema.fields import NumericFieldAttributes
385+
386+
# Verify NumericFieldAttributes doesn't have index_empty
387+
attrs = inspect.signature(NumericFieldAttributes).parameters
388+
assert (
389+
"index_empty" not in attrs
390+
), "NumericFieldAttributes should not have index_empty parameter"
391+
392+
# Verify the attribute doesn't exist on the class
393+
field_attrs = NumericFieldAttributes()
394+
assert not hasattr(
395+
field_attrs, "index_empty"
396+
), "NumericFieldAttributes should not have index_empty attribute"
397+
398+
def test_geo_field_does_not_support_index_empty(self, client, redis_url, worker_id):
399+
"""Verify that GeoField does not have index_empty attribute.
400+
401+
INDEXEMPTY is only supported for TEXT and TAG fields according to
402+
RediSearch documentation. GeoFieldAttributes should not have
403+
an index_empty attribute.
404+
"""
405+
import inspect
406+
407+
from redisvl.schema.fields import GeoFieldAttributes
408+
409+
# Verify GeoFieldAttributes doesn't have index_empty
410+
attrs = inspect.signature(GeoFieldAttributes).parameters
411+
assert (
412+
"index_empty" not in attrs
413+
), "GeoFieldAttributes should not have index_empty parameter"
414+
415+
# Verify the attribute doesn't exist on the class
416+
field_attrs = GeoFieldAttributes()
417+
assert not hasattr(
418+
field_attrs, "index_empty"
419+
), "GeoFieldAttributes should not have index_empty attribute"
420+
421+
def test_text_field_supports_index_empty(self, client, redis_url, worker_id):
422+
"""Verify that TextField supports index_empty attribute.
423+
424+
INDEXEMPTY is supported for TEXT fields according to RediSearch documentation.
425+
"""
426+
from redisvl.schema.fields import TextFieldAttributes
427+
428+
# Verify TextFieldAttributes has index_empty
429+
field_attrs = TextFieldAttributes(index_empty=True)
430+
assert hasattr(
431+
field_attrs, "index_empty"
432+
), "TextFieldAttributes should have index_empty attribute"
433+
assert field_attrs.index_empty is True
434+
435+
def test_tag_field_supports_index_empty(self, client, redis_url, worker_id):
436+
"""Verify that TagField supports index_empty attribute.
437+
438+
INDEXEMPTY is supported for TAG fields according to RediSearch documentation.
439+
"""
440+
from redisvl.schema.fields import TagFieldAttributes
441+
442+
# Verify TagFieldAttributes has index_empty
443+
field_attrs = TagFieldAttributes(index_empty=True)
444+
assert hasattr(
445+
field_attrs, "index_empty"
446+
), "TagFieldAttributes should have index_empty attribute"
447+
assert field_attrs.index_empty is True

0 commit comments

Comments
 (0)