Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Fuzzy string search in Haskell.
Uses TextualMonoid
to be able to run on different types of strings.
Synopsis
- data Fuzzy val prettyText = Fuzzy {}
- data CaseSensitivity
- null :: TextualMonoid s => s -> Bool
- match :: TextualMonoid text => CaseSensitivity -> (text, text) -> (value -> text) -> text -> value -> Maybe (Fuzzy value text)
- filter :: TextualMonoid text => CaseSensitivity -> (text, text) -> (value -> text) -> text -> [value] -> [Fuzzy value text]
- simpleFilter :: TextualMonoid text => text -> [text] -> [text]
- test :: TextualMonoid text => text -> text -> Bool
Documentation
data Fuzzy val prettyText Source #
Included in the return type of match
and filter
.
Contains the original value given, the rendered string
and the matching score.
data CaseSensitivity Source #
Instances
Show CaseSensitivity Source # | |
Defined in Text.Fuzzily showsPrec :: Int -> CaseSensitivity -> ShowS # show :: CaseSensitivity -> String # showList :: [CaseSensitivity] -> ShowS # | |
Eq CaseSensitivity Source # | |
Defined in Text.Fuzzily (==) :: CaseSensitivity -> CaseSensitivity -> Bool # (/=) :: CaseSensitivity -> CaseSensitivity -> Bool # |
null :: TextualMonoid s => s -> Bool Source #
:: TextualMonoid text | |
=> CaseSensitivity | Handle or ignore case of search text |
-> (text, text) | Text to add before and after each match |
-> (value -> text) | Function to extract the text from the container |
-> text | Pattern |
-> value | Value containing the text to search in |
-> Maybe (Fuzzy value text) | Original value, rendered string, and score |
Returns the rendered output and the matching score for a pattern and a text. Two examples are given below:
>>>
match HandleCase ("", "") identity "fnt" "infinite"
Just (Fuzzy { original = "infinite" , rendered = "infinite" , score = 3 })
>>>
match IgnoreCase ("<", ">") fst "hsk" ("Haskell", 1995)
Just (Fuzzy { original = ("Haskell", 1995) , rendered = "<h>a<s><k>ell" , score = 5 })
:: TextualMonoid text | |
=> CaseSensitivity | Handle or ignore case of search text |
-> (text, text) | Text to add before and after each match |
-> (value -> text) | Function to extract the text from the container |
-> text | Pattern |
-> [value] | List of values containing the text to search in |
-> [Fuzzy value text] | List of results, sorted, highest score first |
The function to filter a list of values by fuzzy search on the text extracted from them.
>>>
langs = [("Standard ML", 1990), ("OCaml", 1996), ("Scala", 2003)]
>>>
filter "ML" langs ("<", ">") fst IgnoreCase
[ Fuzzy { original = ("Standard ML", 1990) , rendered = "standard <m><l>" , score = 4} , Fuzzy { original = ("OCaml", 1996) , rendered = "oca<m><l>" , score = 4 } ]
:: TextualMonoid text | |
=> text | Pattern to look for. |
-> [text] | List of texts to check. |
-> [text] | The ones that match. |
Return all elements of the list that have a fuzzy match against the pattern. Runs with default settings where nothing is added around the matches, as case insensitive.
>>>
simpleFilter "vm" ["vim", "emacs", "virtual machine"]
["vim","virtual machine"]
test :: TextualMonoid text => text -> text -> Bool Source #
Returns false if the pattern and the text do not match at all. Returns true otherwise.
>>>
test "brd" "bread"
True