git.iko.soy/typeable/bloodhound
on master help sign in
Added ability to specify a parent document
32f4e2bJohn Galt
src/Database/Bloodhound/Client.hs+5−1
@@ -378,7 +378,7 @@ indexDocument (IndexName indexName)
378 (MappingName mappingName) cfg document (DocId docId) =
378 (MappingName mappingName) cfg document (DocId docId) =
379 bindM2 put url (return body)
379 bindM2 put url (return body)
380 where url = addQuery params <$> joinPath [indexName, mappingName, docId]
380 where url = addQuery params <$> joinPath [indexName, mappingName, docId]
381− params = case idsVersionControl cfg of
381+ versionCtlParams = case idsVersionControl cfg of
382 NoVersionControl -> []
382 NoVersionControl -> []
383 InternalVersion v -> versionParams v "internal"
383 InternalVersion v -> versionParams v "internal"
384 ExternalGT (ExternalDocVersion v) -> versionParams v "external_gt"
384 ExternalGT (ExternalDocVersion v) -> versionParams v "external_gt"
@@ -388,6 +388,10 @@ indexDocument (IndexName indexName)
388 versionParams v t = [ ("version", Just $ vt v)
388 versionParams v t = [ ("version", Just $ vt v)
389 , ("version_type", Just t)
389 , ("version_type", Just t)
390 ]
390 ]
391+ parentParams = case idsParent cfg of
392+ Nothing -> []
393+ Just (DocumentParent (DocId p)) -> [ ("parent", Just p) ]
394+ params = versionCtlParams ++ parentParams
391 body = Just (encode document)
395 body = Just (encode document)
392
396
393-- | 'deleteDocument' is the primary way to delete a single document.
397-- | 'deleteDocument' is the primary way to delete a single document.
src/Database/Bloodhound/Types.hs+11−5
@@ -63,6 +63,7 @@ module Database.Bloodhound.Types
63 , DocVersion
63 , DocVersion
64 , ExternalDocVersion(..)
64 , ExternalDocVersion(..)
65 , VersionControl(..)
65 , VersionControl(..)
66+ , DocumentParent(..)
66 , IndexDocumentSettings(..)
67 , IndexDocumentSettings(..)
67 , Query(..)
68 , Query(..)
68 , Search(..)
69 , Search(..)
@@ -457,18 +458,23 @@ data VersionControl = NoVersionControl
457 -- care, as this could result in data loss.
458 -- care, as this could result in data loss.
458 deriving (Show, Eq, Ord)
459 deriving (Show, Eq, Ord)
459
460
461+{-| 'DocumentParent' is used to specify a parent document.
462+-}
463+newtype DocumentParent = DocumentParent DocId
464+
460{-| 'IndexDocumentSettings' are special settings supplied when indexing
465{-| 'IndexDocumentSettings' are special settings supplied when indexing
461a document. For the best backwards compatiblity when new fields are
466a document. For the best backwards compatiblity when new fields are
462added, you should probably prefer to start with 'defaultIndexDocumentSettings'
467added, you should probably prefer to start with 'defaultIndexDocumentSettings'
463-}
468-}
464−data IndexDocumentSettings = IndexDocumentSettings {
469+data IndexDocumentSettings =
465− idsVersionControl :: VersionControl
470+ IndexDocumentSettings { idsVersionControl :: VersionControl
471+ , idsParent :: Maybe DocumentParent
466− }
472+ }
467
473
468−{-| Reasonable default settings. Chooses no version control.
474+{-| Reasonable default settings. Chooses no version control and no parent.
469-}
475-}
470defaultIndexDocumentSettings :: IndexDocumentSettings
476defaultIndexDocumentSettings :: IndexDocumentSettings
471−defaultIndexDocumentSettings = IndexDocumentSettings NoVersionControl
477+defaultIndexDocumentSettings = IndexDocumentSettings NoVersionControl Nothing
472
478
473{-| 'Sort' is a synonym for a list of 'SortSpec's. Sort behavior is order
479{-| 'Sort' is a synonym for a list of 'SortSpec's. Sort behavior is order
474 dependent with later sorts acting as tie-breakers for earlier sorts.
480 dependent with later sorts acting as tie-breakers for earlier sorts.