Added a constructor to denote "auto" fuzziness to the Fuzziness type

This commit is contained in:
Ashutosh Rishi Ranjan 2018-06-19 18:21:05 +10:00
parent 4e61602b3f
commit 52b67cdbdf
2 changed files with 13 additions and 2 deletions

View File

@ -110,8 +110,6 @@ newtype MinimumTermFrequency =
MinimumTermFrequency Int deriving (Eq, Show, FromJSON, ToJSON)
newtype MaxQueryTerms =
MaxQueryTerms Int deriving (Eq, Show, FromJSON, ToJSON)
newtype Fuzziness =
Fuzziness Double deriving (Eq, Show, FromJSON, ToJSON)
{-| 'PrefixLength' is the prefix length used in queries, defaults to 0. -}
newtype PrefixLength =

View File

@ -1624,3 +1624,16 @@ fieldTagged :: Monad m => (FieldName -> Object -> m a) -> Object -> m a
fieldTagged f o = case HM.toList o of
[(k, Object o')] -> f (FieldName k) o'
_ -> fail "Expected object with 1 field-named key"
{-| Fuzziness value as a number or 'AUTO'. -}
data Fuzziness = Fuzziness Double | FuzzinessAuto
deriving (Eq, Show)
instance ToJSON Fuzziness where
toJSON (Fuzziness n) = toJSON n
toJSON FuzzinessAuto = String "AUTO"
instance FromJSON Fuzziness where
parseJSON (String "AUTO") = return FuzzinessAuto
parseJSON (String "auto") = return FuzzinessAuto
parseJSON v = Fuzziness <$> parseJSON v