Skip to content

Latest commit

 

History

History
422 lines (402 loc) · 19.6 KB

README.org

File metadata and controls

422 lines (402 loc) · 19.6 KB

Search Engines for Nyxt

The aim of nx-search-engines is to get rid of black box world of search bookmarklets and search cookies by moving to the pretty land of lispy syntax and small helper functions generating search URIs.

As an example, instead of fiddling with websites for search bookmarklets, you can define the DuckDuckGo search engine with Terminal theme, instant answers turned off, and autocomplete suggestions turned off with just a simple call to:

(engines:duckduckgo :theme :terminal
                    :instant-answers nil
                    :autocomplete nil)

This will return your new fancy DuckDuckGo engine that you can append to the search-engines in buffer configuration.

(define-configuration buffer
  ((search-engines (append %slot-default%
                           (list (engines:duckduckgo
                                  :theme :terminal
                                  :instant-answers nil
                                  :autocomplete nil))))))

Geting Started

First, you need to clone this repository to where Nyxt can find it:

# The ~/.local/share/nyxt/extensions/ is the default path Nyxt looks
# for extensions in. Change to wherever you set your extension path.
git clone https://github.com/aartaka/nx-search-engines ~/.local/share/nyxt/extensions/nx-search-engines

The smallest possible configuration involving nx-search-engines is:

;; Load search-engines.lisp after loading nx-search-engines.
(load-after-system :nx-search-engines (nyxt-init-file "search-engines.lisp"))

in your init file, and

(in-package #:nyxt-user)

;; Define buffer search-engines slot to be a list of several
;; nx-search-engines-provided ones.
(define-configuration (buffer web-buffer)
  ((search-engines (list (engines:google :shortcut "gmaps"
                                         :object :maps)
                         (engines:wordnet :shortcut "wn"
                                          :show-word-frequencies t)
                         (engines:google :shortcut "g"
                                         :safe-search nil)
                         (engines:duckduckgo :theme :terminal
                                             :help-improve-duckduckgo nil
                                             :homepage-privacy-tips nil
                                             :privacy-newsletter nil
                                             :newsletter-reminders nil
                                             :install-reminders nil
                                             :install-duckduckgo nil)))))

in search-engines.lisp (you need to create this file in the same directory where your init.lisp is). This will give you four search engines: WordNet, Google (maps and basic search) and DuckDuckGo. The last engine in the list is the default one, so your next search will end up in a cozy terminal-themed DuckDuckGo :)

Engines

Helpers have lots of key arguments, but you don’t need to use all of these. Helpers rely on search engine default behavior, so you can omit settings equal to defaults.

A syntax resembling CLHS/man pages is used in search engines description. Basically:

  • square brackets mean an optional element,
  • curly brackets mean a mandatory element with several bar-separated options,
  • vertical bars mean that any of the bar-separated elements is fine,
  • asterisks mean any number of the element it is set after,
  • if there is a type name instead of actual value, then any value of that type is acceptable,
  • additional pseudo-types are explained after the syntax definition,
  • semicolons start comments.

DuckDuckGo

