git.iko.soy/typeable/bloodhound
on master help sign in
Added ability to specify a parent document
commit32f4e2b114ce23fc0bad1f27f5d534c7f680d265 authorJohn Galt <centromere@users.noreply.github.com> dateTue 21 Jul 2015, 15:14 (11 years ago) parenta155e19
2 files changed+16−6
src/Database/Bloodhound/Client.hs+5−1 src/Database/Bloodhound/Types.hs+11−5
src/Database/Bloodhound/Client.hs+5−1
@@ -378,7 +378,7 @@ indexDocument (IndexName indexName)
378378 (MappingName mappingName) cfg document (DocId docId) =
379379 bindM2 put url (return body)
380380 where url = addQuery params <$> joinPath [indexName, mappingName, docId]
381− params = case idsVersionControl cfg of
381+ versionCtlParams = case idsVersionControl cfg of
382382 NoVersionControl -> []
383383 InternalVersion v -> versionParams v "internal"
384384 ExternalGT (ExternalDocVersion v) -> versionParams v "external_gt"
@@ -388,6 +388,10 @@ indexDocument (IndexName indexName)
388388 versionParams v t = [ ("version", Just $ vt v)
389389 , ("version_type", Just t)
390390 ]
391+ parentParams = case idsParent cfg of
392+ Nothing -> []
393+ Just (DocumentParent (DocId p)) -> [ ("parent", Just p) ]
394+ params = versionCtlParams ++ parentParams
391395 body = Just (encode document)
392396
393397-- | '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
6363 , DocVersion
6464 , ExternalDocVersion(..)
6565 , VersionControl(..)
66+ , DocumentParent(..)
6667 , IndexDocumentSettings(..)
6768 , Query(..)
6869 , Search(..)
@@ -457,18 +458,23 @@ data VersionControl = NoVersionControl
457458 -- care, as this could result in data loss.
458459 deriving (Show, Eq, Ord)
459460
461+{-| 'DocumentParent' is used to specify a parent document.
462+-}
463+newtype DocumentParent = DocumentParent DocId
464+
460465{-| 'IndexDocumentSettings' are special settings supplied when indexing
461466a document. For the best backwards compatiblity when new fields are
462467added, you should probably prefer to start with 'defaultIndexDocumentSettings'
463468-}
464−data IndexDocumentSettings = IndexDocumentSettings {
465− idsVersionControl :: VersionControl
466− }
469+data IndexDocumentSettings =
470+ IndexDocumentSettings { idsVersionControl :: VersionControl
471+ , idsParent :: Maybe DocumentParent
472+ }
467473
468−{-| Reasonable default settings. Chooses no version control.
474+{-| Reasonable default settings. Chooses no version control and no parent.
469475-}
470476defaultIndexDocumentSettings :: IndexDocumentSettings
471−defaultIndexDocumentSettings = IndexDocumentSettings NoVersionControl
477+defaultIndexDocumentSettings = IndexDocumentSettings NoVersionControl Nothing
472478
473479{-| 'Sort' is a synonym for a list of 'SortSpec's. Sort behavior is order
474480 dependent with later sorts acting as tie-breakers for earlier sorts.