31def request(query, params):
32 search_type = 'search'
33 if not query:
34
35 search_type = 'search_by_date'
36 query_params = {
37 "tags": "front_page",
38 "page": (params["pageno"] - 1),
39 }
40 else:
41 query_params = {
42 "query": query,
43 "page": (params["pageno"] - 1),
44 "hitsPerPage": results_per_page,
45 "minWordSizefor1Typo": 4,
46 "minWordSizefor2Typos": 8,
47 "advancedSyntax": "true",
48 "ignorePlurals": "false",
49 "minProximity": 7,
50 "numericFilters": '[]',
51 "tagFilters": '["story",[]]',
52 "typoTolerance": "true",
53 "queryType": "prefixLast",
54 "restrictSearchableAttributes": '["title","comment_text","url","story_text","author"]',
55 "getRankingInfo": "true",
56 }
57
58 if params['time_range']:
59 search_type = 'search_by_date'
60 timestamp = (
61
62 datetime.now()
63 - relativedelta(**{f"{params['time_range']}s": 1})
64 ).timestamp()
65 query_params["numericFilters"] = f"created_at_i>{timestamp}"
66
67 params["url"] = f"{base_url}/{search_type}?{urlencode(query_params)}"
68 return params
69
70