summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmaan Bhojwani <me@armaanb.net>2021-11-28 12:50:40 -0500
committerArmaan Bhojwani <me@armaanb.net>2021-11-28 12:51:01 -0500
commitf5c4822a930c5856e49d0dd89fc0c7eea9c32c87 (patch)
tree66b1b9d73ec91437971f6269c27fc8902b9eb5a1
parent4cf9cd77acc6cc8f5d8165cf50b3e8cf3395a333 (diff)
downloadbettersearch-f5c4822a930c5856e49d0dd89fc0c7eea9c32c87.tar.gz
Add a distribution framework0.1
-rw-r--r--.gitignore1
-rw-r--r--Makefile5
-rw-r--r--README6
-rw-r--r--TODO1
-rw-r--r--bettersearch.rkt (renamed from server.rkt)45
5 files changed, 35 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6b915b1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+bettersearch
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..15d8f92
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+dist: clean
+ raco exe bettersearch.rkt
+
+clean:
+ rm -rf bettersearch
diff --git a/README b/README
index 88e5c09..ea5d485 100644
--- a/README
+++ b/README
@@ -1,3 +1,9 @@
Web search that sucks a little bit less
+Written in racket. Build an executable with 'make' and reverse proxy as you
+wish. Runs on port 8000 by default.
+
+You must set the SEARX_INSTANCE environment variable to a searx instance like
+"https://search.trom.tf".
+
https://search.armaanb.net
diff --git a/TODO b/TODO
index ad2c40a..e69de29 100644
--- a/TODO
+++ b/TODO
@@ -1 +0,0 @@
-* Customizeable searx instance
diff --git a/server.rkt b/bettersearch.rkt
index 2b13b6c..4fc695e 100644
--- a/server.rkt
+++ b/bettersearch.rkt
@@ -31,11 +31,12 @@
(define (search query pageno)
(define engine (string->url
(string-append
- "https://search.trom.tf/search?format=json&q="
- query
- "&pageno="
- pageno
- )))
+ (getenv "SEARX_INSTANCE")
+ "/search?format=json&q="
+ query
+ "&pageno="
+ pageno
+ )))
(define response (get-pure-port engine))
(define json-raw (port->string response))
(close-input-port response)
@@ -65,23 +66,23 @@
(define results
(foldr cons '()
(filter hash?
- (map (lambda (i)
- (define result-host
- (url-host (string->url
- (hash-ref i 'url ""))))
- (define result-url (hash-ref i 'url ""))
- (define result-title (hash-ref i 'title ""))
- (define result-content (hash-ref i 'content ""))
- (define ht (make-hash))
- (unless (member-match? result-host blacklist)
- (let ()
- (hash-set! ht "title" result-title)
- (hash-set! ht "url" result-url)
- (hash-set! ht "content" result-content)
- )
- ht
- ))
- (hash-ref (search query pageno) 'results)))))
+ (map (lambda (i)
+ (define result-host
+ (url-host (string->url
+ (hash-ref i 'url ""))))
+ (define result-url (hash-ref i 'url ""))
+ (define result-title (hash-ref i 'title ""))
+ (define result-content (hash-ref i 'content ""))
+ (define ht (make-hash))
+ (unless (member-match? result-host blacklist)
+ (let ()
+ (hash-set! ht "title" result-title)
+ (hash-set! ht "url" result-url)
+ (hash-set! ht "content" result-content)
+ )
+ ht
+ ))
+ (hash-ref (search query pageno) 'results)))))
(http-response (string-append
(do-head (string-append query " | Web Search"))
(include-template "templates/search.html")