From d91c7e276190e53b5f08c8e86f509c4c38634ba7 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 24 Feb 2023 01:32:51 -0600 Subject: [PATCH] Search for plugin content via the search API --- src/khoj/routers/api.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index 2666648b..5e748315 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -109,6 +109,20 @@ def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None, r: Opti count=results_count, ) + elif (t in SearchType or t == None) and state.model.plugin_search: + # query specified plugin type + with timer("Query took", logger): + hits, entries = text_search.query( + user_query, + # Get plugin search model for specified search type, or the first one if none specified + state.model.plugin_search.get(t.value) or next(iter(state.model.plugin_search.values())), + rank_results=r, + ) + + # collate and return results + with timer("Collating results took", logger): + results = text_search.collate_results(hits, entries, results_count) + # Cache results state.query_cache[query_cache_key] = results