;; search boolean-filtered ranked search — Haskell source fragment. ;; Depends on parse (parseQuery/Query), query (evalQuery), rank (tfidfDoc/bm25Doc/ ;; cmpScore). Filters by the boolean query, then ranks the surviving docs by ;; relevance over the query's leaf terms — the real-world filter-then-rank pattern. ;; queryTerms :: Query -> [Term] ;; searchRankTfIdf :: String -> Index -> [DocId] ;; searchRankBm25 :: Float -> Float -> String -> Index -> [DocId] (define search/rankq-src "queryTerms (Term t) = [t]\nqueryTerms (And a b) = queryTerms a ++ queryTerms b\nqueryTerms (Or a b) = queryTerms a ++ queryTerms b\nqueryTerms (Not a) = queryTerms a\nqueryTerms (Phrase ts) = ts\nmkSubPair f terms idx d = (f terms idx d, d)\nrankSubsetWith f terms docs idx = map snd (sortBy cmpScore (map (mkSubPair f terms idx) docs))\nsearchRankTfIdf s idx = let q = parseQuery s in rankSubsetWith tfidfDoc (queryTerms q) (evalQuery idx q) idx\nsearchRankBm25 k1 b s idx = let q = parseQuery s in rankSubsetWith (bm25Doc k1 b) (queryTerms q) (evalQuery idx q) idx\n")