git.iko.soy/typeable/bloodhound
on master help sign in
Added check for empty Array to omitNulls
c9e8dd3Liam Atkinson
Database/Bloodhound/Types.hs+38−35
@@ -1,4 +1,4 @@
1−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE RecordWildCards #-}
2{-# LANGUAGE RecordWildCards #-}
3
3
4{-| Data types for describing actions and data structures performed to interact
4{-| Data types for describing actions and data structures performed to interact
@@ -144,20 +144,22 @@ module Database.Bloodhound.Types
144 , ToJSON(..)
144 , ToJSON(..)
145 ) where
145 ) where
146
146
147−import Control.Applicative
147+import Control.Applicative
148−import Data.Aeson
148+import Data.Aeson
149−import qualified Data.ByteString.Lazy.Char8 as L
149+import qualified Data.ByteString.Lazy.Char8 as L
150−import Data.List (nub)
150+import Data.List (nub)
151−import Data.List.NonEmpty (NonEmpty(..))
151+import Data.List.NonEmpty (NonEmpty (..))
152−import Data.Monoid
152+import Data.Monoid
153−import Data.Text (Text)
153+import Data.Text (Text)
154−import qualified Data.Text as T
154+import qualified Data.Text as T
155−import Data.Time.Clock (UTCTime)
155+import Data.Time.Clock (UTCTime)
156+import Data.Vector (Vector (..))
157+import qualified Data.Vector as V
156−import GHC.Generics (Generic)
158+import GHC.Generics (Generic)
157−import Network.HTTP.Client
159+import Network.HTTP.Client
158−import qualified Network.HTTP.Types.Method as NHTM
160+import qualified Network.HTTP.Types.Method as NHTM
159
161
160−import Database.Bloodhound.Types.Class
162+import Database.Bloodhound.Types.Class
161
163
162
164
163{-| 'Version' is embedded in 'Status' -}
165{-| 'Version' is embedded in 'Status' -}
@@ -215,8 +217,8 @@ data FieldDefinition =
215 FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
217 FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
216
218
217data MappingField =
219data MappingField =
218− MappingField { mappingFieldName :: FieldName
220+ MappingField { mappingFieldName :: FieldName
219− , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
221+ , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
220
222
221{-| Support for type reification of 'Mapping's is currently incomplete, for
223{-| Support for type reification of 'Mapping's is currently incomplete, for
222 now the mapping API verbiage expects a 'ToJSON'able blob.
224 now the mapping API verbiage expects a 'ToJSON'able blob.
@@ -471,13 +473,13 @@ type TrackSortScores = Bool
471type From = Int
473type From = Int
472type Size = Int
474type Size = Int
473
475
474−data Search = Search { queryBody :: Maybe Query
476+data Search = Search { queryBody :: Maybe Query
475− , filterBody :: Maybe Filter
477+ , filterBody :: Maybe Filter
476− , sortBody :: Maybe Sort
478+ , sortBody :: Maybe Sort
477 -- default False
479 -- default False
478 , trackSortScores :: TrackSortScores
480 , trackSortScores :: TrackSortScores
479− , from :: From
481+ , from :: From
480− , size :: Size } deriving (Eq, Show)
482+ , size :: Size } deriving (Eq, Show)
481
483
482data Query =
484data Query =
483 TermQuery Term (Maybe Boost)
485 TermQuery Term (Maybe Boost)
@@ -510,10 +512,10 @@ data Query =
510 deriving (Eq, Show)
512 deriving (Eq, Show)
511
513
512data RegexpQuery =
514data RegexpQuery =
513− RegexpQuery { regexpQueryField :: FieldName
515+ RegexpQuery { regexpQueryField :: FieldName
514− , regexpQuery :: Regexp
516+ , regexpQuery :: Regexp
515− , regexpQueryFlags :: RegexpFlags
517+ , regexpQueryFlags :: RegexpFlags
516− , regexpQueryBoost :: Maybe Boost
518+ , regexpQueryBoost :: Maybe Boost
517 } deriving (Eq, Show)
519 } deriving (Eq, Show)
518
520
519data RangeQuery =
521data RangeQuery =
@@ -633,9 +635,9 @@ data MoreLikeThisQuery =
633data IndicesQuery =
635data IndicesQuery =
634 IndicesQuery
636 IndicesQuery
635 { indicesQueryIndices :: [IndexName]
637 { indicesQueryIndices :: [IndexName]
636− , indicesQuery :: Query
638+ , indicesQuery :: Query
637 -- default "all"
639 -- default "all"
638− , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
640+ , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
639
641
640data HasParentQuery =
642data HasParentQuery =
641 HasParentQuery
643 HasParentQuery
@@ -787,7 +789,7 @@ data CommonMinimumMatch =
787 deriving (Eq, Show)
789 deriving (Eq, Show)
788
790
789data MinimumMatchHighLow =
791data MinimumMatchHighLow =
790− MinimumMatchHighLow { lowFreq :: MinimumMatch
792+ MinimumMatchHighLow { lowFreq :: MinimumMatch
791 , highFreq :: MinimumMatch } deriving (Eq, Show)
793 , highFreq :: MinimumMatch } deriving (Eq, Show)
792
794
793data Filter = AndFilter [Filter] Cache
795data Filter = AndFilter [Filter] Cache
@@ -926,11 +928,11 @@ data FromJSON a => SearchHits a =
926 , hits :: [Hit a] } deriving (Eq, Show)
928 , hits :: [Hit a] } deriving (Eq, Show)
927
929
928data FromJSON a => Hit a =
930data FromJSON a => Hit a =
929− Hit { hitIndex :: IndexName
931+ Hit { hitIndex :: IndexName
930− , hitType :: MappingName
932+ , hitType :: MappingName
931− , hitDocId :: DocId
933+ , hitDocId :: DocId
932− , hitScore :: Score
934+ , hitScore :: Score
933− , hitSource :: a } deriving (Eq, Show)
935+ , hitSource :: a } deriving (Eq, Show)
934
936
935data ShardResult =
937data ShardResult =
936 ShardResult { shardTotal :: Int
938 ShardResult { shardTotal :: Int
@@ -1152,8 +1154,9 @@ instance ToJSON Query where
1152
1154
1153omitNulls :: [(Text, Value)] -> Value
1155omitNulls :: [(Text, Value)] -> Value
1154omitNulls = object . filter notNull where
1156omitNulls = object . filter notNull where
1155− notNull (_, Null) = False
1157+ notNull (_, Null) = False
1156− notNull _ = True
1158+ notNull (_, (Array a)) = V.null a
1159+ notNull _ = True
1157
1160
1158
1161
1159instance ToJSON SimpleQueryStringQuery where
1162instance ToJSON SimpleQueryStringQuery where