Syntax for the DuckDuckGo-generating function is:

  (duckduckgo [:shortcut string]
              [:fallback-url quri:uri]
              [:base-search-url string]
              ;; DuckDuckGo uses two (four?) object-related keywords.
              ;; To ensure the right search object, use both :object and :object2.
              [:object {:all | :images | :videos | :news}]
              [:object2 {:all | :images | :videos | :news}]
              [:theme {:default | :basic | :contrast | :dark | :gray | :terminal}]
              [:get-requests boolean]
              [:video-playback {:prompt-me | :always-ddg | :always-third-party}]
              [:redirect boolean]
              ;; Some of these are abbreviations added for convenience.
              ;; You can suggest yours if it's widespread in your country!
              [:region {:argentina | :australia | :austria | :belgium-fr | :belgium-nl |
                        :brazil | :bulgaria | :canada-en | :canada-fr | :catalonia | :chile |
                        :china | :colombia | :croatia | :czech-republic | :denmark | :estonia |
                        :finland | :france | :germany | :greece | :hong-kong | :hungary |
                        :india-en | :india | :indonesia-en | :indonesia | :ireland |
                        :israel-en | :israel | :italy | :japan | :korea | :latvia |
                        :lithuania | :malaysia-en | :malaysia | :mexico | :netherlands |
                        :new-zealand | :norway | :pakistan-en | :peru | :philippines-en |
                        :philippines | :poland | :portugal | :romania | :russia |
                        :russian-federation | :saudi-arabia | :singapore | :slovakia |
                        :slovenia | :south-africa | :spain-ca | :spain-es | :spain |
                        :sweden | :switzerland-de | :switzerland-fr | :taiwan | :thailand-en |
                        :thailand | :turkey | :us-english | :us-en | :us | :us-spanish |
                        :us-es | :ukraine | :united-kingdom | :uk | :vietnam-en | :vietnam}]
              ;; Not yet written properly, too much Unicode
              [:language string]
              [:safe-search {:moderate | :strict | :off}]
              [:instant-answers boolean]
              [:infinite-scroll-for-media boolean]
              [:infinite-scroll boolean]
              [:autocomplete-suggestions boolean]
              [:open-in-new-tab boolean]
              [:advertisements boolean]
              [:keyboard-shortcuts boolean]
              [:units-of-measure {:no-preference | :metric | :us-based}]
              [:map-rendering {:not-set | :best-available | :image-tiles}]
              [:page-break-numbers {:on | :off | :lines}]
              [:install-duckduckgo boolean]
              [:install-reminders boolean]
              [:privacy-newsletter boolean]
              [:newsletter-reminders boolean]
              [:homepage-privacy-tips boolean]
              [:help-improve-duckduckgo boolean]
              [:font font-name]
              [:font-size {:large | :small | :medium | :larger | :largest}]
              [:page-width {:normal | :wide | :super-wide}]
              [:center-alignment boolean]
              [:background-color color-code-string]
              [:header-behavior {:on-dynamic | :on-fixed | :off | :on-scrolling}]
              [:header-color color-code-string]
              [:result-title-font font-name]
              [:result-title-color color-code-string]
              [:result-visited-title-color color-code-string]
              [:result-title-underline boolean]
              [:result-description-color color-code-string]
              [:result-url-color color-code-string]
              [:result-module-color color-code-string]
              [:result-full-urls boolean]
              [:result-urls-above-snipper boolean]
              [:result-visible-checkmark boolean]
              [:site-icons boolean])

color-code-string := string of six hex numbers, e.g., "FF00A4"
;; Actually, you can use the font name, like "Proxima Nova".
font-name := {:proxima-nova | :arial | :century-gothic | :georgia | :helvetica | :helvetica-neue |
              :sans-serif | :segoe-ui | :serif | :times | :tahoma | :trebuchet-ms | :verdana}

Quite a long definition, eh?

Things left to do for DuckDuckGo:

  • Bind language settings.
  • Allow booleans where they fit (:header-behavior, :safe-search).

DuckDuckGo Images (duckduckgo-images)

A derived Image-search engine has the same syntax as the main one, except that it defaults to images.

HTML-only DuckDuckGo (duckduckgo-html-only)

This one can come in handy if you’re into noscript-mode. Everything’s the same as usual DDG, but it requires no JS to run and has much less configuration (barely any). Search completion is inherited from usual DDG, so you can have both dynamically loaded suggestions and HTML-only search :D

DuckDuckGo completion helper

make-duckduckgo-completion returns a search-ready completion function (it’s already included if you use duckduckgo). Syntax is:

(make-duckduckgo-completion [:request-args list])

Google

Syntax for Google helper is:

(google [:shortcut string]
        [:fallback-url quri:uri]
        [:base-search-url string]
        [:safe-search boolean]
        [:object {:all | :image | :video | :news | :shopping | :books | :finance}])

Things left to do for Google:

  • Bind object-specific sorting settings.
  • Add keyword alias for :safe-mode (i.e., :strict as alias to t)

Google Images (google-images)

Same as Google, but :object defaults to :images.

Google completion helper

make-google-completion returns a search-ready completion function (it’s already included if you use google). Syntax is:

(make-google-completion [:request-args list])

Bing

Bing is special – it hosts separate types of searches on separate paths, so we need to make several engines with different search-urls:

Plain Bing

Syntax is:

(bing [:shortcut string]
      [:fallback-url quri:uri]
      [:base-search-url string]
      [:my-language-only boolean]
      [:my-country-only boolean]
      [:date {:all | :past-24-hours | :past-week | :past-month | :past-year |
              (bing-date local-time:timestamp local-time:timestamp)}])

