2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
12 module Make
(S
: SearchUtils.Searchable
) = struct
13 module Fuzzy
= FuzzySearchService.Make
(S
)
14 module Trie
= TrieSearchService.Make
(S
)
15 module AutocompleteTrie
= TrieSearchService.Make
(S
)
17 module WorkerApi
= struct
19 let update fn trie_defs fuzzy_defs autocomplete_defs
=
20 Trie.WorkerApi.update fn trie_defs
;
21 AutocompleteTrie.WorkerApi.update fn autocomplete_defs
;
22 Fuzzy.update fn fuzzy_defs
24 let process_trie_term = Trie.WorkerApi.process_term_for_search
26 let process_autocomplete_term = Trie.WorkerApi.process_term
28 let process_fuzzy_term = Fuzzy.process_term
32 module MasterApi
= struct
34 (* Called by the master process when there is new information in
35 * shared memory for us to index *)
36 let update_search_index ~fuzzy files
=
37 Trie.MasterApi.index_files files
;
38 AutocompleteTrie.MasterApi.index_files files
;
40 Fuzzy.index_files files
;
41 (* At this point, users can start searching again so we should clear the
42 * cache that contains the actual results. We don't have to worry
43 * about the string->keys list shared memory because it's uncached *)
44 SharedMem.invalidate_caches
()
46 let clear_shared_memory fns
=
47 Trie.SearchUpdates.remove_batch fns
;
48 Trie.SearchKeys.remove_batch fns
;
49 AutocompleteTrie.SearchUpdates.remove_batch fns
;
50 AutocompleteTrie.SearchKeys.remove_batch fns
;
51 Fuzzy.SearchKeyToTermMap.remove_batch fns
;
52 Fuzzy.SearchKeys.remove_batch fns
56 (workers
: MultiWorker.worker list
option)
58 (type_
: Fuzzy.TMap.key
option) =
59 let is_fuzzy_indexed = match type_
with
60 | Some ty
-> List.mem
S.fuzzy_types ty
63 let trie_results = match type_
, is_fuzzy_indexed with
65 | None
, _
-> Trie.MasterApi.search_query input type_
66 | Some _
, true when not fuzzy
-> Trie.MasterApi.search_query input type_
69 let fuzzy_results = if not fuzzy
then [] else
70 match type_
, is_fuzzy_indexed with
72 | None
, _
-> Fuzzy.query workers input type_
75 let res = List.merge
fuzzy_results trie_results ~cmp
:begin fun a b
->
78 let res = List.take
res 50 in