Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
--name typesense \
-v /tmp/typesense-data:/data \
-v /tmp/typesense-analytics-data:/analytics-data \
typesense/typesense:30.0.alpha1 \
typesense/typesense:30.2 \
--api-key=xyz \
--data-dir=/data \
--enable-search-analytics=true \
Expand Down
56 changes: 51 additions & 5 deletions src/typesense/types/curation_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,36 @@ class CurationRuleTagsSchema(typing.TypedDict):
tags: typing.List[str]


class CurationRuleQuerySchema(typing.TypedDict):
class CurationRuleQueryBaseSchema(typing.TypedDict):
"""
Schema for a curation rule using query and match.
Schema for the base of a curation rule using query and match.
"""

query: str
match: typing.Literal["exact", "contains"]


class CurationRuleQueryCreateSchema(CurationRuleQueryBaseSchema):
"""
Schema for creating a curation rule using query and match.
"""

stem: typing.NotRequired[bool]
synonyms: typing.NotRequired[bool]


class CurationRuleQuerySchema(CurationRuleQueryBaseSchema):
"""
Schema for retrieving a curation rule using query and match.
"""

stem: typing.NotRequired[
bool
] # TODO: This is a bug in Typesense server upstream, so until 31.0 is
# released, this is staying as notrequired.
synonyms: typing.NotRequired[bool]


class CurationRuleFilterBySchema(typing.TypedDict):
"""
Schema for a curation rule using filter_by.
Expand Down Expand Up @@ -85,20 +106,45 @@ class CurationItemSchema(typing.TypedDict):
metadata: typing.NotRequired[typing.Dict[str, typing.Any]]


class CurationItemUpsertSchema(typing.TypedDict):
"""
Schema for creating or updating a single curation item.
"""

id: str
rule: typing.Union[
CurationRuleTagsSchema,
CurationRuleQueryCreateSchema,
CurationRuleFilterBySchema,
]
includes: typing.NotRequired[typing.List[CurationIncludeSchema]]
excludes: typing.NotRequired[typing.List[CurationExcludeSchema]]
filter_by: typing.NotRequired[str]
sort_by: typing.NotRequired[str]
replace_query: typing.NotRequired[str]
remove_matched_tokens: typing.NotRequired[bool]
filter_curated_hits: typing.NotRequired[bool]
stop_processing: typing.NotRequired[bool]
effective_from_ts: typing.NotRequired[int]
effective_to_ts: typing.NotRequired[int]
metadata: typing.NotRequired[typing.Dict[str, typing.Any]]


class CurationSetUpsertSchema(typing.TypedDict):
"""
Payload schema to create or replace a curation set.
"""

items: typing.List[CurationItemSchema]
items: typing.List[CurationItemUpsertSchema]


class CurationSetSchema(CurationSetUpsertSchema, total=False):
class CurationSetSchema(typing.TypedDict):
"""
Response schema for a curation set.
"""

name: typing.NotRequired[str]
items: typing.List[CurationItemSchema]
name: str


class CurationSetsListEntrySchema(typing.TypedDict):
Expand Down
13 changes: 12 additions & 1 deletion tests/curation_set_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Tests for the CurationSet class including items APIs."""


import pytest

from tests.utils.version import is_v30_or_above
Expand Down Expand Up @@ -62,6 +61,8 @@ def test_actual_retrieve(
"rule": {
"match": "contains",
"query": "shoe",
"stem": False,
"synonyms": False,
},
"stop_processing": True,
},
Expand Down Expand Up @@ -108,6 +109,8 @@ def test_actual_list_items(
"rule": {
"match": "contains",
"query": "shoe",
"stem": False,
"synonyms": False,
},
"stop_processing": True,
},
Expand Down Expand Up @@ -140,6 +143,8 @@ def test_actual_get_item(
"rule": {
"match": "contains",
"query": "shoe",
"stem": False,
"synonyms": False,
},
"stop_processing": True,
}
Expand Down Expand Up @@ -218,6 +223,8 @@ async def test_actual_retrieve_async(
"rule": {
"match": "contains",
"query": "shoe",
"stem": False,
"synonyms": False,
},
"stop_processing": True,
},
Expand Down Expand Up @@ -263,6 +270,8 @@ async def test_actual_list_items_async(
"rule": {
"match": "contains",
"query": "shoe",
"stem": False,
"synonyms": False,
},
"stop_processing": True,
},
Expand Down Expand Up @@ -295,6 +304,8 @@ async def test_actual_get_item_async(
"rule": {
"match": "contains",
"query": "shoe",
"stem": False,
"synonyms": False,
},
"stop_processing": True,
}
Expand Down
4 changes: 4 additions & 0 deletions tests/curation_sets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def test_actual_upsert(
"rule": {
"match": "contains",
"query": "shoe",
"stem": False,
"synonyms": False,
},
"stop_processing": True,
},
Expand Down Expand Up @@ -150,6 +152,8 @@ async def test_actual_upsert_async(
"rule": {
"match": "contains",
"query": "shoe",
"stem": False,
"synonyms": False,
},
"stop_processing": True,
},
Expand Down
Loading