Notice the use of bind-date helper – it allows you to specify the date for the search. Lower bound is January 1st, 1970, upper bound is… uncertain.

Things to do:

  • :past-day alias for :past-24-hours value of :date.

Bing Images

Syntax is:

(bing-images [:shortcut string]
             [:fallback-url quri:uri]
             [:base-search-url string])

Bing Videos

Syntax is:

(bing-videos [:shortcut string]
             [:fallback-url quri:uri]
             [:base-search-url string])

Bing Maps

Syntax is:

(bing-maps [:shortcut string]
           [:fallback-url quri:uri]
           [:base-search-url string])

Bing News

Syntax is:

(bing-news [:shortcut string]
           [:fallback-url quri:uri]
           [:base-search-url string]
           [:interval {:all | :past-5-minutes | :past-15-mimutes | :past-30-minutes |
                       :past-hour | :past-4-hours | :past-6-hours | :past-24-hours |
                       :past-day | :past-7-days | :past-week | :past-30-days | :past-month}])

Bing Shopping

Syntax is:

(bing-shopping [:shortcut string]
               [:fallback-url quri:uri]
               [:base-search-url string])

WordNet

While WordNet is not a general purpose search engine, it’s a great dictionary and a linguistic tool (I mostly use it as a dictionary, though). Syntax is:

(wordnet [:shortcut string]
         [:fallback-url quri:uri]
         [:base-search-url string]
         [:show-examples boolean]
         [:show-glosses boolean]
         [:show-word-frequencies boolean]
         [:show-db-locations boolean]
         [:show-lexical-file-info boolean]
         [:show-lexical-file-numbers boolean]
         [:show-sense-keys boolean]
         [:show-sense-numbers boolean])

Things to do:

  • Shorten the keyword names?

Wikipedia

Wikipedia is included in Nyxt by default, and there’s not much you can configure in it’s search, but it should be in this repo :) Syntax:

(wikipedia [:shortcut string]
           [:fallback-url quri:uri]
           [:base-search-url string]
           [:completion-function function])

Wikipedia completion function helper

make-wikipedia-completion returns a search-ready completion function (it’s already included if you use wikipedia). Syntax is:

(make-wikipedia-completion [:suggestion-limit integer]
                           [:namespace namespace-keyword]
                           [:request-args list])

namespace-keyword := {:general | :talk | :user | :user-talk | :wikipedia | :wikipedia-talk |
                      :file | :file-talk | :media-wiki | :media-wiki-talk | :template |
                      :template-talk | :help | :help-talk | :category | :category-talk}

Yahoo

Yahoo is still under development (I’m trying to figure out its sorting mechanism). Usable, though. Syntax:

(yahoo [:shortcut string]
       [:fallback-url quri:uri]
       [:base-search-url string]
       [:completion-function function]
       [:number-of-results number]
       [:encoding {:utf}]
       [:domain {:any | :dot-com | :dot-edu | :dot-gov | :dot-org}]
       [:date {:past-day | :past-week | :past-month}])

Yahoo completion helper

make-yahoo-completion returns a search-ready completion function (it’s already included if you use yahoo). Syntax is:

(make-yahoo-completion [:suggestion-limit integer]
                       [:request-args list])

SearX

Syntax:

(searx [:shortcut string]
       [:fallback-url quri:uri]
       [:base-search-url string] ; customize the instance there
       [:completion-function function]
       [:categories {:general | :images | :files | :map | :it |
                     :news | :science | :social-media | :videos}]
       [:language string] ; like en-US
       [:time-range {:day | :week | :month | :year}])

Startpage

All the settings which are accessible from the search page can be configured. In order to specify settings from Startpage’s “Settings” page, set `:settings-string` to the hexadecimal number situated after “prfe=” in the URL displayed in the “Save without cookie” section. Syntax:

