Fix failing test after search was refactored

This commit is contained in:
Cadence Ember 2024-01-10 11:21:42 +13:00
parent b8a6c5198d
commit b02e2a4053
3 changed files with 12 additions and 10 deletions

View file

@ -25,8 +25,8 @@
page-search) page-search)
(define search-providers (define search-providers
(hash "fandom" generate-results-content-fandom (hash "fandom" search-fandom
"solr" generate-results-content-solr)) "solr" search-solr))
;; this takes the info we gathered from fandom and makes the big fat x-expression page ;; this takes the info we gathered from fandom and makes the big fat x-expression page
(define (generate-results-page req source-url wikiname query results-content #:siteinfo [siteinfo #f]) (define (generate-results-page req source-url wikiname query results-content #:siteinfo [siteinfo #f])

View file

@ -8,15 +8,15 @@
"../lib/xexpr-utils.rkt") "../lib/xexpr-utils.rkt")
(provide (provide
generate-results-content-fandom) search-fandom)
(module+ test (module+ test
(require rackunit (require rackunit
"test-utils.rkt") "test-utils.rkt")
(define search-json-data (define search-results-data
'#hasheq((batchcomplete . #t) (query . #hasheq((search . (#hasheq((ns . 0) (pageid . 219) (size . 1482) (snippet . "") (timestamp . "2022-08-21T08:54:23Z") (title . "Gacha Capsule") (wordcount . 214)) #hasheq((ns . 0) (pageid . 201) (size . 1198) (snippet . "") (timestamp . "2022-07-11T17:52:47Z") (title . "Badges") (wordcount . 181))))))))) '(#hasheq((ns . 0) (pageid . 219) (size . 1482) (snippet . "") (timestamp . "2022-08-21T08:54:23Z") (title . "Gacha Capsule") (wordcount . 214)) #hasheq((ns . 0) (pageid . 201) (size . 1198) (snippet . "") (timestamp . "2022-07-11T17:52:47Z") (title . "Badges") (wordcount . 181)))))
(define (generate-results-content-fandom wikiname query params) (define (search-fandom wikiname query params)
;; constructing the URL where I want to get fandom data from... ;; constructing the URL where I want to get fandom data from...
(define origin (format "https://~a.fandom.com" wikiname)) (define origin (format "https://~a.fandom.com" wikiname))
;; the dest-URL will look something like https://minecraft.fandom.com/api.php?action=query&list=search&srsearch=Spawner&formatversion=2&format=json ;; the dest-URL will look something like https://minecraft.fandom.com/api.php?action=query&list=search&srsearch=Spawner&formatversion=2&format=json
@ -33,8 +33,10 @@
(define res (easy:get dest-url #:timeouts timeouts)) (define res (easy:get dest-url #:timeouts timeouts))
(define json (easy:response-json res)) (define json (easy:response-json res))
(define search-results (jp "/query/search" json)) (define search-results (jp "/query/search" json))
(generate-results-content-fandom wikiname query search-results))
;; generate content for display in the wiki page layout ;;; generate content for display in the wiki page layout
(define (generate-results-content-fandom wikiname query search-results)
`(div (@ (class "mw-parser-output")) `(div (@ (class "mw-parser-output"))
;; header before the search results showing how many we found ;; header before the search results showing how many we found
(p ,(format "~a results found for " (length search-results)) (p ,(format "~a results found for " (length search-results))
@ -60,4 +62,4 @@
(module+ test (module+ test
(parameterize ([(config-parameter 'feature_offline::only) "false"]) (parameterize ([(config-parameter 'feature_offline::only) "false"])
(check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Gacha_Capsule") (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Gacha_Capsule")
(generate-results-content-fandom test-req "" "test" "Gacha" search-json-data)))))) (generate-results-content-fandom "test" "Gacha" search-results-data))))))

View file

@ -9,11 +9,11 @@
"../lib/xexpr-utils.rkt") "../lib/xexpr-utils.rkt")
(provide (provide
generate-results-content-solr) search-solr)
(struct result^ (hl-title hl-body kb words page-path) #:transparent) (struct result^ (hl-title hl-body kb words page-path) #:transparent)
(define (generate-results-content-solr wikiname query params) (define (search-solr wikiname query params)
;; grab things from params that would modify the search ;; grab things from params that would modify the search
(define op (if (equal? (dict-ref params 'op #f) "or") '("or" . "OR") '("and" . "AND"))) (define op (if (equal? (dict-ref params 'op #f) "or") '("or" . "OR") '("and" . "AND")))
(define sort (if (equal? (dict-ref params 'sort #f) "len") '("len" . "len desc") '("relevance" . "score desc"))) (define sort (if (equal? (dict-ref params 'sort #f) "len") '("len" . "len desc") '("relevance" . "score desc")))