git.iko.soy/typeable/bloodhound
on master help sign in
killed non-test orphans, added note about specific Elasticsearch version
b5437e8Chris Allen
Database/Bloodhound.hs−2
@@ -1,9 +1,7 @@
1module Database.Bloodhound
1module Database.Bloodhound
2 ( module Database.Bloodhound.Client
2 ( module Database.Bloodhound.Client
3 , module Database.Bloodhound.Types
3 , module Database.Bloodhound.Types
4− , module Database.Bloodhound.Types.Instances
5 ) where
4 ) where
6
5
7import Database.Bloodhound.Client
6import Database.Bloodhound.Client
8import Database.Bloodhound.Types
7import Database.Bloodhound.Types
9−import Database.Bloodhound.Types.Instances
Database/Bloodhound/Client.hs−1
@@ -35,7 +35,6 @@ import qualified Network.HTTP.Types.Status as NHTS
35import Prelude hiding (head, filter)
35import Prelude hiding (head, filter)
36
36
37import Database.Bloodhound.Types
37import Database.Bloodhound.Types
38−import Database.Bloodhound.Types.Instances
39
38
40-- find way to avoid destructuring Servers and Indexes?
39-- find way to avoid destructuring Servers and Indexes?
41-- make get, post, put, delete helpers.
40-- make get, post, put, delete helpers.
Database/Bloodhound/Types.hs+788−2
@@ -141,18 +141,26 @@ module Database.Bloodhound.Types
141 , EnablePositionIncrements(..)
141 , EnablePositionIncrements(..)
142 , SimpleQueryFlag(..)
142 , SimpleQueryFlag(..)
143 , FieldOrFields(..)
143 , FieldOrFields(..)
144+ , Monoid(..)
145+ , ToJSON(..)
144 ) where
146 ) where
145
147
148+import Control.Applicative
146import Data.Aeson
149import Data.Aeson
147import qualified Data.ByteString.Lazy.Char8 as L
150import qualified Data.ByteString.Lazy.Char8 as L
148−import Data.List.NonEmpty (NonEmpty)
151+import Data.List (nub)
152+import Data.List.NonEmpty (NonEmpty(..))
153+import Data.Maybe (catMaybes)
154+import Data.Monoid
149import Data.Text (Text)
155import Data.Text (Text)
150import qualified Data.Text as T
156import qualified Data.Text as T
151import Data.Time.Clock (UTCTime)
157import Data.Time.Clock (UTCTime)
152−import Database.Bloodhound.Types.Class
153import GHC.Generics (Generic)
158import GHC.Generics (Generic)
154import Network.HTTP.Client
159import Network.HTTP.Client
155import qualified Network.HTTP.Types.Method as NHTM
160import qualified Network.HTTP.Types.Method as NHTM
161+import Prelude hiding (filter)
162+
163+import Database.Bloodhound.Types.Class
156
164
157
165
158{-| 'Version' is embedded in 'Status' -}
166{-| 'Version' is embedded in 'Status' -}
@@ -942,3 +950,781 @@ maybeJsonF _ _ = []
942
950
943showText :: Show a => a -> Text
951showText :: Show a => a -> Text
944showText = T.pack . show
952showText = T.pack . show
953+
954+
955+instance Monoid Filter where
956+ mempty = IdentityFilter
957+ mappend a b = AndFilter [a, b] defaultCache
958+
959+instance Seminearring Filter where
960+ a <||> b = OrFilter [a, b] defaultCache
961+
962+instance ToJSON Filter where
963+ toJSON (AndFilter filters cache) =
964+ object ["and" .= fmap toJSON filters
965+ , "_cache" .= cache]
966+
967+ toJSON (OrFilter filters cache) =
968+ object ["or" .= fmap toJSON filters
969+ , "_cache" .= cache]
970+
971+ toJSON (NotFilter filter cache) =
972+ object ["not" .=
973+ object ["filter" .= toJSON filter
974+ , "_cache" .= cache]]
975+
976+ toJSON (IdentityFilter) =
977+ object ["match_all" .= object []]
978+
979+ toJSON (TermFilter (Term termFilterField termFilterValue) cache) =
980+ object ["term" .= object base]
981+ where base = [termFilterField .= termFilterValue,
982+ "_cache" .= cache]
983+
984+ toJSON (ExistsFilter (FieldName fieldName)) =
985+ object ["exists" .= object
986+ ["field" .= fieldName]]
987+
988+ toJSON (BoolFilter boolMatch) =
989+ object ["bool" .= toJSON boolMatch]
990+
991+ toJSON (GeoBoundingBoxFilter bbConstraint filterType) =
992+ object ["geo_bounding_box" .= toJSON bbConstraint
993+ , "type" .= toJSON filterType]
994+
995+ toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
996+ distance distanceType optimizeBbox cache) =
997+ object ["geo_distance" .=
998+ object ["distance" .= toJSON distance
999+ , "distance_type" .= toJSON distanceType
1000+ , "optimize_bbox" .= optimizeBbox
1001+ , distanceGeoField .= toJSON geoDistLatLon
1002+ , "_cache" .= cache]]
1003+
1004+ toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1005+ (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1006+ object ["geo_distance_range" .=
1007+ object ["from" .= toJSON geoDistRangeDistFrom
1008+ , "to" .= toJSON drDistanceTo
1009+ , gddrField .= toJSON drLatLon]]
1010+
1011+ toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1012+ object ["geo_polygon" .=
1013+ object [geoPolygonFilterField .=
1014+ object ["points" .= fmap toJSON latLons]]]
1015+
1016+ toJSON (IdsFilter (MappingName mappingName) values) =
1017+ object ["ids" .=
1018+ object ["type" .= mappingName
1019+ , "values" .= fmap (T.pack . unpackId) values]]
1020+
1021+ toJSON (LimitFilter limit) =
1022+ object ["limit" .= object ["value" .= limit]]
1023+
1024+ toJSON (MissingFilter (FieldName fieldName) (Existence existence) (NullValue nullValue)) =
1025+ object ["missing" .=
1026+ object ["field" .= fieldName
1027+ , "existence" .= existence
1028+ , "null_value" .= nullValue]]
1029+
1030+ toJSON (PrefixFilter (FieldName fieldName) fieldValue cache) =
1031+ object ["prefix" .=
1032+ object [fieldName .= fieldValue
1033+ , "_cache" .= cache]]
1034+
1035+ toJSON (RangeFilter (FieldName fieldName) (Left halfRange) rangeExecution cache) =
1036+ object ["range" .=
1037+ object [fieldName .=
1038+ object [key .= val]
1039+ , "execution" .= toJSON rangeExecution
1040+ , "_cache" .= cache]]
1041+ where
1042+ (key, val) = halfRangeToKV halfRange
1043+
1044+ toJSON (RangeFilter (FieldName fieldName) (Right range) rangeExecution cache) =
1045+ object ["range" .=
1046+ object [fieldName .=
1047+ object [lessKey .= lessVal
1048+ , greaterKey .= greaterVal]
1049+ , "execution" .= toJSON rangeExecution
1050+ , "_cache" .= cache]]
1051+ where
1052+ (lessKey, lessVal, greaterKey, greaterVal) = rangeToKV range
1053+
1054+ toJSON (RegexpFilter (FieldName fieldName)
1055+ (Regexp regexText) flags (CacheName cacheName) cache (CacheKey cacheKey)) =
1056+ object ["regexp" .=
1057+ object [fieldName .=
1058+ object ["value" .= regexText
1059+ , "flags" .= toJSON flags]
1060+ , "_name" .= cacheName
1061+ , "_cache" .= cache
1062+ , "_cache_key" .= cacheKey]]
1063+
1064+instance ToJSON GeoPoint where
1065+ toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1066+ object [ geoPointField .= toJSON geoPointLatLon ]
1067+
1068+
1069+instance ToJSON Query where
1070+ toJSON (TermQuery (Term termQueryField termQueryValue) boost) =
1071+ object [ "term" .=
1072+ object [termQueryField .= object merged]]
1073+ where
1074+ base = [ "value" .= termQueryValue ]
1075+ boosted = maybe [] (return . ("boost" .=)) boost
1076+ merged = mappend base boosted
1077+
1078+ toJSON (TermsQuery terms termsQueryMinimumMatch) =
1079+ object [ "terms" .= object conjoined ]
1080+ where conjoined =
1081+ [ "tags" .= fmap toJSON terms
1082+ , "minimum_should_match" .= toJSON termsQueryMinimumMatch ]
1083+
1084+ toJSON (IdsQuery idsQueryMappingName docIds) =
1085+ object [ "ids" .= object conjoined ]
1086+ where conjoined = [ "type" .= toJSON idsQueryMappingName
1087+ , "values" .= fmap toJSON docIds ]
1088+
1089+ toJSON (QueryQueryStringQuery qQueryStringQuery) =
1090+ object [ "query_string" .= toJSON qQueryStringQuery ]
1091+
1092+ toJSON (QueryMatchQuery matchQuery) =
1093+ object [ "match" .= toJSON matchQuery ]
1094+
1095+ toJSON (QueryMultiMatchQuery multiMatchQuery) =
1096+ object [ "multi_match" .= toJSON multiMatchQuery ]
1097+
1098+ toJSON (QueryBoolQuery boolQuery) =
1099+ object [ "bool" .= toJSON boolQuery ]
1100+
1101+ toJSON (QueryBoostingQuery boostingQuery) =
1102+ object [ "boosting" .= toJSON boostingQuery ]
1103+
1104+ toJSON (QueryCommonTermsQuery commonTermsQuery) =
1105+ object [ "common" .= toJSON commonTermsQuery ]
1106+
1107+ toJSON (ConstantScoreFilter filter boost) =
1108+ object [ "constant_score" .= toJSON filter
1109+ , "boost" .= toJSON boost]
1110+
1111+ toJSON (ConstantScoreQuery query boost) =
1112+ object [ "constant_score" .= toJSON query
1113+ , "boost" .= toJSON boost]
1114+
1115+ toJSON (QueryDisMaxQuery disMaxQuery) =
1116+ object [ "dis_max" .= toJSON disMaxQuery ]
1117+
1118+ toJSON (QueryFilteredQuery qFilteredQuery) =
1119+ object [ "filtered" .= toJSON qFilteredQuery ]
1120+
1121+ toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1122+ object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
1123+
1124+ toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1125+ object [ "fuzzy_like_this_field" .= toJSON fuzzyFieldQuery ]
1126+
1127+ toJSON (QueryFuzzyQuery fuzzyQuery) =
1128+ object [ "fuzzy" .= toJSON fuzzyQuery ]
1129+
1130+ toJSON (QueryHasChildQuery childQuery) =
1131+ object [ "has_child" .= toJSON childQuery ]
1132+
1133+ toJSON (QueryHasParentQuery parentQuery) =
1134+ object [ "has_parent" .= toJSON parentQuery ]
1135+
1136+ toJSON (QueryIndicesQuery qIndicesQuery) =
1137+ object [ "indices" .= toJSON qIndicesQuery ]
1138+
1139+ toJSON (MatchAllQuery boost) =
1140+ object [ "match_all" .= object maybeAdd ]
1141+ where maybeAdd = catMaybes [ mField "boost" boost ]
1142+
1143+ toJSON (QueryMoreLikeThisQuery query) =
1144+ object [ "more_like_this" .= toJSON query ]
1145+
1146+ toJSON (QueryMoreLikeThisFieldQuery query) =
1147+ object [ "more_like_this_field" .= toJSON query ]
1148+
1149+ toJSON (QueryNestedQuery query) =
1150+ object [ "nested" .= toJSON query ]
1151+
1152+ toJSON (QueryPrefixQuery query) =
1153+ object [ "prefix" .= toJSON query ]
1154+
1155+ toJSON (QueryRangeQuery query) =
1156+ object [ "range" .= toJSON query ]
1157+
1158+ toJSON (QueryRegexpQuery query) =
1159+ object [ "regexp" .= toJSON query ]
1160+
1161+ toJSON (QuerySimpleQueryStringQuery query) =
1162+ object [ "simple_query_string" .= toJSON query ]
1163+
1164+
1165+mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
1166+mField field = fmap ((field .=) . toJSON)
1167+
1168+instance ToJSON SimpleQueryStringQuery where
1169+ toJSON (SimpleQueryStringQuery sqsQueryString
1170+ sqsFields sqsBoolean sqsAnalyzer
1171+ sqsFlags sqsLowercaseExpanded sqsLocale) =
1172+ object conjoined
1173+ where base = [ "query" .= toJSON sqsQueryString ]
1174+ maybeAdd =
1175+ catMaybes [ mField "fields" sqsFields
1176+ , mField "default_operator" sqsBoolean
1177+ , mField "analyzer" sqsAnalyzer
1178+ , mField "flags" sqsFlags
1179+ , mField "lowercase_expanded_terms" sqsLowercaseExpanded
1180+ , mField "locale" sqsLocale ]
1181+ conjoined = base ++ maybeAdd
1182+
1183+instance ToJSON FieldOrFields where
1184+ toJSON (FofField fieldName) =
1185+ toJSON fieldName
1186+ toJSON (FofFields fieldNames) =
1187+ toJSON fieldNames
1188+
1189+instance ToJSON SimpleQueryFlag where
1190+ toJSON SimpleQueryAll = "ALL"
1191+ toJSON SimpleQueryNone = "NONE"
1192+ toJSON SimpleQueryAnd = "AND"
1193+ toJSON SimpleQueryOr = "OR"
1194+ toJSON SimpleQueryPrefix = "PREFIX"
1195+ toJSON SimpleQueryPhrase = "PHRASE"
1196+ toJSON SimpleQueryPrecedence = "PRECEDENCE"
1197+ toJSON SimpleQueryEscape = "ESCAPE"
1198+ toJSON SimpleQueryWhitespace = "WHITESPACE"
1199+ toJSON SimpleQueryFuzzy = "FUZZY"
1200+ toJSON SimpleQueryNear = "NEAR"
1201+ toJSON SimpleQuerySlop = "SLOP"
1202+
1203+instance ToJSON RegexpQuery where
1204+ toJSON (RegexpQuery (FieldName rqQueryField)
1205+ (Regexp regexpQueryQuery) rqQueryFlags
1206+ rqQueryBoost) =
1207+ object [ rqQueryField .= object conjoined ]
1208+ where base = [ "value" .= regexpQueryQuery
1209+ , "flags" .= toJSON rqQueryFlags ]
1210+ maybeAdd = catMaybes [ mField "boost" rqQueryBoost ]
1211+ conjoined = base ++ maybeAdd
1212+
1213+instance ToJSON QueryStringQuery where
1214+ toJSON (QueryStringQuery qsQueryString
1215+ qsDefaultField qsOperator
1216+ qsAnalyzer qsAllowWildcard
1217+ qsLowercaseExpanded qsEnablePositionIncrements
1218+ qsFuzzyMaxExpansions qsFuzziness
1219+ qsFuzzyPrefixLength qsPhraseSlop
1220+ qsBoost qsAnalyzeWildcard
1221+ qsGeneratePhraseQueries qsMinimumShouldMatch
1222+ qsLenient qsLocale) =
1223+ object conjoined
1224+ where
1225+ base = [ "query" .= toJSON qsQueryString ]
1226+ maybeAdd =
1227+ catMaybes [ mField "default_field" qsDefaultField
1228+ , mField "default_operator" qsOperator
1229+ , mField "analyzer" qsAnalyzer
1230+ , mField "allow_leading_wildcard" qsAllowWildcard
1231+ , mField "lowercase_expanded_terms" qsLowercaseExpanded
1232+ , mField "enable_position_increments" qsEnablePositionIncrements
1233+ , mField "fuzzy_max_expansions" qsFuzzyMaxExpansions
1234+ , mField "fuzziness" qsFuzziness
1235+ , mField "fuzzy_prefix_length" qsFuzzyPrefixLength
1236+ , mField "phrase_slop" qsPhraseSlop
1237+ , mField "boost" qsBoost
1238+ , mField "analyze_wildcard" qsAnalyzeWildcard
1239+ , mField "auto_generate_phrase_queries" qsGeneratePhraseQueries
1240+ , mField "minimum_should_match" qsMinimumShouldMatch
1241+ , mField "lenient" qsLenient
1242+ , mField "locale" qsLocale ]
1243+ conjoined = base ++ maybeAdd
1244+
1245+instance ToJSON RangeQuery where
1246+ toJSON (RangeQuery (FieldName fieldName) (Right range) boost) =
1247+ object [ fieldName .= conjoined ]
1248+ where conjoined = [ "boost" .= toJSON boost
1249+ , lessKey .= lessVal
1250+ , greaterKey .= greaterVal ]
1251+ (lessKey, lessVal, greaterKey, greaterVal) = rangeToKV range
1252+
1253+ toJSON (RangeQuery (FieldName fieldName) (Left halfRange) boost) =
1254+ object [ fieldName .= conjoined ]
1255+ where conjoined = [ "boost" .= toJSON boost
1256+ , key .= val ]
1257+ (key, val) = halfRangeToKV halfRange
1258+
1259+instance ToJSON PrefixQuery where
1260+ toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1261+ object [ fieldName .= object conjoined ]
1262+ where base = [ "value" .= toJSON queryValue ]
1263+ maybeAdd = catMaybes [ mField "boost" boost ]
1264+ conjoined = base ++ maybeAdd
1265+
1266+
1267+instance ToJSON NestedQuery where
1268+ toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1269+ object [ "path" .= toJSON nqPath
1270+ , "score_mode" .= toJSON nqScoreType
1271+ , "query" .= toJSON nqQuery ]
1272+
1273+
1274+instance ToJSON MoreLikeThisFieldQuery where
1275+ toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
1276+ percent mtf mqt stopwords mindf maxdf
1277+ minwl maxwl boostTerms boost analyzer) =
1278+ object [ fieldName .= object conjoined ]
1279+ where base = [ "like_text" .= toJSON text ]
1280+ maybeAdd = catMaybes [ mField "percent_terms_to_match" percent
1281+ , mField "min_term_freq" mtf
1282+ , mField "max_query_terms" mqt
1283+ , mField "stop_words" stopwords
1284+ , mField "min_doc_freq" mindf
1285+ , mField "max_doc_freq" maxdf
1286+ , mField "min_word_length" minwl
1287+ , mField "max_word_length" maxwl
1288+ , mField "boost_terms" boostTerms
1289+ , mField "boost" boost
1290+ , mField "analyzer" analyzer ]
1291+ conjoined = base ++ maybeAdd
1292+
1293+
1294+instance ToJSON MoreLikeThisQuery where
1295+ toJSON (MoreLikeThisQuery text fields percent
1296+ mtf mqt stopwords mindf maxdf
1297+ minwl maxwl boostTerms boost analyzer) =
1298+ object conjoined
1299+ where base = [ "like_text" .= toJSON text ]
1300+ maybeAdd = catMaybes [ mField "fields" fields
1301+ , mField "percent_terms_to_match" percent
1302+ , mField "min_term_freq" mtf
1303+ , mField "max_query_terms" mqt
1304+ , mField "stop_words" stopwords
1305+ , mField "min_doc_freq" mindf
1306+ , mField "max_doc_freq" maxdf
1307+ , mField "min_word_length" minwl
1308+ , mField "max_word_length" maxwl
1309+ , mField "boost_terms" boostTerms
1310+ , mField "boost" boost
1311+ , mField "analyzer" analyzer ]
1312+ conjoined = base ++ maybeAdd
1313+
1314+
1315+instance ToJSON IndicesQuery where
1316+ toJSON (IndicesQuery indices query noMatch) =
1317+ object $ [ "indices" .= toJSON indices
1318+ , "query" .= toJSON query ] ++ maybeAdd
1319+ where maybeAdd = catMaybes [ mField "no_match_query" noMatch ]
1320+
1321+
1322+instance ToJSON HasParentQuery where
1323+ toJSON (HasParentQuery queryType query scoreType) =
1324+ object $ [ "parent_type" .= toJSON queryType
1325+ , "query" .= toJSON query ] ++ maybeAdd
1326+ where maybeAdd = catMaybes [ mField "score_type" scoreType ]
1327+
1328+
1329+instance ToJSON HasChildQuery where
1330+ toJSON (HasChildQuery queryType query scoreType) =
1331+ object $ [ "query" .= toJSON query
1332+ , "type" .= toJSON queryType ] ++ maybeAdd
1333+ where maybeAdd = catMaybes [ mField "score_type" scoreType ]
1334+
1335+
1336+instance ToJSON FuzzyQuery where
1337+ toJSON (FuzzyQuery (FieldName fieldName) queryText
1338+ prefixLength maxEx fuzziness boost) =
1339+ object [ fieldName .= object conjoined ]
1340+ where base = [ "value" .= toJSON queryText
1341+ , "fuzziness" .= toJSON fuzziness
1342+ , "prefix_length" .= toJSON prefixLength
1343+ , "max_expansions" .= toJSON maxEx ]
1344+ maybeAdd = catMaybes [ mField "boost" boost ]
1345+ conjoined = base ++ maybeAdd
1346+
1347+
1348+instance ToJSON FuzzyLikeFieldQuery where
1349+ toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
1350+ fieldText maxTerms ignoreFreq fuzziness prefixLength
1351+ boost analyzer) =
1352+ object $ [ fieldName .=
1353+ object [ "like_text" .= toJSON fieldText
1354+ , "max_query_terms" .= toJSON maxTerms
1355+ , "ignore_tf" .= toJSON ignoreFreq
1356+ , "fuzziness" .= toJSON fuzziness
1357+ , "prefix_length" .= toJSON prefixLength
1358+ , "boost" .= toJSON boost ]] ++ maybeAdd
1359+ where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
1360+
1361+
1362+instance ToJSON FuzzyLikeThisQuery where
1363+ toJSON (FuzzyLikeThisQuery fields text maxTerms
1364+ ignoreFreq fuzziness prefixLength boost analyzer) =
1365+ object conjoined
1366+ where base = [ "fields" .= toJSON fields
1367+ , "like_text" .= toJSON text
1368+ , "max_query_terms" .= toJSON maxTerms
1369+ , "ignore_tf" .= toJSON ignoreFreq
1370+ , "fuzziness" .= toJSON fuzziness
1371+ , "prefix_length" .= toJSON prefixLength
1372+ , "boost" .= toJSON boost ]
1373+ maybeAdd = catMaybes [ mField "analyzer" analyzer ]
1374+ conjoined = base ++ maybeAdd
1375+
1376+
1377+instance ToJSON FilteredQuery where
1378+ toJSON (FilteredQuery query filter) =
1379+ object [ "query" .= toJSON query
1380+ , "filter" .= toJSON filter ]
1381+
1382+
1383+instance ToJSON DisMaxQuery where
1384+ toJSON (DisMaxQuery queries tiebreaker boost) =
1385+ object conjoined
1386+ where maybeAdd = catMaybes [mField "boost" boost]
1387+ base = [ "queries" .= toJSON queries
1388+ , "tie_breaker" .= toJSON tiebreaker ]
1389+ conjoined = base ++ maybeAdd
1390+
1391+
1392+instance ToJSON CommonTermsQuery where
1393+ toJSON (CommonTermsQuery (FieldName fieldName)
1394+ (QueryString query) cf lfo hfo msm
1395+ boost analyzer disableCoord) =
1396+ object [fieldName .= object conjoined]
1397+ where base = [ "query" .= query
1398+ , "cutoff_frequency" .= toJSON cf
1399+ , "low_freq_operator" .= toJSON lfo
1400+ , "high_freq_operator" .= toJSON hfo ]
1401+ extension = catMaybes
1402+ [ mField "minimum_should_match" msm
1403+ , mField "boost" boost
1404+ , mField "analyzer" analyzer
1405+ , mField "disable_coord" disableCoord ]
1406+ conjoined = base ++ extension
1407+
1408+
1409+instance ToJSON CommonMinimumMatch where
1410+ toJSON (CommonMinimumMatch mm) = toJSON mm
1411+ toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1412+ object [ "low_freq" .= toJSON lowF
1413+ , "high_freq" .= toJSON highF ]
1414+
1415+instance ToJSON BoostingQuery where
1416+ toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1417+ object [ "positive" .= toJSON bqPositiveQuery
1418+ , "negative" .= toJSON bqNegativeQuery
1419+ , "negative_boost" .= toJSON bqNegativeBoost ]
1420+
1421+
1422+instance ToJSON BoolQuery where
1423+ toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1424+ object filtered
1425+ where filtered = catMaybes
1426+ [ mField "must" mustM
1427+ , mField "must_not" notM
1428+ , mField "should" shouldM
1429+ , mField "minimum_should_match" bqMin
1430+ , mField "boost" boost
1431+ , mField "disable_coord" disableCoord ]
1432+
1433+
1434+instance ToJSON MatchQuery where
1435+ toJSON (MatchQuery (FieldName fieldName)
1436+ (QueryString mqQueryString) booleanOperator
1437+ zeroTermsQuery cutoffFrequency matchQueryType
1438+ analyzer maxExpansions lenient) =
1439+ object [ fieldName .= object conjoined ]
1440+ where conjoined = [ "query" .= mqQueryString
1441+ , "operator" .= toJSON booleanOperator
1442+ , "zero_terms_query" .= toJSON zeroTermsQuery]
1443+ ++ maybeAdd
1444+ maybeAdd = catMaybes [ mField "cutoff_frequency" cutoffFrequency
1445+ , mField "type" matchQueryType
1446+ , mField "analyzer" analyzer
1447+ , mField "max_expansions" maxExpansions
1448+ , mField "lenient" lenient ]
1449+
1450+
1451+instance ToJSON MultiMatchQuery where
1452+ toJSON (MultiMatchQuery fields (QueryString query) boolOp
1453+ ztQ tb mmqt cf analyzer maxEx lenient) =
1454+ object ["multi_match" .= object conjoined]
1455+ where baseQuery = [ "fields" .= fmap toJSON fields
1456+ , "query" .= query
1457+ , "operator" .= toJSON boolOp
1458+ , "zero_terms_query" .= toJSON ztQ ]
1459+ maybeAdd = catMaybes [ mField "tiebreaker" tb
1460+ , mField "type" mmqt
1461+ , mField "cutoff_frequency" cf
1462+ , mField "analyzer" analyzer
1463+ , mField "max_expansions" maxEx
1464+ , mField "lenient" lenient ]
1465+ conjoined = baseQuery ++ maybeAdd
1466+
1467+
1468+instance ToJSON MultiMatchQueryType where
1469+ toJSON MultiMatchBestFields = "best_fields"
1470+ toJSON MultiMatchMostFields = "most_fields"
1471+ toJSON MultiMatchCrossFields = "cross_fields"
1472+ toJSON MultiMatchPhrase = "phrase"
1473+ toJSON MultiMatchPhrasePrefix = "phrase_prefix"
1474+
1475+instance ToJSON BooleanOperator where
1476+ toJSON And = String "and"
1477+ toJSON Or = String "or"
1478+
1479+instance ToJSON ZeroTermsQuery where
1480+ toJSON ZeroTermsNone = String "none"
1481+ toJSON ZeroTermsAll = String "all"
1482+
1483+instance ToJSON MatchQueryType where
1484+ toJSON MatchPhrase = "phrase"
1485+ toJSON MatchPhrasePrefix = "phrase_prefix"
1486+
1487+instance ToJSON FieldName where
1488+ toJSON (FieldName fieldName) = String fieldName
1489+
1490+instance ToJSON ReplicaCount
1491+instance ToJSON ShardCount
1492+instance ToJSON CutoffFrequency
1493+instance ToJSON Analyzer
1494+instance ToJSON MaxExpansions
1495+instance ToJSON Lenient
1496+instance ToJSON Boost
1497+instance ToJSON Version
1498+instance ToJSON Tiebreaker
1499+instance ToJSON MinimumMatch
1500+instance ToJSON DisableCoord
1501+instance ToJSON PrefixLength
1502+instance ToJSON Fuzziness
1503+instance ToJSON IgnoreTermFrequency
1504+instance ToJSON MaxQueryTerms
1505+instance ToJSON TypeName
1506+instance ToJSON IndexName
1507+instance ToJSON BoostTerms
1508+instance ToJSON MaxWordLength
1509+instance ToJSON MinWordLength
1510+instance ToJSON MaxDocFrequency
1511+instance ToJSON MinDocFrequency
1512+instance ToJSON PhraseSlop
1513+instance ToJSON StopWord
1514+instance ToJSON QueryPath
1515+instance ToJSON MinimumTermFrequency
1516+instance ToJSON PercentMatch
1517+instance ToJSON MappingName
1518+instance ToJSON DocId
1519+instance ToJSON QueryString
1520+instance ToJSON AllowLeadingWildcard
1521+instance ToJSON LowercaseExpanded
1522+instance ToJSON AnalyzeWildcard
1523+instance ToJSON GeneratePhraseQueries
1524+instance ToJSON Locale
1525+instance ToJSON EnablePositionIncrements
1526+instance FromJSON Version
1527+instance FromJSON IndexName
1528+instance FromJSON MappingName
1529+instance FromJSON DocId
1530+
1531+
1532+instance FromJSON Status where
1533+ parseJSON (Object v) = Status <$>
1534+ v .: "ok" <*>
1535+ v .: "status" <*>
1536+ v .: "name" <*>
1537+ v .: "version" <*>
1538+ v .: "tagline"
1539+ parseJSON _ = empty
1540+
1541+
1542+instance ToJSON IndexSettings where
1543+ toJSON (IndexSettings s r) = object ["settings" .= object ["shards" .= s, "replicas" .= r]]
1544+
1545+
1546+instance (FromJSON a) => FromJSON (EsResult a) where
1547+ parseJSON (Object v) = EsResult <$>
1548+ v .: "_index" <*>
1549+ v .: "_type" <*>
1550+ v .: "_id" <*>
1551+ v .: "_version" <*>
1552+ v .:? "found" <*>
1553+ v .: "_source"
1554+ parseJSON _ = empty
1555+
1556+
1557+instance ToJSON Search where
1558+ toJSON (Search query filter sort sTrackSortScores sFrom sSize) =
1559+ object merged where
1560+ lQuery = maybeJson "query" query
1561+ lFilter = maybeJson "filter" filter
1562+ lSort = maybeJsonF "sort" sort
1563+ merged = mconcat [[ "from" .= sFrom
1564+ , "size" .= sSize
1565+ , "track_scores" .= sTrackSortScores]
1566+ , lQuery
1567+ , lFilter
1568+ , lSort]
1569+
1570+
1571+instance ToJSON SortSpec where
1572+ toJSON (DefaultSortSpec
1573+ (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
1574+ dsSortMode dsMissingSort dsNestedFilter)) =
1575+ object [dsSortFieldName .= object merged] where
1576+ base = ["order" .= toJSON dsSortOrder
1577+ , "ignore_unmapped" .= dsIgnoreUnmapped]
1578+ lSortMode = maybeJson "mode" dsSortMode
1579+ lMissingSort = maybeJson "missing" dsMissingSort
1580+ lNestedFilter = maybeJson "nested_filter" dsNestedFilter
1581+ merged = mconcat [base, lSortMode, lMissingSort, lNestedFilter]
1582+
1583+ toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
1584+ object [ "unit" .= toJSON units
1585+ , field .= toJSON gdsLatLon
1586+ , "order" .= toJSON gdsSortOrder ]
1587+
1588+
1589+instance ToJSON SortOrder where
1590+ toJSON Ascending = String "asc"
1591+ toJSON Descending = String "desc"
1592+
1593+
1594+instance ToJSON SortMode where
1595+ toJSON SortMin = String "min"
1596+ toJSON SortMax = String "max"
1597+ toJSON SortSum = String "sum"
1598+ toJSON SortAvg = String "avg"
1599+
1600+
1601+instance ToJSON Missing where
1602+ toJSON LastMissing = String "_last"
1603+ toJSON FirstMissing = String "_first"
1604+ toJSON (CustomMissing txt) = String txt
1605+
1606+
1607+instance ToJSON ScoreType where
1608+ toJSON ScoreTypeMax = "max"
1609+ toJSON ScoreTypeAvg = "avg"
1610+ toJSON ScoreTypeSum = "sum"
1611+ toJSON ScoreTypeNone = "none"
1612+
1613+
1614+instance ToJSON Distance where
1615+ toJSON (Distance dCoefficient dUnit) =
1616+ String boltedTogether where
1617+ coefText = showText dCoefficient
1618+ (String unitText) = toJSON dUnit
1619+ boltedTogether = mappend coefText unitText
1620+
1621+
1622+instance ToJSON DistanceUnit where
1623+ toJSON Miles = String "mi"
1624+ toJSON Yards = String "yd"
1625+ toJSON Feet = String "ft"
1626+ toJSON Inches = String "in"
1627+ toJSON Kilometers = String "km"
1628+ toJSON Meters = String "m"
1629+ toJSON Centimeters = String "cm"
1630+ toJSON Millimeters = String "mm"
1631+ toJSON NauticalMiles = String "nmi"
1632+
1633+
1634+instance ToJSON DistanceType where
1635+ toJSON Arc = String "arc"
1636+ toJSON SloppyArc = String "sloppy_arc"
1637+ toJSON Plane = String "plane"
1638+
1639+
1640+instance ToJSON OptimizeBbox where
1641+ toJSON NoOptimizeBbox = String "none"
1642+ toJSON (OptimizeGeoFilterType gft) = toJSON gft
1643+
1644+
1645+instance ToJSON GeoBoundingBoxConstraint where
1646+ toJSON (GeoBoundingBoxConstraint
1647+ (FieldName gbbcGeoBBField) gbbcConstraintBox cache) =
1648+ object [gbbcGeoBBField .= toJSON gbbcConstraintBox
1649+ , "_cache" .= cache]
1650+
1651+
1652+instance ToJSON GeoFilterType where
1653+ toJSON GeoFilterMemory = String "memory"
1654+ toJSON GeoFilterIndexed = String "indexed"
1655+
1656+
1657+instance ToJSON GeoBoundingBox where
1658+ toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
1659+ object ["top_left" .= toJSON gbbTopLeft
1660+ , "bottom_right" .= toJSON gbbBottomRight]
1661+
1662+
1663+instance ToJSON LatLon where
1664+ toJSON (LatLon lLat lLon) =
1665+ object ["lat" .= lLat
1666+ , "lon" .= lLon]
1667+
1668+
1669+-- index for smaller ranges, fielddata for longer ranges
1670+instance ToJSON RangeExecution where
1671+ toJSON RangeExecutionIndex = "index"
1672+ toJSON RangeExecutionFielddata = "fielddata"
1673+
1674+
1675+instance ToJSON RegexpFlags where
1676+ toJSON AllRegexpFlags = String "ALL"
1677+ toJSON NoRegexpFlags = String "NONE"
1678+ toJSON (SomeRegexpFlags (h :| fs)) = String $ T.intercalate "|" flagStrs
1679+ where flagStrs = map flagStr . nub $ h:fs
1680+ flagStr AnyString = "ANYSTRING"
1681+ flagStr Automaton = "AUTOMATON"
1682+ flagStr Complement = "COMPLEMENT"
1683+ flagStr Empty = "EMPTY"
1684+ flagStr Intersection = "INTERSECTION"
1685+ flagStr Interval = "INTERVAL"
1686+
1687+instance ToJSON Term where
1688+ toJSON (Term field value) = object ["term" .= object
1689+ [field .= value]]
1690+
1691+
1692+instance ToJSON BoolMatch where
1693+ toJSON (MustMatch term cache) = object ["must" .= toJSON term,
1694+ "_cache" .= cache]
1695+ toJSON (MustNotMatch term cache) = object ["must_not" .= toJSON term,
1696+ "_cache" .= cache]
1697+ toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
1698+ "_cache" .= cache]
1699+
1700+
1701+instance (FromJSON a) => FromJSON (SearchResult a) where
1702+ parseJSON (Object v) = SearchResult <$>
1703+ v .: "took" <*>
1704+ v .: "timed_out" <*>
1705+ v .: "_shards" <*>
1706+ v .: "hits"
1707+ parseJSON _ = empty
1708+
1709+instance (FromJSON a) => FromJSON (SearchHits a) where
1710+ parseJSON (Object v) = SearchHits <$>
1711+ v .: "total" <*>
1712+ v .: "max_score" <*>
1713+ v .: "hits"
1714+ parseJSON _ = empty
1715+
1716+instance (FromJSON a) => FromJSON (Hit a) where
1717+ parseJSON (Object v) = Hit <$>
1718+ v .: "_index" <*>
1719+ v .: "_type" <*>
1720+ v .: "_id" <*>
1721+ v .: "_score" <*>
1722+ v .: "_source"
1723+ parseJSON _ = empty
1724+
1725+instance FromJSON ShardResult where
1726+ parseJSON (Object v) = ShardResult <$>
1727+ v .: "total" <*>
1728+ v .: "successful" <*>
1729+ v .: "failed"
1730+ parseJSON _ = empty
Database/Bloodhound/Types/Instances.hsdeleted−795
@@ -1,795 +0,0 @@
1−{-# LANGUAGE DeriveGeneric #-}
2−
3−module Database.Bloodhound.Types.Instances
4− ( Monoid(..)
5− , Seminearring(..)
6− , ToJSON(..)
7− ) where
8−
9−import Control.Applicative
10−import Data.Aeson
11−import Data.List (nub)
12−import Data.List.NonEmpty (NonEmpty(..))
13−import Data.Maybe (catMaybes)
14−import Data.Monoid
15−import qualified Data.Text as T
16−import Database.Bloodhound.Types
17−import Database.Bloodhound.Types.Class ()
18−import Prelude hiding (filter)
19−
20−instance Monoid Filter where
21− mempty = IdentityFilter
22− mappend a b = AndFilter [a, b] defaultCache
23−
24−instance Seminearring Filter where
25− a <||> b = OrFilter [a, b] defaultCache
26−
27−instance ToJSON Filter where
28− toJSON (AndFilter filters cache) =
29− object ["and" .= fmap toJSON filters
30− , "_cache" .= cache]
31−
32− toJSON (OrFilter filters cache) =
33− object ["or" .= fmap toJSON filters
34− , "_cache" .= cache]
35−
36− toJSON (NotFilter filter cache) =
37− object ["not" .=
38− object ["filter" .= toJSON filter
39− , "_cache" .= cache]]
40−
41− toJSON (IdentityFilter) =
42− object ["match_all" .= object []]
43−
44− toJSON (TermFilter (Term termFilterField termFilterValue) cache) =
45− object ["term" .= object base]
46− where base = [termFilterField .= termFilterValue,
47− "_cache" .= cache]
48−
49− toJSON (ExistsFilter (FieldName fieldName)) =
50− object ["exists" .= object
51− ["field" .= fieldName]]
52−
53− toJSON (BoolFilter boolMatch) =
54− object ["bool" .= toJSON boolMatch]
55−
56− toJSON (GeoBoundingBoxFilter bbConstraint filterType) =
57− object ["geo_bounding_box" .= toJSON bbConstraint
58− , "type" .= toJSON filterType]
59−
60− toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
61− distance distanceType optimizeBbox cache) =
62− object ["geo_distance" .=
63− object ["distance" .= toJSON distance
64− , "distance_type" .= toJSON distanceType
65− , "optimize_bbox" .= optimizeBbox
66− , distanceGeoField .= toJSON geoDistLatLon
67− , "_cache" .= cache]]
68−
69− toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
70− (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
71− object ["geo_distance_range" .=
72− object ["from" .= toJSON geoDistRangeDistFrom
73− , "to" .= toJSON drDistanceTo
74− , gddrField .= toJSON drLatLon]]
75−
76− toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
77− object ["geo_polygon" .=
78− object [geoPolygonFilterField .=
79− object ["points" .= fmap toJSON latLons]]]
80−
81− toJSON (IdsFilter (MappingName mappingName) values) =
82− object ["ids" .=
83− object ["type" .= mappingName
84− , "values" .= fmap (T.pack . unpackId) values]]
85−
86− toJSON (LimitFilter limit) =
87− object ["limit" .= object ["value" .= limit]]
88−
89− toJSON (MissingFilter (FieldName fieldName) (Existence existence) (NullValue nullValue)) =
90− object ["missing" .=
91− object ["field" .= fieldName
92− , "existence" .= existence
93− , "null_value" .= nullValue]]
94−
95− toJSON (PrefixFilter (FieldName fieldName) fieldValue cache) =
96− object ["prefix" .=
97− object [fieldName .= fieldValue
98− , "_cache" .= cache]]
99−
100− toJSON (RangeFilter (FieldName fieldName) (Left halfRange) rangeExecution cache) =
101− object ["range" .=
102− object [fieldName .=
103− object [key .= val]
104− , "execution" .= toJSON rangeExecution
105− , "_cache" .= cache]]
106− where
107− (key, val) = halfRangeToKV halfRange
108−
109− toJSON (RangeFilter (FieldName fieldName) (Right range) rangeExecution cache) =
110− object ["range" .=
111− object [fieldName .=
112− object [lessKey .= lessVal
113− , greaterKey .= greaterVal]
114− , "execution" .= toJSON rangeExecution
115− , "_cache" .= cache]]
116− where
117− (lessKey, lessVal, greaterKey, greaterVal) = rangeToKV range
118−
119− toJSON (RegexpFilter (FieldName fieldName)
120− (Regexp regexText) flags (CacheName cacheName) cache (CacheKey cacheKey)) =
121− object ["regexp" .=
122− object [fieldName .=
123− object ["value" .= regexText
124− , "flags" .= toJSON flags]
125− , "_name" .= cacheName
126− , "_cache" .= cache
127− , "_cache_key" .= cacheKey]]
128−
129−instance ToJSON GeoPoint where
130− toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
131− object [ geoPointField .= toJSON geoPointLatLon ]
132−
133−
134−instance ToJSON Query where
135− toJSON (TermQuery (Term termQueryField termQueryValue) boost) =
136− object [ "term" .=
137− object [termQueryField .= object merged]]
138− where
139− base = [ "value" .= termQueryValue ]
140− boosted = maybe [] (return . ("boost" .=)) boost
141− merged = mappend base boosted
142−
143− toJSON (TermsQuery terms termsQueryMinimumMatch) =
144− object [ "terms" .= object conjoined ]
145− where conjoined =
146− [ "tags" .= fmap toJSON terms
147− , "minimum_should_match" .= toJSON termsQueryMinimumMatch ]
148−
149− toJSON (IdsQuery idsQueryMappingName docIds) =
150− object [ "ids" .= object conjoined ]
151− where conjoined = [ "type" .= toJSON idsQueryMappingName
152− , "values" .= fmap toJSON docIds ]
153−
154− toJSON (QueryQueryStringQuery qQueryStringQuery) =
155− object [ "query_string" .= toJSON qQueryStringQuery ]
156−
157− toJSON (QueryMatchQuery matchQuery) =
158− object [ "match" .= toJSON matchQuery ]
159−
160− toJSON (QueryMultiMatchQuery multiMatchQuery) =
161− object [ "multi_match" .= toJSON multiMatchQuery ]
162−
163− toJSON (QueryBoolQuery boolQuery) =
164− object [ "bool" .= toJSON boolQuery ]
165−
166− toJSON (QueryBoostingQuery boostingQuery) =
167− object [ "boosting" .= toJSON boostingQuery ]
168−
169− toJSON (QueryCommonTermsQuery commonTermsQuery) =
170− object [ "common" .= toJSON commonTermsQuery ]
171−
172− toJSON (ConstantScoreFilter filter boost) =
173− object [ "constant_score" .= toJSON filter
174− , "boost" .= toJSON boost]
175−
176− toJSON (ConstantScoreQuery query boost) =
177− object [ "constant_score" .= toJSON query
178− , "boost" .= toJSON boost]
179−
180− toJSON (QueryDisMaxQuery disMaxQuery) =
181− object [ "dis_max" .= toJSON disMaxQuery ]
182−
183− toJSON (QueryFilteredQuery qFilteredQuery) =
184− object [ "filtered" .= toJSON qFilteredQuery ]
185−
186− toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
187− object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
188−
189− toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
190− object [ "fuzzy_like_this_field" .= toJSON fuzzyFieldQuery ]
191−
192− toJSON (QueryFuzzyQuery fuzzyQuery) =
193− object [ "fuzzy" .= toJSON fuzzyQuery ]
194−
195− toJSON (QueryHasChildQuery childQuery) =
196− object [ "has_child" .= toJSON childQuery ]
197−
198− toJSON (QueryHasParentQuery parentQuery) =
199− object [ "has_parent" .= toJSON parentQuery ]
200−
201− toJSON (QueryIndicesQuery qIndicesQuery) =
202− object [ "indices" .= toJSON qIndicesQuery ]
203−
204− toJSON (MatchAllQuery boost) =
205− object [ "match_all" .= object maybeAdd ]
206− where maybeAdd = catMaybes [ mField "boost" boost ]
207−
208− toJSON (QueryMoreLikeThisQuery query) =
209− object [ "more_like_this" .= toJSON query ]
210−
211− toJSON (QueryMoreLikeThisFieldQuery query) =
212− object [ "more_like_this_field" .= toJSON query ]
213−
214− toJSON (QueryNestedQuery query) =
215− object [ "nested" .= toJSON query ]
216−
217− toJSON (QueryPrefixQuery query) =
218− object [ "prefix" .= toJSON query ]
219−
220− toJSON (QueryRangeQuery query) =
221− object [ "range" .= toJSON query ]
222−
223− toJSON (QueryRegexpQuery query) =
224− object [ "regexp" .= toJSON query ]
225−
226− toJSON (QuerySimpleQueryStringQuery query) =
227− object [ "simple_query_string" .= toJSON query ]
228−
229−
230−mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
231−mField field = fmap ((field .=) . toJSON)
232−
233−instance ToJSON SimpleQueryStringQuery where
234− toJSON (SimpleQueryStringQuery sqsQueryString
235− sqsFields sqsBoolean sqsAnalyzer
236− sqsFlags sqsLowercaseExpanded sqsLocale) =
237− object conjoined
238− where base = [ "query" .= toJSON sqsQueryString ]
239− maybeAdd =
240− catMaybes [ mField "fields" sqsFields
241− , mField "default_operator" sqsBoolean
242− , mField "analyzer" sqsAnalyzer
243− , mField "flags" sqsFlags
244− , mField "lowercase_expanded_terms" sqsLowercaseExpanded
245− , mField "locale" sqsLocale ]
246− conjoined = base ++ maybeAdd
247−
248−instance ToJSON FieldOrFields where
249− toJSON (FofField fieldName) =
250− toJSON fieldName
251− toJSON (FofFields fieldNames) =
252− toJSON fieldNames
253−
254−instance ToJSON SimpleQueryFlag where
255− toJSON SimpleQueryAll = "ALL"
256− toJSON SimpleQueryNone = "NONE"
257− toJSON SimpleQueryAnd = "AND"
258− toJSON SimpleQueryOr = "OR"
259− toJSON SimpleQueryPrefix = "PREFIX"
260− toJSON SimpleQueryPhrase = "PHRASE"
261− toJSON SimpleQueryPrecedence = "PRECEDENCE"
262− toJSON SimpleQueryEscape = "ESCAPE"
263− toJSON SimpleQueryWhitespace = "WHITESPACE"
264− toJSON SimpleQueryFuzzy = "FUZZY"
265− toJSON SimpleQueryNear = "NEAR"
266− toJSON SimpleQuerySlop = "SLOP"
267−
268−instance ToJSON RegexpQuery where
269− toJSON (RegexpQuery (FieldName rqQueryField)
270− (Regexp regexpQueryQuery) rqQueryFlags
271− rqQueryBoost) =
272− object [ rqQueryField .= object conjoined ]
273− where base = [ "value" .= regexpQueryQuery
274− , "flags" .= toJSON rqQueryFlags ]
275− maybeAdd = catMaybes [ mField "boost" rqQueryBoost ]
276− conjoined = base ++ maybeAdd
277−
278−instance ToJSON QueryStringQuery where
279− toJSON (QueryStringQuery qsQueryString
280− qsDefaultField qsOperator
281− qsAnalyzer qsAllowWildcard
282− qsLowercaseExpanded qsEnablePositionIncrements
283− qsFuzzyMaxExpansions qsFuzziness
284− qsFuzzyPrefixLength qsPhraseSlop
285− qsBoost qsAnalyzeWildcard
286− qsGeneratePhraseQueries qsMinimumShouldMatch
287− qsLenient qsLocale) =
288− object conjoined
289− where
290− base = [ "query" .= toJSON qsQueryString ]
291− maybeAdd =
292− catMaybes [ mField "default_field" qsDefaultField
293− , mField "default_operator" qsOperator
294− , mField "analyzer" qsAnalyzer
295− , mField "allow_leading_wildcard" qsAllowWildcard
296− , mField "lowercase_expanded_terms" qsLowercaseExpanded
297− , mField "enable_position_increments" qsEnablePositionIncrements
298− , mField "fuzzy_max_expansions" qsFuzzyMaxExpansions
299− , mField "fuzziness" qsFuzziness
300− , mField "fuzzy_prefix_length" qsFuzzyPrefixLength
301− , mField "phrase_slop" qsPhraseSlop
302− , mField "boost" qsBoost
303− , mField "analyze_wildcard" qsAnalyzeWildcard
304− , mField "auto_generate_phrase_queries" qsGeneratePhraseQueries
305− , mField "minimum_should_match" qsMinimumShouldMatch
306− , mField "lenient" qsLenient
307− , mField "locale" qsLocale ]
308− conjoined = base ++ maybeAdd
309−
310−instance ToJSON RangeQuery where
311− toJSON (RangeQuery (FieldName fieldName) (Right range) boost) =
312− object [ fieldName .= conjoined ]
313− where conjoined = [ "boost" .= toJSON boost
314− , lessKey .= lessVal
315− , greaterKey .= greaterVal ]
316− (lessKey, lessVal, greaterKey, greaterVal) = rangeToKV range
317−
318− toJSON (RangeQuery (FieldName fieldName) (Left halfRange) boost) =
319− object [ fieldName .= conjoined ]
320− where conjoined = [ "boost" .= toJSON boost
321− , key .= val ]
322− (key, val) = halfRangeToKV halfRange
323−
324−instance ToJSON PrefixQuery where
325− toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
326− object [ fieldName .= object conjoined ]
327− where base = [ "value" .= toJSON queryValue ]
328− maybeAdd = catMaybes [ mField "boost" boost ]
329− conjoined = base ++ maybeAdd
330−
331−
332−instance ToJSON NestedQuery where
333− toJSON (NestedQuery path scoreType query) =
334− object [ "path" .= toJSON path
335− , "score_mode" .= toJSON scoreType
336− , "query" .= toJSON query ]
337−
338−
339−instance ToJSON MoreLikeThisFieldQuery where
340− toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
341− percent mtf mqt stopwords mindf maxdf
342− minwl maxwl boostTerms boost analyzer) =
343− object [ fieldName .= object conjoined ]
344− where base = [ "like_text" .= toJSON text ]
345− maybeAdd = catMaybes [ mField "percent_terms_to_match" percent
346− , mField "min_term_freq" mtf
347− , mField "max_query_terms" mqt
348− , mField "stop_words" stopwords
349− , mField "min_doc_freq" mindf
350− , mField "max_doc_freq" maxdf
351− , mField "min_word_length" minwl
352− , mField "max_word_length" maxwl
353− , mField "boost_terms" boostTerms
354− , mField "boost" boost
355− , mField "analyzer" analyzer ]
356− conjoined = base ++ maybeAdd
357−
358−
359−instance ToJSON MoreLikeThisQuery where
360− toJSON (MoreLikeThisQuery text fields percent
361− mtf mqt stopwords mindf maxdf
362− minwl maxwl boostTerms boost analyzer) =
363− object conjoined
364− where base = [ "like_text" .= toJSON text ]
365− maybeAdd = catMaybes [ mField "fields" fields
366− , mField "percent_terms_to_match" percent
367− , mField "min_term_freq" mtf
368− , mField "max_query_terms" mqt
369− , mField "stop_words" stopwords
370− , mField "min_doc_freq" mindf
371− , mField "max_doc_freq" maxdf
372− , mField "min_word_length" minwl
373− , mField "max_word_length" maxwl
374− , mField "boost_terms" boostTerms
375− , mField "boost" boost
376− , mField "analyzer" analyzer ]
377− conjoined = base ++ maybeAdd
378−
379−
380−instance ToJSON IndicesQuery where
381− toJSON (IndicesQuery indices query noMatch) =
382− object $ [ "indices" .= toJSON indices
383− , "query" .= toJSON query ] ++ maybeAdd
384− where maybeAdd = catMaybes [ mField "no_match_query" noMatch ]
385−
386−
387−instance ToJSON HasParentQuery where
388− toJSON (HasParentQuery queryType query scoreType) =
389− object $ [ "parent_type" .= toJSON queryType
390− , "query" .= toJSON query ] ++ maybeAdd
391− where maybeAdd = catMaybes [ mField "score_type" scoreType ]
392−
393−
394−instance ToJSON HasChildQuery where
395− toJSON (HasChildQuery queryType query scoreType) =
396− object $ [ "query" .= toJSON query
397− , "type" .= toJSON queryType ] ++ maybeAdd
398− where maybeAdd = catMaybes [ mField "score_type" scoreType ]
399−
400−
401−instance ToJSON FuzzyQuery where
402− toJSON (FuzzyQuery (FieldName fieldName) queryText
403− prefixLength maxEx fuzziness boost) =
404− object [ fieldName .= object conjoined ]
405− where base = [ "value" .= toJSON queryText
406− , "fuzziness" .= toJSON fuzziness
407− , "prefix_length" .= toJSON prefixLength
408− , "max_expansions" .= toJSON maxEx ]
409− maybeAdd = catMaybes [ mField "boost" boost ]
410− conjoined = base ++ maybeAdd
411−
412−
413−instance ToJSON FuzzyLikeFieldQuery where
414− toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
415− fieldText maxTerms ignoreFreq fuzziness prefixLength
416− boost analyzer) =
417− object $ [ fieldName .=
418− object [ "like_text" .= toJSON fieldText
419− , "max_query_terms" .= toJSON maxTerms
420− , "ignore_tf" .= toJSON ignoreFreq
421− , "fuzziness" .= toJSON fuzziness
422− , "prefix_length" .= toJSON prefixLength
423− , "boost" .= toJSON boost ]] ++ maybeAdd
424− where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
425−
426−
427−instance ToJSON FuzzyLikeThisQuery where
428− toJSON (FuzzyLikeThisQuery fields text maxTerms
429− ignoreFreq fuzziness prefixLength boost analyzer) =
430− object conjoined
431− where base = [ "fields" .= toJSON fields
432− , "like_text" .= toJSON text
433− , "max_query_terms" .= toJSON maxTerms
434− , "ignore_tf" .= toJSON ignoreFreq
435− , "fuzziness" .= toJSON fuzziness
436− , "prefix_length" .= toJSON prefixLength
437− , "boost" .= toJSON boost ]
438− maybeAdd = catMaybes [ mField "analyzer" analyzer ]
439− conjoined = base ++ maybeAdd
440−
441−
442−instance ToJSON FilteredQuery where
443− toJSON (FilteredQuery query filter) =
444− object [ "query" .= toJSON query
445− , "filter" .= toJSON filter ]
446−
447−
448−instance ToJSON DisMaxQuery where
449− toJSON (DisMaxQuery queries tiebreaker boost) =
450− object conjoined
451− where maybeAdd = catMaybes [mField "boost" boost]
452− base = [ "queries" .= toJSON queries
453− , "tie_breaker" .= toJSON tiebreaker ]
454− conjoined = base ++ maybeAdd
455−
456−
457−instance ToJSON CommonTermsQuery where
458− toJSON (CommonTermsQuery (FieldName fieldName)
459− (QueryString query) cf lfo hfo msm
460− boost analyzer disableCoord) =
461− object [fieldName .= object conjoined]
462− where base = [ "query" .= query
463− , "cutoff_frequency" .= toJSON cf
464− , "low_freq_operator" .= toJSON lfo
465− , "high_freq_operator" .= toJSON hfo ]
466− extension = catMaybes
467− [ mField "minimum_should_match" msm
468− , mField "boost" boost
469− , mField "analyzer" analyzer
470− , mField "disable_coord" disableCoord ]
471− conjoined = base ++ extension
472−
473−
474−instance ToJSON CommonMinimumMatch where
475− toJSON (CommonMinimumMatch mm) = toJSON mm
476− toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
477− object [ "low_freq" .= toJSON lowF
478− , "high_freq" .= toJSON highF ]
479−
480−instance ToJSON BoostingQuery where
481− toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
482− object [ "positive" .= toJSON bqPositiveQuery
483− , "negative" .= toJSON bqNegativeQuery
484− , "negative_boost" .= toJSON bqNegativeBoost ]
485−
486−
487−instance ToJSON BoolQuery where
488− toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
489− object filtered
490− where filtered = catMaybes
491− [ mField "must" mustM
492− , mField "must_not" notM
493− , mField "should" shouldM
494− , mField "minimum_should_match" bqMin
495− , mField "boost" boost
496− , mField "disable_coord" disableCoord ]
497−
498−
499−instance ToJSON MatchQuery where
500− toJSON (MatchQuery (FieldName fieldName)
501− (QueryString queryString) booleanOperator
502− zeroTermsQuery cutoffFrequency matchQueryType
503− analyzer maxExpansions lenient) =
504− object [ fieldName .= object conjoined ]
505− where conjoined = [ "query" .= queryString
506− , "operator" .= toJSON booleanOperator
507− , "zero_terms_query" .= toJSON zeroTermsQuery]
508− ++ maybeAdd
509− maybeAdd = catMaybes [ mField "cutoff_frequency" cutoffFrequency
510− , mField "type" matchQueryType
511− , mField "analyzer" analyzer
512− , mField "max_expansions" maxExpansions
513− , mField "lenient" lenient ]
514−
515−
516−instance ToJSON MultiMatchQuery where
517− toJSON (MultiMatchQuery fields (QueryString query) boolOp
518− ztQ tb mmqt cf analyzer maxEx lenient) =
519− object ["multi_match" .= object conjoined]
520− where baseQuery = [ "fields" .= fmap toJSON fields
521− , "query" .= query
522− , "operator" .= toJSON boolOp
523− , "zero_terms_query" .= toJSON ztQ ]
524− maybeAdd = catMaybes [ mField "tiebreaker" tb
525− , mField "type" mmqt
526− , mField "cutoff_frequency" cf
527− , mField "analyzer" analyzer
528− , mField "max_expansions" maxEx
529− , mField "lenient" lenient ]
530− conjoined = baseQuery ++ maybeAdd
531−
532−
533−instance ToJSON MultiMatchQueryType where
534− toJSON MultiMatchBestFields = "best_fields"
535− toJSON MultiMatchMostFields = "most_fields"
536− toJSON MultiMatchCrossFields = "cross_fields"
537− toJSON MultiMatchPhrase = "phrase"
538− toJSON MultiMatchPhrasePrefix = "phrase_prefix"
539−
540−instance ToJSON BooleanOperator where
541− toJSON And = String "and"
542− toJSON Or = String "or"
543−
544−instance ToJSON ZeroTermsQuery where
545− toJSON ZeroTermsNone = String "none"
546− toJSON ZeroTermsAll = String "all"
547−
548−instance ToJSON MatchQueryType where
549− toJSON MatchPhrase = "phrase"
550− toJSON MatchPhrasePrefix = "phrase_prefix"
551−
552−instance ToJSON FieldName where
553− toJSON (FieldName fieldName) = String fieldName
554−
555−instance ToJSON ReplicaCount
556−instance ToJSON ShardCount
557−instance ToJSON CutoffFrequency
558−instance ToJSON Analyzer
559−instance ToJSON MaxExpansions
560−instance ToJSON Lenient
561−instance ToJSON Boost
562−instance ToJSON Version
563−instance ToJSON Tiebreaker
564−instance ToJSON MinimumMatch
565−instance ToJSON DisableCoord
566−instance ToJSON PrefixLength
567−instance ToJSON Fuzziness
568−instance ToJSON IgnoreTermFrequency
569−instance ToJSON MaxQueryTerms
570−instance ToJSON TypeName
571−instance ToJSON IndexName
572−instance ToJSON BoostTerms
573−instance ToJSON MaxWordLength
574−instance ToJSON MinWordLength
575−instance ToJSON MaxDocFrequency
576−instance ToJSON MinDocFrequency
577−instance ToJSON PhraseSlop
578−instance ToJSON StopWord
579−instance ToJSON QueryPath
580−instance ToJSON MinimumTermFrequency
581−instance ToJSON PercentMatch
582−instance ToJSON MappingName
583−instance ToJSON DocId
584−instance ToJSON QueryString
585−instance ToJSON AllowLeadingWildcard
586−instance ToJSON LowercaseExpanded
587−instance ToJSON AnalyzeWildcard
588−instance ToJSON GeneratePhraseQueries
589−instance ToJSON Locale
590−instance ToJSON EnablePositionIncrements
591−instance FromJSON Version
592−instance FromJSON IndexName
593−instance FromJSON MappingName
594−instance FromJSON DocId
595−
596−
597−instance FromJSON Status where
598− parseJSON (Object v) = Status <$>
599− v .: "ok" <*>
600− v .: "status" <*>
601− v .: "name" <*>
602− v .: "version" <*>
603− v .: "tagline"
604− parseJSON _ = empty
605−
606−
607−instance ToJSON IndexSettings where
608− toJSON (IndexSettings s r) = object ["settings" .= object ["shards" .= s, "replicas" .= r]]
609−
610−
611−instance (FromJSON a) => FromJSON (EsResult a) where
612− parseJSON (Object v) = EsResult <$>
613− v .: "_index" <*>
614− v .: "_type" <*>
615− v .: "_id" <*>
616− v .: "_version" <*>
617− v .:? "found" <*>
618− v .: "_source"
619− parseJSON _ = empty
620−
621−
622−instance ToJSON Search where
623− toJSON (Search query filter sort sTrackSortScores sFrom sSize) =
624− object merged where
625− lQuery = maybeJson "query" query
626− lFilter = maybeJson "filter" filter
627− lSort = maybeJsonF "sort" sort
628− merged = mconcat [[ "from" .= sFrom
629− , "size" .= sSize
630− , "track_scores" .= sTrackSortScores]
631− , lQuery
632− , lFilter
633− , lSort]
634−
635−
636−instance ToJSON SortSpec where
637− toJSON (DefaultSortSpec
638− (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
639− dsSortMode dsMissingSort dsNestedFilter)) =
640− object [dsSortFieldName .= object merged] where
641− base = ["order" .= toJSON dsSortOrder
642− , "ignore_unmapped" .= dsIgnoreUnmapped]
643− lSortMode = maybeJson "mode" dsSortMode
644− lMissingSort = maybeJson "missing" dsMissingSort
645− lNestedFilter = maybeJson "nested_filter" dsNestedFilter
646− merged = mconcat [base, lSortMode, lMissingSort, lNestedFilter]
647−
648− toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
649− object [ "unit" .= toJSON units
650− , field .= toJSON gdsLatLon
651− , "order" .= toJSON gdsSortOrder ]
652−
653−
654−instance ToJSON SortOrder where
655− toJSON Ascending = String "asc"
656− toJSON Descending = String "desc"
657−
658−
659−instance ToJSON SortMode where
660− toJSON SortMin = String "min"
661− toJSON SortMax = String "max"
662− toJSON SortSum = String "sum"
663− toJSON SortAvg = String "avg"
664−
665−
666−instance ToJSON Missing where
667− toJSON LastMissing = String "_last"
668− toJSON FirstMissing = String "_first"
669− toJSON (CustomMissing txt) = String txt
670−
671−
672−instance ToJSON ScoreType where
673− toJSON ScoreTypeMax = "max"
674− toJSON ScoreTypeAvg = "avg"
675− toJSON ScoreTypeSum = "sum"
676− toJSON ScoreTypeNone = "none"
677−
678−
679−instance ToJSON Distance where
680− toJSON (Distance dCoefficient dUnit) =
681− String boltedTogether where
682− coefText = showText dCoefficient
683− (String unitText) = toJSON dUnit
684− boltedTogether = mappend coefText unitText
685−
686−
687−instance ToJSON DistanceUnit where
688− toJSON Miles = String "mi"
689− toJSON Yards = String "yd"
690− toJSON Feet = String "ft"
691− toJSON Inches = String "in"
692− toJSON Kilometers = String "km"
693− toJSON Meters = String "m"
694− toJSON Centimeters = String "cm"
695− toJSON Millimeters = String "mm"
696− toJSON NauticalMiles = String "nmi"
697−
698−
699−instance ToJSON DistanceType where
700− toJSON Arc = String "arc"
701− toJSON SloppyArc = String "sloppy_arc"
702− toJSON Plane = String "plane"
703−
704−
705−instance ToJSON OptimizeBbox where
706− toJSON NoOptimizeBbox = String "none"
707− toJSON (OptimizeGeoFilterType gft) = toJSON gft
708−
709−
710−instance ToJSON GeoBoundingBoxConstraint where
711− toJSON (GeoBoundingBoxConstraint
712− (FieldName gbbcGeoBBField) gbbcConstraintBox cache) =
713− object [gbbcGeoBBField .= toJSON gbbcConstraintBox
714− , "_cache" .= cache]
715−
716−
717−instance ToJSON GeoFilterType where
718− toJSON GeoFilterMemory = String "memory"
719− toJSON GeoFilterIndexed = String "indexed"
720−
721−
722−instance ToJSON GeoBoundingBox where
723− toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
724− object ["top_left" .= toJSON gbbTopLeft
725− , "bottom_right" .= toJSON gbbBottomRight]
726−
727−
728−instance ToJSON LatLon where
729− toJSON (LatLon lLat lLon) =
730− object ["lat" .= lLat
731− , "lon" .= lLon]
732−
733−
734−-- index for smaller ranges, fielddata for longer ranges
735−instance ToJSON RangeExecution where
736− toJSON RangeExecutionIndex = "index"
737− toJSON RangeExecutionFielddata = "fielddata"
738−
739−
740−instance ToJSON RegexpFlags where
741− toJSON AllRegexpFlags = String "ALL"
742− toJSON NoRegexpFlags = String "NONE"
743− toJSON (SomeRegexpFlags (h :| fs)) = String $ T.intercalate "|" flagStrs
744− where flagStrs = map flagStr . nub $ h:fs
745− flagStr AnyString = "ANYSTRING"
746− flagStr Automaton = "AUTOMATON"
747− flagStr Complement = "COMPLEMENT"
748− flagStr Empty = "EMPTY"
749− flagStr Intersection = "INTERSECTION"
750− flagStr Interval = "INTERVAL"
751−
752−instance ToJSON Term where
753− toJSON (Term field value) = object ["term" .= object
754− [field .= value]]
755−
756−
757−instance ToJSON BoolMatch where
758− toJSON (MustMatch term cache) = object ["must" .= toJSON term,
759− "_cache" .= cache]
760− toJSON (MustNotMatch term cache) = object ["must_not" .= toJSON term,
761− "_cache" .= cache]
762− toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
763− "_cache" .= cache]
764−
765−
766−instance (FromJSON a) => FromJSON (SearchResult a) where
767− parseJSON (Object v) = SearchResult <$>
768− v .: "took" <*>
769− v .: "timed_out" <*>
770− v .: "_shards" <*>
771− v .: "hits"
772− parseJSON _ = empty
773−
774−instance (FromJSON a) => FromJSON (SearchHits a) where
775− parseJSON (Object v) = SearchHits <$>
776− v .: "total" <*>
777− v .: "max_score" <*>
778− v .: "hits"
779− parseJSON _ = empty
780−
781−instance (FromJSON a) => FromJSON (Hit a) where
782− parseJSON (Object v) = Hit <$>
783− v .: "_index" <*>
784− v .: "_type" <*>
785− v .: "_id" <*>
786− v .: "_score" <*>
787− v .: "_source"
788− parseJSON _ = empty
789−
790−instance FromJSON ShardResult where
791− parseJSON (Object v) = ShardResult <$>
792− v .: "total" <*>
793− v .: "successful" <*>
794− v .: "failed"
795− parseJSON _ = empty
README.org+2
@@ -17,6 +17,8 @@ Search doesn't have to be hard. Let the dog do it.
17
17
18Elasticsearch >= 1.0 is recommended. Bloodhound mostly works with 0.9.x, but I don't recommend it if you expect everything to work.
18Elasticsearch >= 1.0 is recommended. Bloodhound mostly works with 0.9.x, but I don't recommend it if you expect everything to work.
19
19
20+Current version we test against is 1.0.1
21+
20** Stability
22** Stability
21
23
22Bloodhound is alpha at the moment. The library works fine, but I don't want to mislead anyone into thinking the API is final or stable. I wouldn't call the library "complete" or representative of everything you can do in Elasticsearch but compared to clients in other languages, the usability is good.
24Bloodhound is alpha at the moment. The library works fine, but I don't want to mislead anyone into thinking the API is final or stable. I wouldn't call the library "complete" or representative of everything you can do in Elasticsearch but compared to clients in other languages, the usability is good.
bloodhound.cabal+1−2
@@ -17,13 +17,12 @@ source-repository head
17 location: https://github.com/bitemyapp/bloodhound.git
17 location: https://github.com/bitemyapp/bloodhound.git
18
18
19library
19library
20− ghc-options: -Wall -fno-warn-orphans
20+ ghc-options: -Wall
21 default-extensions: OverloadedStrings
21 default-extensions: OverloadedStrings
22 exposed-modules: Database.Bloodhound
22 exposed-modules: Database.Bloodhound
23 Database.Bloodhound.Client
23 Database.Bloodhound.Client
24 Database.Bloodhound.Types
24 Database.Bloodhound.Types
25 Database.Bloodhound.Types.Class
25 Database.Bloodhound.Types.Class
26− Database.Bloodhound.Types.Instances
27 build-depends: base >= 4.3 && <5,
26 build-depends: base >= 4.3 && <5,
28 bytestring >= 0.10.2,
27 bytestring >= 0.10.2,
29 aeson >= 0.7,
28 aeson >= 0.7,
changelog+9−1
@@ -1,6 +1,14 @@
1** 0.2.x
1** 0.2.x
2+
3+0.2.0.0 --> 0.2.0.1
4+===================
5+
6+* Merged Types and Instances module into Types to prevent possibility of orphans and cull orphan instance warnings.
7+
8+* Added note about current supported Elasticsearch version.
9+
20.1.0.2 --> 0.2.0.0
100.1.0.2 --> 0.2.0.0
3−===============
11+===================
4
12
5* Added TermFilter
13* Added TermFilter
6
14