;; Extension — prefix / wildcard queries.
;; Corpus: 1 "alpha alpine"  2 "beta apple"  3 "banana alpha"
;; allTerms sorted: alpha alpine apple banana beta

(define
  prefix-setup
  "idx = indexDoc 3 \"banana alpha\" (indexDoc 2 \"beta apple\" (indexDoc 1 \"alpha alpine\" emptyIndex))\n")

(define
  prefix-cases
  (list
    (list
      "prefix terms two matches"
      "prefixTerms \"al\" idx"
      (list "alpha" "alpine"))
    (list
      "prefix terms narrower"
      "prefixTerms \"alp\" idx"
      (list "alpha" "alpine"))
    (list
      "prefix terms wide"
      "prefixTerms \"a\" idx"
      (list "alpha" "alpine" "apple"))
    (list "prefix terms single" "prefixTerms \"ban\" idx" (list "banana"))
    (list "prefix terms exact term" "prefixTerms \"beta\" idx" (list "beta"))
    (list "prefix terms none" "prefixTerms \"z\" idx" (list))
    (list
      "prefix docs union"
      "prefixDocs \"al\" idx"
      (list 1 3))
    (list "prefix docs single term" "prefixDocs \"ban\" idx" (list 3))
    (list
      "prefix docs wide"
      "prefixDocs \"a\" idx"
      (list 1 2 3))
    (list "prefix docs none" "prefixDocs \"z\" idx" (list))
    (list
      "prefix docs exact"
      "prefixDocs \"alpha\" idx"
      (list 1 3))
    (list
      "prefix rank ranks by matched terms"
      "prefixRankTfIdf \"al\" idx"
      (list 1 3))
    (list
      "prefix rank single doc"
      "prefixRankTfIdf \"ban\" idx"
      (list 3))
    (list "prefix rank empty" "prefixRankTfIdf \"z\" idx" (list))))

(define
  prefix-results
  (search-batch
    prefix-setup
    (map (fn (c) (nth c 1)) prefix-cases)))

(map-indexed
  (fn
    (i c)
    (hk-test (nth c 0) (nth prefix-results i) (nth c 2)))
  prefix-cases)

{:fail hk-test-fail :pass hk-test-pass :fails hk-test-fails}
