@@ -130,7 +130,8 @@ data Tweet = Tweet { user :: Text
130 , postDate :: UTCTime
130 , postDate :: UTCTime
131 , message :: Text
131 , message :: Text
132 , age :: Int
132 , age :: Int
133− , location :: Location }
133+ , location :: Location
134+ , extra :: Maybe Text }
134 deriving (Eq, Generic, Show)
135 deriving (Eq, Generic, Show)
136instance ToJSON Tweet where
137instance ToJSON Tweet where
@@ -178,7 +179,18 @@ exampleTweet = Tweet { user = "bitemyapp"
178 (secondsToDiffTime 10)
179 (secondsToDiffTime 10)
179 , message = "Use haskell!"
180 , message = "Use haskell!"
180 , age = 10000
181 , age = 10000
181− , location = Location 40.12 (-71.34) }
182+ , location = Location 40.12 (-71.34)
185+tweetWithExtra :: Tweet
186+tweetWithExtra = Tweet { user = "bitemyapp"
187+ , postDate = UTCTime
188+ (ModifiedJulianDay 55000)
189+ (secondsToDiffTime 10)
190+ , message = "Use haskell!"
192+ , location = Location 40.12 (-71.34)
193+ , extra = Just "blah blah" }
183newAge :: Int
195newAge :: Int
184newAge = 31337
196newAge = 31337
@@ -202,7 +214,8 @@ otherTweet = Tweet { user = "notmyapp"
202 (secondsToDiffTime 11)
214 (secondsToDiffTime 11)
203 , message = "Use haskell!"
215 , message = "Use haskell!"
204 , age = 1000
216 , age = 1000
205− , location = Location 40.12 (-71.34) }
217+ , location = Location 40.12 (-71.34)
207resetIndex :: BH IO ()
220resetIndex :: BH IO ()
208resetIndex = do
221resetIndex = do
@@ -234,6 +247,12 @@ insertOther = do
234 _ <- refreshIndex testIndex
247 _ <- refreshIndex testIndex
235 return ()
248 return ()
250+insertExtra :: BH IO ()
252+ _ <- indexDocument testIndex testMapping defaultIndexDocumentSettings tweetWithExtra (DocId "4")
253+ _ <- refreshIndex testIndex
237insertWithSpaceInId :: BH IO ()
256insertWithSpaceInId :: BH IO ()
238insertWithSpaceInId = do
257insertWithSpaceInId = do
239 _ <- indexDocument testIndex testMapping defaultIndexDocumentSettings exampleTweet (DocId "Hello World")
258 _ <- indexDocument testIndex testMapping defaultIndexDocumentSettings exampleTweet (DocId "Hello World")
@@ -1236,6 +1255,16 @@ main = hspec $ do
1236 forM_ intervals expect
1255 forM_ intervals expect
1237 forM_ intervals valid
1256 forM_ intervals valid
1258+ it "can execute missing aggregations" $ withTestEnv $ do
1261+ let ags = mkAggregations "missing_agg" (MissingAgg (MissingAggregation "extra"))
1262+ let search = mkAggregateSearch Nothing ags
1263+ let docCountPair k n = (k, object ["doc_count" .= Number n])
1264+ res <- searchTweets search
1266+ fmap aggregations res `shouldBe` Right (Just (M.fromList [docCountPair "missing_agg" 1]))
1239 describe "Highlights API" $ do
1268 describe "Highlights API" $ do
1241 it "returns highlight from query when there should be one" $ withTestEnv $ do
1270 it "returns highlight from query when there should be one" $ withTestEnv $ do
@@ -1284,7 +1313,8 @@ main = hspec $ do
1285 it "excludes source patterns" $ withTestEnv $ do
1314 it "excludes source patterns" $ withTestEnv $ do
1286 searchExpectSource
1315 searchExpectSource
1316+ (SourceIncludeExclude (Include [])
1287− (SourceIncludeExclude (Include []) (Exclude [Pattern "l*", Pattern "*ge", Pattern "postDate"]))
1317+ (Exclude [Pattern "l*", Pattern "*ge", Pattern "postDate", Pattern "extra"]))
1288 (Right (Object (HM.fromList [("user",String "bitemyapp")])))
1318 (Right (Object (HM.fromList [("user",String "bitemyapp")])))
1290 describe "ToJSON RegexpFlags" $ do
1320 describe "ToJSON RegexpFlags" $ do