git.iko.soy/typeable/bloodhound
on master help sign in
Added check for empty Array to omitNulls
commitc9e8dd3581937941456c4b7fd6cae9c1a2924762 authorLiam Atkinson <liamatkinson@gmail.com> dateThu 9 Oct 2014, 22:06 (12 years ago) parent7cf7b4e
1 file changed+38−35
Database/Bloodhound/Types.hs+38−35
Database/Bloodhound/Types.hs+38−35
@@ -1,4 +1,4 @@
1−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DeriveGeneric #-}
22{-# LANGUAGE RecordWildCards #-}
33
44{-| Data types for describing actions and data structures performed to interact
@@ -144,20 +144,22 @@ module Database.Bloodhound.Types
144144 , ToJSON(..)
145145 ) where
146146
147−import Control.Applicative
148−import Data.Aeson
149−import qualified Data.ByteString.Lazy.Char8 as L
150−import Data.List (nub)
151−import Data.List.NonEmpty (NonEmpty(..))
152−import Data.Monoid
153−import Data.Text (Text)
154−import qualified Data.Text as T
155−import Data.Time.Clock (UTCTime)
156−import GHC.Generics (Generic)
157−import Network.HTTP.Client
158−import qualified Network.HTTP.Types.Method as NHTM
147+import Control.Applicative
148+import Data.Aeson
149+import qualified Data.ByteString.Lazy.Char8 as L
150+import Data.List (nub)
151+import Data.List.NonEmpty (NonEmpty (..))
152+import Data.Monoid
153+import Data.Text (Text)
154+import qualified Data.Text as T
155+import Data.Time.Clock (UTCTime)
156+import Data.Vector (Vector (..))
157+import qualified Data.Vector as V
158+import GHC.Generics (Generic)
159+import Network.HTTP.Client
160+import qualified Network.HTTP.Types.Method as NHTM
159161
160−import Database.Bloodhound.Types.Class
162+import Database.Bloodhound.Types.Class
161163
162164
163165{-| 'Version' is embedded in 'Status' -}
@@ -215,8 +217,8 @@ data FieldDefinition =
215217 FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
216218
217219data MappingField =
218− MappingField { mappingFieldName :: FieldName
219− , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
220+ MappingField { mappingFieldName :: FieldName
221+ , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
220222
221223{-| Support for type reification of 'Mapping's is currently incomplete, for
222224 now the mapping API verbiage expects a 'ToJSON'able blob.
@@ -471,13 +473,13 @@ type TrackSortScores = Bool
471473type From = Int
472474type Size = Int
473475
474−data Search = Search { queryBody :: Maybe Query
475− , filterBody :: Maybe Filter
476− , sortBody :: Maybe Sort
476+data Search = Search { queryBody :: Maybe Query
477+ , filterBody :: Maybe Filter
478+ , sortBody :: Maybe Sort
477479 -- default False
478480 , trackSortScores :: TrackSortScores
479− , from :: From
480− , size :: Size } deriving (Eq, Show)
481+ , from :: From
482+ , size :: Size } deriving (Eq, Show)
481483
482484data Query =
483485 TermQuery Term (Maybe Boost)
@@ -510,10 +512,10 @@ data Query =
510512 deriving (Eq, Show)
511513
512514data RegexpQuery =
513− RegexpQuery { regexpQueryField :: FieldName
514− , regexpQuery :: Regexp
515− , regexpQueryFlags :: RegexpFlags
516− , regexpQueryBoost :: Maybe Boost
515+ RegexpQuery { regexpQueryField :: FieldName
516+ , regexpQuery :: Regexp
517+ , regexpQueryFlags :: RegexpFlags
518+ , regexpQueryBoost :: Maybe Boost
517519 } deriving (Eq, Show)
518520
519521data RangeQuery =
@@ -633,9 +635,9 @@ data MoreLikeThisQuery =
633635data IndicesQuery =
634636 IndicesQuery
635637 { indicesQueryIndices :: [IndexName]
636− , indicesQuery :: Query
638+ , indicesQuery :: Query
637639 -- default "all"
638− , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
640+ , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
639641
640642data HasParentQuery =
641643 HasParentQuery
@@ -787,7 +789,7 @@ data CommonMinimumMatch =
787789 deriving (Eq, Show)
788790
789791data MinimumMatchHighLow =
790− MinimumMatchHighLow { lowFreq :: MinimumMatch
792+ MinimumMatchHighLow { lowFreq :: MinimumMatch
791793 , highFreq :: MinimumMatch } deriving (Eq, Show)
792794
793795data Filter = AndFilter [Filter] Cache
@@ -926,11 +928,11 @@ data FromJSON a => SearchHits a =
926928 , hits :: [Hit a] } deriving (Eq, Show)
927929
928930data FromJSON a => Hit a =
929− Hit { hitIndex :: IndexName
930− , hitType :: MappingName
931− , hitDocId :: DocId
932− , hitScore :: Score
933− , hitSource :: a } deriving (Eq, Show)
931+ Hit { hitIndex :: IndexName
932+ , hitType :: MappingName
933+ , hitDocId :: DocId
934+ , hitScore :: Score
935+ , hitSource :: a } deriving (Eq, Show)
934936
935937data ShardResult =
936938 ShardResult { shardTotal :: Int
@@ -1152,8 +1154,9 @@ instance ToJSON Query where
11521154
11531155omitNulls :: [(Text, Value)] -> Value
11541156omitNulls = object . filter notNull where
1155− notNull (_, Null) = False
1156− notNull _ = True
1157+ notNull (_, Null) = False
1158+ notNull (_, (Array a)) = V.null a
1159+ notNull _ = True
11571160
11581161
11591162instance ToJSON SimpleQueryStringQuery where