git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #105 from MHova/missing-result
6126d00Chris Allen
src/Database/Bloodhound/Types.hs+16−3
@@ -47,6 +47,7 @@ module Database.Bloodhound.Types
47 , mkDateHistogram
47 , mkDateHistogram
48 , mkDocVersion
48 , mkDocVersion
49 , docVersionNumber
49 , docVersionNumber
50+ , toMissing
50 , toTerms
51 , toTerms
51 , toDateHistogram
52 , toDateHistogram
52 , omitNulls
53 , omitNulls
@@ -265,6 +266,7 @@ module Database.Bloodhound.Types
265 , HighlightTag(..)
266 , HighlightTag(..)
266 , HitHighlight
267 , HitHighlight
267
268
269+ , MissingResult(..)
268 , TermsResult(..)
270 , TermsResult(..)
269 , DateHistogramResult(..)
271 , DateHistogramResult(..)
270 , DateRangeResult(..)
272 , DateRangeResult(..)
@@ -1792,6 +1794,8 @@ data BucketValue = TextValue Text
1792 | ScientificValue Scientific
1794 | ScientificValue Scientific
1793 | BoolValue Bool deriving (Show)
1795 | BoolValue Bool deriving (Show)
1794
1796
1797+data MissingResult = MissingResult { missingDocCount :: Int } deriving (Show)
1798+
1795data TermsResult = TermsResult { termKey :: BucketValue
1799data TermsResult = TermsResult { termKey :: BucketValue
1796 , termsDocCount :: Int
1800 , termsDocCount :: Int
1797 , termsAggs :: Maybe AggregationResults } deriving (Show)
1801 , termsAggs :: Maybe AggregationResults } deriving (Show)
@@ -1810,11 +1814,16 @@ data DateRangeResult = DateRangeResult { dateRangeKey :: Text
1810 , dateRangeAggs :: Maybe AggregationResults } deriving (Show, Eq, Generic, Typeable)
1814 , dateRangeAggs :: Maybe AggregationResults } deriving (Show, Eq, Generic, Typeable)
1811
1815
1812toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1816toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1813−toTerms t a = M.lookup t a >>= deserialize
1817+toTerms = toAggResult
1814− where deserialize = parseMaybe parseJSON
1815
1818
1816toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1819toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1820+toDateHistogram = toAggResult
1821+
1822+toMissing :: Text -> AggregationResults -> Maybe MissingResult
1823+toMissing = toAggResult
1824+
1825+toAggResult :: (FromJSON a) => Text -> AggregationResults -> Maybe a
1817−toDateHistogram t a = M.lookup t a >>= deserialize
1826+toAggResult t a = M.lookup t a >>= deserialize
1818 where deserialize = parseMaybe parseJSON
1827 where deserialize = parseMaybe parseJSON
1819
1828
1820instance BucketAggregation TermsResult where
1829instance BucketAggregation TermsResult where
@@ -1843,6 +1852,10 @@ instance FromJSON BucketValue where
1843 parseJSON (Bool b) = return $ BoolValue b
1852 parseJSON (Bool b) = return $ BoolValue b
1844 parseJSON _ = mempty
1853 parseJSON _ = mempty
1845
1854
1855+instance FromJSON MissingResult where
1856+ parseJSON = withObject "MissingResult" parse
1857+ where parse v = MissingResult <$> v .: "doc_count"
1858+
1846instance FromJSON TermsResult where
1859instance FromJSON TermsResult where
1847 parseJSON (Object v) = TermsResult <$>
1860 parseJSON (Object v) = TermsResult <$>
1848 v .: "key" <*>
1861 v .: "key" <*>