|
1 /** |
|
2 * Used with testSearchSuggestions. |
|
3 * Returns a set of pre-defined suggestions for given prefixes. |
|
4 */ |
|
5 |
|
6 function handleRequest(request, response) { |
|
7 let query = request.queryString.match(/^query=(.*)$/)[1]; |
|
8 query = decodeURIComponent(query).replace(/\+/g, " "); |
|
9 |
|
10 let suggestMap = { |
|
11 "f": ["facebook", "fandango", "frys", "forever 21", "fafsa"], |
|
12 "fo": ["forever 21", "food network", "fox news", "foothill college", "fox"], |
|
13 "foo": ["food network", "foothill college", "foot locker", "footloose", "foo fighters"], |
|
14 "foo ": ["foo fighters", "foo bar", "foo bat", "foo bay"], |
|
15 "foo b": ["foo bar", "foo bat", "foo bay"], |
|
16 "foo ba": ["foo bar", "foo bat", "foo bay"], |
|
17 "foo bar": ["foo bar"] |
|
18 }; |
|
19 |
|
20 let suggestions = suggestMap[query]; |
|
21 if (!suggestions) |
|
22 suggestions = []; |
|
23 suggestions = [query, suggestions]; |
|
24 |
|
25 /* |
|
26 * Sample result: |
|
27 * ["foo",["food network","foothill college","foot locker",...]] |
|
28 */ |
|
29 response.setHeader("Content-Type", "text/json", false); |
|
30 response.setHeader("Cache-Control", "no-cache", false); |
|
31 response.write(JSON.stringify(suggestions)); |
|
32 } |