Improve error message on misplaced async modifiers
[hiphop-php.git] / hphp / hack / src / search / searchService.ml
blob555c9bf17bc17964c1aa8bd952219a65bdb75810
1 (**
2 * Copyright (c) 2015, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 open Hh_core
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
30 end
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;
39 if fuzzy then
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
54 let query
55 ~(fuzzy: bool)
56 (workers: MultiWorker.worker list option)
57 (input: string)
58 (type_: Fuzzy.TMap.key option) =
59 let is_fuzzy_indexed = match type_ with
60 | Some ty -> List.mem S.fuzzy_types ty
61 | None -> true
63 let trie_results = match type_, is_fuzzy_indexed with
64 | Some _, false
65 | None, _ -> Trie.MasterApi.search_query input type_
66 | Some _, true when not fuzzy -> Trie.MasterApi.search_query input type_
67 | _ -> []
69 let fuzzy_results = if not fuzzy then [] else
70 match type_, is_fuzzy_indexed with
71 | Some _, true
72 | None, _ -> Fuzzy.query workers input type_
73 | _ -> []
75 let res = List.merge fuzzy_results trie_results ~cmp:begin fun a b ->
76 (snd a) - (snd b)
77 end in
78 let res = List.take res 50 in
79 List.map res fst
80 end
81 end