;; Extension — did-you-mean / spelling suggestion.
;; Corpus terms (sorted): ample apple apply banana orange

(define
  suggest-setup
  "idx = indexDoc 1 \"apple apply ample banana orange\" emptyIndex\n")

(define
  suggest-cases
  (list
    (list "suggest exact term" "[suggest \"apple\" idx]" (list "apple"))
    (list
      "suggest misspelled banana"
      "[suggest \"bananna\" idx]"
      (list "banana"))
    (list
      "suggest missing letter orange"
      "[suggest \"orang\" idx]"
      (list "orange"))
    (list "suggest closest apply" "[suggest \"aply\" idx]" (list "apply"))
    (list "suggestN 1 banana" "suggestN 1 \"bananna\" idx" (list "banana"))
    (list
      "suggestN 2 ties alpha"
      "suggestN 2 \"aple\" idx"
      (list "ample" "apple"))
    (list "suggest empty term shortest" "[suggest \"\" idx]" (list "ample"))
    (list "suggest empty index" "[suggest \"apple\" emptyIndex]" (list ""))
    (list "suggestN empty index" "suggestN 1 \"apple\" emptyIndex" (list))))

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

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

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