git.iko.soy/typeable/bloodhound
on master help sign in
Merge branch 'master' of github.com:bitemyapp/bloodhound
commit81eef6864522c76b0803c7d8be6629fe31c6e0fa authorChris Allen <cma@bitemyapp.com> dateSun 28 Feb 2016, 21:00 (11 years ago) parentf35ea3d89e3b2a
4 files changed+46−23
.gitignore+1 README.md+28−14 src/Database/Bloodhound/Types.hs+17−3 tests/tests.hs−6
.gitignore+1
@@ -10,3 +10,4 @@ bloodhound-*-docs/
1010bloodhound-*-docs.tar.gz
1111bloodhound.iml
1212.idea/
13+.stack-work/
README.md+28−14
@@ -23,13 +23,27 @@ Version compatibility
2323
2424Elasticsearch \>=1.0 && \<2.0 is recommended. Bloodhound mostly works with 0.9.x, but I don't recommend it if you expect everything to work. As of Bloodhound 0.3 all \>=1.0 && \<2.0 versions of Elasticsearch work. Some (or even most?) features will work with versions \>=2.0, but it is not officially supported yet.
2525
26−Current versions we test against are 1.0.3, 1.1.2, 1.2.3, 1.3.2, and 1.4.0. We also check that GHC 7.6 and 7.8 both build and pass tests. See our [TravisCI](https://travis-ci.org/bitemyapp/bloodhound) to learn more.
26+Current versions we test against are 1.2.4, 1.3.6, 1.4.1, 1.5.2, 1.6.0, and 1.7.2. We also check that GHC 7.6 and 7.8 both build and pass tests. See our [TravisCI](https://travis-ci.org/bitemyapp/bloodhound) to learn more.
2727
2828Stability
2929---------
3030
3131Bloodhound is stable for production use. I will strive to avoid breaking API compatibility from here on forward, but dramatic features like a type-safe, fully integrated mapping API may require breaking things in the future.
3232
33+Testing
34+---------
35+
36+The TravisCI tests are run using [Stack](http://docs.haskellstack.org/en/stable/README.html). You should use Stack instead of `cabal` to build and test Bloodhound to avoid compatibility problems. You will also need to have an ElasticSearch instance running at `localhost:9200` in order to execute some of the tests. See the "Version compatibility" section above for a list of ElasticSearch versions that are officially validated against in TravisCI.
37+
38+Steps to run the tests locally:
39+ 1. Dig through the [past releases] (https://www.elastic.co/downloads/past-releases) section of the ElasticSearch download page and install the desired ElasticSearch versions.
40+ 2. Install [Stack] (http://docs.haskellstack.org/en/stable/README.html#how-to-install)
41+ 3. In your local Bloodhound directory, run `stack setup && stack build`
42+ 4. Start the desired version of ElasticSearch at `localhost:9200`, which should be the default.
43+ 5. Run `stack test` in your local Bloodhound directory.
44+ 6. The unit tests will pass if you re-execute `stack test`, but some of the doctests might fail due to existing data in ElasticSearch. If you want to start with a clean slate, stop your ElasticSearch instance, delete the `data/` folder in the ElasticSearch installation, restart ElasticSearch, and re-run `stack test`.
45+
46+
3347Hackage page and Haddock documentation
3448======================================
3549
@@ -38,7 +52,7 @@ Hackage page and Haddock documentation
3852Elasticsearch Tutorial
3953======================
4054
41−It's not using Bloodhound, but if you need an introduction to or overview of Elasticsearch and how to use it, you can use [this screencast](http://vimeo.com/106463167).
55+It's not using Bloodhound, but if you need an introduction to or overview of Elasticsearch and how to use it, you can use [this screencast](https://vimeo.com/106463167).
4256
4357Examples
4458========
@@ -820,7 +834,7 @@ let ta' = ta { termCollectMode = Just BreadthFirst }
820834let ta'' = TermsAgg ta'
821835```
822836
823−For more documentation on how the Terms Aggregation works, see <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html>
837+For more documentation on how the Terms Aggregation works, see <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html>
824838
825839#### Date Histogram Aggregation
826840
@@ -873,7 +887,7 @@ It is an instance of `BucketAggregation`, and can have nested aggregations in ea
873887Buckets can be extracted from an `AggregationResult` using
874888`toDateHistogram name`
875889
876−For more information on the Date Histogram Aggregation, see: <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html>
890+For more information on the Date Histogram Aggregation, see: <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html>
877891
878892
879893Contributors
@@ -896,12 +910,12 @@ Possible future functionality
896910Span Queries
897911------------
898912
899−Beginning here: <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html>
913+Beginning here: <https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html>
900914
901915Function Score Query
902916--------------------
903917
904−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html>
918+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html>
905919
906920Node discovery and failover
907921---------------------------
@@ -921,42 +935,42 @@ Might require making a lucene index on disk with the appropriate format.
921935GeoShapeQuery
922936-------------
923937
924−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html>
938+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html>
925939
926940GeoShapeFilter
927941--------------
928942
929−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html>
943+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html>
930944
931945Geohash cell filter
932946-------------------
933947
934−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html>
948+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html>
935949
936950HasChild Filter
937951---------------
938952
939−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html>
953+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html>
940954
941955HasParent Filter
942956----------------
943957
944−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-parent-filter.html>
958+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-filter.html>
945959
946960Indices Filter
947961--------------
948962
949−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html>
963+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html>
950964
951965Query Filter
952966------------
953967
954−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html>
968+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html>
955969
956970Script based sorting
957971--------------------
958972
959−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_script_based_sorting>
973+<https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_script_based_sorting>
960974
961975Collapsing redundantly nested and/or structures
962976-----------------------------------------------
src/Database/Bloodhound/Types.hs+17−3
@@ -47,6 +47,7 @@ module Database.Bloodhound.Types
4747 , mkDateHistogram
4848 , mkDocVersion
4949 , docVersionNumber
50+ , toMissing
5051 , toTerms
5152 , toDateHistogram
5253 , omitNulls
@@ -238,6 +239,7 @@ module Database.Bloodhound.Types
238239 , Aggregation(..)
239240 , Aggregations
240241 , AggregationResults
242+ , BucketValue(..)
241243 , Bucket(..)
242244 , BucketAggregation(..)
243245 , TermsAggregation(..)
@@ -264,6 +266,7 @@ module Database.Bloodhound.Types
264266 , HighlightTag(..)
265267 , HitHighlight
266268
269+ , MissingResult(..)
267270 , TermsResult(..)
268271 , DateHistogramResult(..)
269272 , DateRangeResult(..)
@@ -1791,6 +1794,8 @@ data BucketValue = TextValue Text
17911794 | ScientificValue Scientific
17921795 | BoolValue Bool deriving (Show)
17931796
1797+data MissingResult = MissingResult { missingDocCount :: Int } deriving (Show)
1798+
17941799data TermsResult = TermsResult { termKey :: BucketValue
17951800 , termsDocCount :: Int
17961801 , termsAggs :: Maybe AggregationResults } deriving (Show)
@@ -1809,11 +1814,16 @@ data DateRangeResult = DateRangeResult { dateRangeKey :: Text
18091814 , dateRangeAggs :: Maybe AggregationResults } deriving (Show, Eq, Generic, Typeable)
18101815
18111816toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1812−toTerms t a = M.lookup t a >>= deserialize
1813− where deserialize = parseMaybe parseJSON
1817+toTerms = toAggResult
18141818
18151819toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1816−toDateHistogram t a = M.lookup t a >>= deserialize
1820+toDateHistogram = toAggResult
1821+
1822+toMissing :: Text -> AggregationResults -> Maybe MissingResult
1823+toMissing = toAggResult
1824+
1825+toAggResult :: (FromJSON a) => Text -> AggregationResults -> Maybe a
1826+toAggResult t a = M.lookup t a >>= deserialize
18171827 where deserialize = parseMaybe parseJSON
18181828
18191829instance BucketAggregation TermsResult where
@@ -1842,6 +1852,10 @@ instance FromJSON BucketValue where
18421852 parseJSON (Bool b) = return $ BoolValue b
18431853 parseJSON _ = mempty
18441854
1855+instance FromJSON MissingResult where
1856+ parseJSON = withObject "MissingResult" parse
1857+ where parse v = MissingResult <$> v .: "doc_count"
1858+
18451859instance FromJSON TermsResult where
18461860 parseJSON (Object v) = TermsResult <$>
18471861 v .: "key" <*>
tests/tests.hs−6
@@ -66,9 +66,6 @@ deleteExampleIndex = deleteIndex testIndex
6666
6767data ServerVersion = ServerVersion Int Int Int deriving (Show, Eq, Ord)
6868
69−es14 :: ServerVersion
70−es14 = ServerVersion 1 4 0
71−
7269es13 :: ServerVersion
7370es13 = ServerVersion 1 3 0
7471
@@ -78,9 +75,6 @@ es12 = ServerVersion 1 2 0
7875es11 :: ServerVersion
7976es11 = ServerVersion 1 1 0
8077
81−es10 :: ServerVersion
82−es10 = ServerVersion 1 0 0
83−
8478serverBranch :: ServerVersion -> ServerVersion
8579serverBranch (ServerVersion majorVer minorVer patchVer) =
8680 ServerVersion majorVer minorVer patchVer