@csrf_exempt
-@queryparams('a', 'd', 'l', 'ln', 'm', 'p', 'q', 's', 'u')
+@queryparams('d', 'l', 'ln', 'm', 'p', 'q', 's', 'u')
@cache(minutes=30)
def search(request):
# Perform a general web search
else:
searchlists = False
suburl = request.GET.get('u', None)
- allsites = request.GET.get('a', None) == "1"
# Check that we actually have something to search for
if request.GET.get('q', '') == '':
# perform the query for general web search
try:
- curs.execute("SELECT * FROM site_search(%(query)s, %(firsthit)s, %(hitsperpage)s, %(allsites)s, %(suburl)s, %(internal)s)", {
+ curs.execute("SELECT * FROM site_search(%(query)s, %(firsthit)s, %(hitsperpage)s, %(suburl)s, %(internal)s)", {
'query': query,
'firsthit': firsthit - 1,
'hitsperpage': hitsperpage,
- 'allsites': allsites,
'suburl': suburl,
'internal': include_internal,
})
quoted_suburl = ''
except Exception as e:
quoted_suburl = ''
- querystr = "?q=%s&a=%s&u=%s" % (
+ querystr = "?q=%s&u=%s" % (
urllib.parse.quote_plus(query.encode('utf-8')),
- allsites and "1" or "0",
quoted_suburl,
)
return render(request, 'search/sitesearch.html', {
'suburl': suburl,
- 'allsites': allsites,
'hitcount': totalhits,
'firsthit': firsthit,
'lasthit': min(totalhits, firsthit + hitsperpage - 1),
ALTER FUNCTION archives_search(text, int, timestamptz, timestamptz, int, int, char) SET default_text_search_config = 'public.pg';
-CREATE OR REPLACE FUNCTION site_search(query text, startofs int, hitsperpage int, allsites bool, _suburl text, includeinternal boolean DEFAULT False)
+CREATE OR REPLACE FUNCTION site_search(query text, startofs int, hitsperpage int, _suburl text, includeinternal boolean DEFAULT False)
RETURNS TABLE (siteid int, baseurl text, suburl text, title text, headline text, rank float)
AS $$
DECLARE
hits := 0;
- IF allsites THEN
- SELECT INTO pagecount sum(sites.pagecount) FROM sites;
- OPEN curs FOR SELECT sites.id AS siteid, sites.baseurl, webpages.suburl, ts_rank_cd(fti,tsq) * relprio AS ts_rank_cd FROM webpages INNER JOIN sites ON webpages.site=sites.id WHERE fti @@ tsq AND (includeinternal OR NOT isinternal) ORDER BY ts_rank_cd(fti,tsq) * relprio DESC LIMIT 1000;
+ SELECT INTO pagecount sites.pagecount FROM sites WHERE id=1;
+ IF _suburl IS NULL THEN
+ OPEN curs FOR SELECT sites.id AS siteid, sites.baseurl, webpages.suburl, ts_rank_cd(fti,tsq) * relprio AS ts_rank_cd FROM webpages INNER JOIN sites ON webpages.site=sites.id WHERE fti @@ tsq AND site=1 AND (includeinternal OR NOT isinternal) ORDER BY ts_rank_cd(fti,tsq) * relprio DESC LIMIT 1000;
ELSE
- SELECT INTO pagecount sites.pagecount FROM sites WHERE id=1;
- IF _suburl IS NULL THEN
- OPEN curs FOR SELECT sites.id AS siteid, sites.baseurl, webpages.suburl, ts_rank_cd(fti,tsq) * relprio AS ts_rank_cd FROM webpages INNER JOIN sites ON webpages.site=sites.id WHERE fti @@ tsq AND site=1 AND (includeinternal OR NOT isinternal) ORDER BY ts_rank_cd(fti,tsq) * relprio DESC LIMIT 1000;
- ELSE
- OPEN curs FOR SELECT sites.id AS siteid, sites.baseurl, webpages.suburl, ts_rank_cd(fti,tsq) * relprio AS ts_rank_cd FROM webpages INNER JOIN sites ON webpages.site=sites.id WHERE fti @@ tsq AND site=1 AND webpages.suburl LIKE _suburl||'%' AND (includeinternal OR NOT isinternal) ORDER BY ts_rank_cd(fti,tsq) * relprio DESC LIMIT 1000;
- END IF;
+ OPEN curs FOR SELECT sites.id AS siteid, sites.baseurl, webpages.suburl, ts_rank_cd(fti,tsq) * relprio AS ts_rank_cd FROM webpages INNER JOIN sites ON webpages.site=sites.id WHERE fti @@ tsq AND site=1 AND webpages.suburl LIKE _suburl||'%' AND (includeinternal OR NOT isinternal) ORDER BY ts_rank_cd(fti,tsq) * relprio DESC LIMIT 1000;
END IF;
LOOP
FETCH curs INTO hit;
END;
$$
LANGUAGE 'plpgsql';
-ALTER FUNCTION site_search(text, int, int, bool, text, bool) SET default_text_search_config = 'public.pg';
+ALTER FUNCTION site_search(text, int, int, text, bool) SET default_text_search_config = 'public.pg';