summaryrefslogtreecommitdiff
path: root/config/services/web/searx/engines.nix
blob: 69cc861c7ef4066b2b211ebee380b0ba62407485 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{ lib, ... }:

with lib;
let
  overrideDisabled =
    value: names:
    map (name: {
      inherit name;
      disabled = value;
    }) names;
  enable = overrideDisabled false;
  disable = overrideDisabled true;

  makeSearchUrl =
    {
      baseUrl,
      queryKeyword ? "query",
      pageKeyword ? null,
      preventRedirect ? false,
      extraParameters ? { },
    }:
    baseUrl
    + "?${queryKeyword}={query}"
    # an invisible whitespace is added at the end of the query to prevent redirections
    + (optionalString preventRedirect "%E2%80%8E")
    + (optionalString (pageKeyword != null) "&${pageKeyword}={pageno}")
    + (concatStrings (
      mapAttrsToList (name: value: "&${name}=${builtins.toString value}") extraParameters
    ));

  wikipediaSearch = lang: {
    name = "wikipedia search ${lang}";
    engine = "xpath";
    search_url = makeSearchUrl {
      baseUrl = "https://${lang}.wikipedia.org/w/index.php";
      queryKeyword = "search";
      extraParameters = {
        fulltext = 1;
      };
    };
    results_xpath = ''//ul[@class="mw-search-results"]/li'';
    url_xpath = ''.//div[@class="mw-search-result-heading"]/a/@href'';
    title_xpath = ''.//div[@class="mw-search-result-heading"]/a/@title'';
    content_xpath = ''.//div[@class="searchresult"]'';
    shortcut = "w${lang}";
    categories = "general";
    disabled = true;
    about = {
      website = "https://${lang}.wikipedia.org/";
      wikidata_id = "Q52";
      official_api_documentation = "https://${lang}.wikipedia.org/api/";
      use_official_api = false;
      require_api_key = false;
      results = "HTML";
    };
  };
in
{
  services.searx.settings.engines =
    (disable [
      # general
      "bing"
      "brave"
      "currency"
      "dictzone"
      "google"
      # files
      "btdigg"
      # images
      "openverse"
      "bing images"
      "library of congress"
      "qwant images"
      # it
      "hoogle"
      # map
      "photon"
    ])
    ++ (enable [
      # general
      "duckduckgo"
      "startpage"
    ])
    ++ [
      {
        name = "nlab";
        engine = "xpath";
        search_url = makeSearchUrl { baseUrl = "https://ncatlab.org/nlab/search"; };
        results_xpath = "//li/a";
        url_xpath = "./@href";
        title_xpath = ".";
        content_xpath = ".";
        shortcut = "nlab";
        timeout = 10.0;
        categories = "science";
        disabled = true;
        about = {
          website = "https://ncatlab.org/";
          wikidata_id = "Q6954693";
          official_api_documentation = "";
          use_official_api = false;
          require_api_key = false;
          results = "HTML";
        };
      }
    ]
    ++ (map wikipediaSearch [
      "fr"
      "en"
    ]);
}