snapkitty
developer-tools
c++
SNAPKITTYWEST commited on
Commit
4ba2c0a
·
verified ·
1 Parent(s): 2884964

Add src/hk_search_provider.erl

Browse files
Files changed (1) hide show
  1. src/hk_search_provider.erl +30 -0
src/hk_search_provider.erl ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ %%%-------------------------------------------------------------------
2
+ %%% @doc HK-SEARCH :: pluggable search provider behaviour.
3
+ %%%
4
+ %%% `hk_search_job' talks to *this* interface, never to a specific
5
+ %%% vendor's API. This is what "provider-agnostic and should not
6
+ %%% copy proprietary implementation details" means concretely: the
7
+ %%% harness only assumes a provider can plan sub-queries, execute a
8
+ %%% web search, fetch a URL's content, and extract text plus a
9
+ %%% citation map from it -- the generic shape shared by essentially
10
+ %%% every answer-oriented search API, not any one vendor's request
11
+ %%% format, ranking model, or response schema. A real deployment
12
+ %%% configures `{hyperkitty, search_provider, Module}' to point at
13
+ %%% an adapter for whatever API it actually holds credentials for;
14
+ %%% `hk_search_provider_mock' is the bundled reference/test
15
+ %%% implementation used when none is configured.
16
+ %%% @end
17
+ %%%-------------------------------------------------------------------
18
+ -module(hk_search_provider).
19
+
20
+ -callback plan(Query :: binary(), Opts :: map()) ->
21
+ {ok, [binary()]} | {error, term()}.
22
+
23
+ -callback search(SubQuery :: binary(), Opts :: map()) ->
24
+ {ok, [#{url := binary(), title := binary(), snippet := binary()}]} | {error, term()}.
25
+
26
+ -callback fetch(Url :: binary()) ->
27
+ {ok, #{content_type := binary(), body := binary()}} | {error, term()}.
28
+
29
+ -callback extract(Body :: binary(), ContentType :: binary()) ->
30
+ {ok, #{text := binary(), citation_map := map()}} | {error, term()}.