Skip to content
Merged
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
5 changes: 3 additions & 2 deletions videodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing import Optional
from videodb._utils._video import play_stream
from videodb._constants import VIDEO_DB_API, MediaType
from videodb._constants import VIDEO_DB_API, MediaType, SearchType
from videodb.client import Connection
from videodb.exceptions import (
VideodbError,
Expand All @@ -16,7 +16,7 @@

logger: logging.Logger = logging.getLogger("videodb")

__version__ = "0.0.3"
__version__ = "0.0.4"
__author__ = "videodb"

__all__ = [
Expand All @@ -26,6 +26,7 @@
"SearchError",
"play_stream",
"MediaType",
"SearchType",
]


Expand Down
1 change: 1 addition & 0 deletions videodb/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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