(startpage [:shortcut string]
           [:fallback-url quri:uri]
           [:base-search-url string]
           [:object {:web | :images | :videos | :news }
           ;; If `language-ui` or `language-results` are set in Startpage's
           ;; settings page, either via a cookie or the settings string, the
           ;; settings below will be overridden.
           [:language-ui {:dansk | :deutsch | :english | :espanol | :francais |
                          :nederlands | :norsk | :polski | :portugues | :svenska}]
           [:language-results  {:afrikaans | :albanian | :amharic | :arabic |
                                :azerbaijani | :basque | :belarusian | :bengali |
                                :bihari | :bosnian | :bulgarian | :catalan |
                                :croatian | :czech | :dansk | :deutsch | :english |
                                :english-uk | :espanol | :esperanto | :estonian |
                                :fantizhengwen | :faroese | :francais | :frisian |
                                :gaelic | :galician | :georgian | :greek |
                                :gujarati | :hangul | :hebrew | :hindi | :hungarian |
                                :icelandic | :indonesian | :interlingua |
                                :irish | :italiano | :javanese | :jiantizhongwen |
                                :kannada | :latin | :latvian | :lithuanian |
                                :macedonian | :malay | :malayalam | :maltese |
                                :marathi | :nederlands | :nepali | :nihongo |
                                :norsk | :occitan | :persian | :polski | :portugues |
                                :punjabi | :romanian | :russian | :serbian |
                                :sinhalese | :slovak | :slovenian | :sudanese |
                                :suomi | :svenska | :swahili | :tagalog |
                                :tamil | :telugu | :thai | :tigrinya |
                                :turkce | :ukrainian | :urdu | :uzbek |
                                :vietnamese | :welsh | :xhosa | :zulu}]
           ;; web search arguments:
           [:web-date {:any | :day | :week | :month | :year}]
           [family-filter boolean]
           [:web-region {:all :australia | :austria | :belarus |
                         :belgium-fr | :belgium-nl | :brazil | :bulgaria | :canada |
                         :canada-fr | :chile | :china | :denmark | :egypt | :finland |
                         :france | :germany | :greece | :honk-kong | :india | :japan |
                         :korean | :malaysia | :malaysia-en | :netherlands | :norway |
                         :poland | :portugal | :romania | :russia | :south-africa |
                         :spain | :spain-ca | :sweden | :switzerland-de |
                         :switzerland-fr | :switzerland-it | :taiwan | :turkey |
                         :united-kingdom | :united-states-en | :united-states-es}]
           ;; image search arguments:
           [family-filter {:off | :on}]
           [:images-size {:any :large :medium :large :icon}]
           [:images-size-predefined {:any | :400x300 | :640x480 | :800x600 | :1024x768 |
                                    :1600x1200 ;2MP | :2272x1704 ;4MP | :2816x2112 ;6MP |
                                    :3264x2448 ;8MP | :3648x2736 ;10MP | :4096x3072 ;12MP |
                                    :4480x3360 ;15MP :5120x3840 ;20MP :7216x5412 ;40MP
                                    :9600x7200 ;70MP}]
           [:images-size-exact-width positive-integer
            :images-size-exact-height positive-integer]
           [:images-color {:any | :color-only | :black-white | :transparent |
            :red | :orange | :yellow | :green | :teal | :blue | :purple |
            :pink | :gray | :black | :brown}]
           [:images-type  {:any | :jpg | :png | :gif}]
           ;; video search arguments:
           [family-filter {:off | :on}]
           [videos-filter  {:relevant | :popular | :recent}]
           [videos-length {:any | :short | :medium | :long}]
           ;; news search arguments:
           [news-date  {:any | :day | :week | :month }]
           ;; To use the advanced settings, users should visit https://startpage.com/do/settings,
           ;; modify settings then click on "copy settings URL". The copied
           ;; URL is of the form
           ;; `https://www.startpage.com/do/mypage.pl?prfe=STRING', where
           ;; STRING is a 160 character long hexadecimal number, which should
           ;; be the value of `settings-string'.
           [settings-string string])

Changelog

0.0.1

First version, experimental.

0.9.0

Stable version targeting Nyxt 2-pre-release 6.

  • define-search-engine is full-featured.

1.0.0

Stable release targeting Nyxt 2.0.

1.1.0

  • Remove search-engines-mode as close-to-meaningless and unstable.
  • base-search-url argument to define-search-engine, mainly to support newly added SearX (thanks @edgar-vincent!).
  • Startpage (thanks to @edgar-vincent again).
  • Yahoo!
  • HTML-only DuckDuckGo.

Future Plans

  • Add more engines (see comments in search-engines.lisp).