michael@0: /** michael@0: * Used with testSearchSuggestions. michael@0: * Returns a set of pre-defined suggestions for given prefixes. michael@0: */ michael@0: michael@0: function handleRequest(request, response) { michael@0: let query = request.queryString.match(/^query=(.*)$/)[1]; michael@0: query = decodeURIComponent(query).replace(/\+/g, " "); michael@0: michael@0: let suggestMap = { michael@0: "f": ["facebook", "fandango", "frys", "forever 21", "fafsa"], michael@0: "fo": ["forever 21", "food network", "fox news", "foothill college", "fox"], michael@0: "foo": ["food network", "foothill college", "foot locker", "footloose", "foo fighters"], michael@0: "foo ": ["foo fighters", "foo bar", "foo bat", "foo bay"], michael@0: "foo b": ["foo bar", "foo bat", "foo bay"], michael@0: "foo ba": ["foo bar", "foo bat", "foo bay"], michael@0: "foo bar": ["foo bar"] michael@0: }; michael@0: michael@0: let suggestions = suggestMap[query]; michael@0: if (!suggestions) michael@0: suggestions = []; michael@0: suggestions = [query, suggestions]; michael@0: michael@0: /* michael@0: * Sample result: michael@0: * ["foo",["food network","foothill college","foot locker",...]] michael@0: */ michael@0: response.setHeader("Content-Type", "text/json", false); michael@0: response.setHeader("Cache-Control", "no-cache", false); michael@0: response.write(JSON.stringify(suggestions)); michael@0: }