Skip to content

Latest commit

 

History

History
44 lines (30 loc) · 1.11 KB

replace-rewriter.md

File metadata and controls

44 lines (30 loc) · 1.11 KB

Replace Rewriter

The Replace Rewriter is mainly intended as a pre-processing step for other rewriters. Some common use cases are to fix typos, delete unhelpful terms, and otherwise fix up user input so that subsequent rewriters are simpler to define.

See the Querqy docs for more details.

Usage

Querqy File

You can read in a text file with replace rules written in the Querqy Replace Rewriter syntax. See the docs for the details of that format.

This format is particularly useful if you can source a large list of typos and their corrections from your query logs.

(require '[com.nytimes.querqy.replace :refer [replace-rewriter]])
(require '[clojure.java.io :as io])

(replace-rewriter (io/resource "replace-rules.txt"))

DSL

The querqy-clj library ships with a DSL for creating a replace rewriter from Clojure.

(require '[com.nytimes.querqy.replace :as r])

(r/replace-rewriter
  ;; Fix typos
  (r/replace "abocado" (r/with "avocado"))

  ;; Delete useless terms
  (r/delete "recipe")
  (r/delete "recipes"))