Skip to content

Commit 62ac735

Browse files
committed
feat: add keyward search
1 parent 6646cd8 commit 62ac735

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

videodb/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from typing import Optional
77
from videodb._utils._video import play_stream
8-
from videodb._constants import VIDEO_DB_API, MediaType
8+
from videodb._constants import VIDEO_DB_API, MediaType, SearchType
99
from videodb.client import Connection
1010
from videodb.exceptions import (
1111
VideodbError,
@@ -26,6 +26,7 @@
2626
"SearchError",
2727
"play_stream",
2828
"MediaType",
29+
"SearchType",
2930
]
3031

3132

videodb/_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MediaType:
1111

1212
class SearchType:
1313
semantic = "semantic"
14+
keyword = "keyword"
1415

1516

1617
class IndexType:

videodb/search.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,35 @@ def search_inside_collection(
148148
return SearchResult(self._connection, **search_data)
149149

150150

151-
search_type = {SearchType.semantic: SemanticSearch}
151+
class KeywordSearch(Search):
152+
def __init__(self, _connection):
153+
self._connection = _connection
154+
155+
def search_inside_video(
156+
self,
157+
video_id: str,
158+
query: str,
159+
result_threshold: Optional[int] = None,
160+
score_threshold: Optional[int] = None,
161+
dynamic_score_percentage: Optional[int] = None,
162+
**kwargs,
163+
):
164+
search_data = self._connection.post(
165+
path=f"{ApiPath.video}/{video_id}/{ApiPath.search}",
166+
data={
167+
"type": SearchType.keyword,
168+
"query": query,
169+
"score_threshold": score_threshold,
170+
"result_threshold": result_threshold,
171+
},
172+
)
173+
return SearchResult(self._connection, **search_data)
174+
175+
def search_inside_collection(**kwargs):
176+
raise NotImplementedError("Keyword search will be implemented in the future")
177+
178+
179+
search_type = {SearchType.semantic: SemanticSearch, SearchType.keyword: KeywordSearch}
152180

153181

154182
class SearchFactory:

0 commit comments

Comments
 (0)