Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/video-db/videodb-python int…
Browse files Browse the repository at this point in the history
…o ar/add-image-support
  • Loading branch information
ankit-v2-3 committed Feb 22, 2024
2 parents 30da85a + 7588bc4 commit 63290e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions videodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from videodb._constants import (
VIDEO_DB_API,
MediaType,
SearchType,
SubtitleAlignment,
SubtitleBorderStyle,
SubtitleStyle,
Expand All @@ -32,6 +33,7 @@
"SearchError",
"play_stream",
"MediaType",
"SearchType",
"SubtitleAlignment",
"SubtitleBorderStyle",
"SubtitleStyle",
Expand Down
1 change: 1 addition & 0 deletions videodb/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MediaType:

class SearchType:
semantic = "semantic"
keyword = "keyword"


class IndexType:
Expand Down
34 changes: 31 additions & 3 deletions videodb/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def search_inside_video(
search_data = self._connection.post(
path=f"{ApiPath.video}/{video_id}/{ApiPath.search}",
data={
"type": SearchType.semantic,
"index_type": SearchType.semantic,
"query": query,
"score_threshold": score_threshold
or SemanticSearchDefaultValues.score_threshold,
Expand All @@ -137,7 +137,7 @@ def search_inside_collection(
search_data = self._connection.post(
path=f"{ApiPath.collection}/{collection_id}/{ApiPath.search}",
data={
"type": SearchType.semantic,
"index_type": SearchType.semantic,
"query": query,
"score_threshold": score_threshold
or SemanticSearchDefaultValues.score_threshold,
Expand All @@ -148,7 +148,35 @@ def search_inside_collection(
return SearchResult(self._connection, **search_data)


search_type = {SearchType.semantic: SemanticSearch}
class KeywordSearch(Search):
def __init__(self, _connection):
self._connection = _connection

def search_inside_video(
self,
video_id: str,
query: str,
result_threshold: Optional[int] = None,
score_threshold: Optional[int] = None,
dynamic_score_percentage: Optional[int] = None,
**kwargs,
):
search_data = self._connection.post(
path=f"{ApiPath.video}/{video_id}/{ApiPath.search}",
data={
"index_type": SearchType.keyword,
"query": query,
"score_threshold": score_threshold,
"result_threshold": result_threshold,
},
)
return SearchResult(self._connection, **search_data)

def search_inside_collection(**kwargs):
raise NotImplementedError("Keyword search will be implemented in the future")


search_type = {SearchType.semantic: SemanticSearch, SearchType.keyword: KeywordSearch}


class SearchFactory:
Expand Down

0 comments on commit 63290e4

Please sign in to comment.