From 212b1a96c8dfef47af5d2727d0604cf406efc232 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 28 Jun 2023 11:34:26 -0700 Subject: [PATCH] Create "all" search type for search across all content types on khoj server Allows moving logic to handle search across all content types to server from clients --- src/khoj/routers/api.py | 15 ++++++++------- src/khoj/utils/config.py | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index 4e305704..266eaed0 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -65,6 +65,7 @@ def get_config_types(): and getattr(state.model, f"{search_type.value}_search") is not None ) or ("plugins" in configured_content_types and search_type.name in configured_content_types["plugins"]) + or search_type == SearchType.All ] @@ -135,7 +136,7 @@ async def set_processor_conversation_config_data(updated_config: ConversationPro async def search( q: str, n: Optional[int] = 5, - t: Optional[SearchType] = None, + t: Optional[SearchType] = SearchType.All, r: Optional[bool] = False, score_threshold: Optional[Union[float, None]] = None, dedupe: Optional[bool] = True, @@ -166,7 +167,7 @@ async def search( defiltered_query = filter.defilter(user_query) encoded_asymmetric_query = None - if t == None or (t != SearchType.Ledger and t != SearchType.Image): + if t == SearchType.All or (t != SearchType.Ledger and t != SearchType.Image): with timer("Encoding query took", logger=logger): encoded_asymmetric_query = util.normalize_embeddings( state.model.org_search.bi_encoder.encode( @@ -177,7 +178,7 @@ async def search( ) with concurrent.futures.ThreadPoolExecutor() as executor: - if (t == SearchType.Org or t == None) and state.model.org_search: + if (t == SearchType.Org or t == SearchType.All) and state.model.org_search: # query org-mode notes search_futures += [ executor.submit( @@ -191,7 +192,7 @@ async def search( ) ] - if (t == SearchType.Markdown or t == None) and state.model.markdown_search: + if (t == SearchType.Markdown or t == SearchType.All) and state.model.markdown_search: # query markdown notes search_futures += [ executor.submit( @@ -205,7 +206,7 @@ async def search( ) ] - if (t == SearchType.Pdf or t == None) and state.model.pdf_search: + if (t == SearchType.Pdf or t == SearchType.All) and state.model.pdf_search: # query pdf files search_futures += [ executor.submit( @@ -232,7 +233,7 @@ async def search( ) ] - if (t == SearchType.Music or t == None) and state.model.music_search: + if (t == SearchType.Music or t == SearchType.All) and state.model.music_search: # query music library search_futures += [ executor.submit( @@ -258,7 +259,7 @@ async def search( ) ] - if (t is None or t in SearchType) and state.model.plugin_search: + if (t == SearchType.All or t in SearchType) and state.model.plugin_search: # query specified plugin type search_futures += [ executor.submit( diff --git a/src/khoj/utils/config.py b/src/khoj/utils/config.py index a83f7814..e3bea7b9 100644 --- a/src/khoj/utils/config.py +++ b/src/khoj/utils/config.py @@ -17,6 +17,7 @@ if TYPE_CHECKING: class SearchType(str, Enum): + All = "all" Org = "org" Ledger = "ledger" Music = "music"