git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #204 from jagare/examples-location
b879d5fChris Allen
examples/Tweet.hs+3−16
@@ -29,22 +29,13 @@ instance ToJSON TweetMapping where
29 [ "properties" .=
29 [ "properties" .=
30 object ["location" .= object ["type" .= ("geo_point" :: Text)]]
30 object ["location" .= object ["type" .= ("geo_point" :: Text)]]
31 ]
31 ]
32−
33−
34−-------------------------------------------------------------------------------
35−data Location = Location
36− { locLat :: Double
37− , locLon :: Double
38− } deriving (Eq, Generic, Show)
39−
40−
41-------------------------------------------------------------------------------
32-------------------------------------------------------------------------------
42data Tweet = Tweet
33data Tweet = Tweet
43 { user :: Text
34 { user :: Text
44 , postDate :: UTCTime
35 , postDate :: UTCTime
45 , message :: Text
36 , message :: Text
46 , age :: Int
37 , age :: Int
47− , location :: Location
38+ , location :: LatLon
48 } deriving (Eq, Generic, Show)
39 } deriving (Eq, Generic, Show)
49
40
50
41
@@ -59,16 +50,12 @@ exampleTweet =
59 , location = loc
50 , location = loc
60 }
51 }
61 where
52 where
62− loc = Location {locLat = 40.12, locLon = (-71.34)}
53+ loc = LatLon {lat = 40.12, lon = -71.3}
63
54
64instance ToJSON Tweet where
55instance ToJSON Tweet where
65 toJSON = genericToJSON defaultOptions
56 toJSON = genericToJSON defaultOptions
66instance FromJSON Tweet where
57instance FromJSON Tweet where
67 parseJSON = genericParseJSON defaultOptions
58 parseJSON = genericParseJSON defaultOptions
68−instance ToJSON Location where
69− toJSON = genericToJSON defaultOptions
70−instance FromJSON Location where
71− parseJSON = genericParseJSON defaultOptions
72
59
73
60
74main :: IO ()
61main :: IO ()
@@ -117,7 +104,7 @@ main = runBH' $ do
117
104
118 return ()
105 return ()
119 where
106 where
120− testServer = (Server "http://localhost:9200")
107+ testServer = Server "http://localhost:9200"
121 runBH' = withBH defaultManagerSettings testServer
108 runBH' = withBH defaultManagerSettings testServer
122 testIndex = IndexName "twitter"
109 testIndex = IndexName "twitter"
123 testMapping = MappingName "tweet"
110 testMapping = MappingName "tweet"