Skip to content

Commit

Permalink
Add the author's group field into the Monocle schema
Browse files Browse the repository at this point in the history
  • Loading branch information
morucci committed Nov 28, 2023
1 parent b6f17ff commit e213766
Showing 1 changed file with 113 additions and 103 deletions.
216 changes: 113 additions & 103 deletions src/Monocle/Backend/Index.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ instance ToJSON AuthorMapping where
object
[ "uid" .= object ["type" .= ("keyword" :: Text)]
, "muid" .= object ["type" .= ("keyword" :: Text)]
, "groups" .= object ["type" .= ("keyword" :: Text)]
]

instance ToJSON AuthorIndexMapping where
Expand Down Expand Up @@ -121,109 +122,111 @@ data BoolMapping = BoolMapping deriving (Eq, Show)
instance ToJSON BoolMapping where
toJSON BoolMapping = object ["type" .= ("boolean" :: Text)]

schema :: Value
schema =
object [ "properties"
.= object
( [ "id" .= KWMapping
, "type" .= KWMapping
, "number" .= KWMapping
, "change_id" .= KWMapping
, "title" .= TextAndKWMapping
, "text" .= TextAndKWMapping
, "url" .= KWMapping
, "commit_count" .= IntegerMapping
, "additions" .= IntegerMapping
, "deletions" .= IntegerMapping
, "change_files_count" .= IntegerMapping
, "changed_files"
.= object
[ "properties"
.= object
[ "additions" .= IntegerMapping
, "deletions" .= IntegerMapping
, "path" .= KWMapping
]
]
, "commits"
.= object
[ "properties"
.= object
[ "sha" .= KWMapping
, "author" .= AuthorIndexMapping
, "committer" .= AuthorIndexMapping
, "authored_at" .= DateIndexMapping
, "committed_at" .= DateIndexMapping
, "additions" .= IntegerMapping
, "deletions" .= IntegerMapping
, "title" .= object ["type" .= ("text" :: Text)]
]
]
, "repository_prefix" .= KWMapping
, "repository_fullname" .= KWMapping
, "repository_shortname" .= KWMapping
, "author" .= AuthorIndexMapping
, "on_author" .= AuthorIndexMapping
, "committer" .= AuthorIndexMapping
, "merged_by" .= AuthorIndexMapping
, "branch" .= KWMapping
, "target_branch" .= KWMapping
, "created_at" .= DateIndexMapping
, "on_created_at" .= DateIndexMapping
, "merged_at" .= DateIndexMapping
, "updated_at" .= DateIndexMapping
, "closed_at" .= DateIndexMapping
, "state" .= KWMapping
, "duration" .= IntegerMapping
, "mergeable" .= KWMapping
, "labels" .= KWMapping
, "assignees"
.= object
[ "type" .= ("nested" :: Text)
, "properties" .= AuthorMapping
]
, "approval" .= KWMapping
, "draft" .= BoolMapping
, "self_merged" .= BoolMapping
, "crawler_metadata"
.= object
[ "properties"
.= object
[ "crawler_name" .= KWMapping
, "crawler_type" .= KWMapping
, "crawler_type_value" .= KWMapping
, "last_commit_at" .= DateIndexMapping
, "last_post_at" .= DateIndexMapping
, "total_docs_posted" .= IntegerMapping
, "total_changes_updated" .= IntegerMapping
, "total_change_events_updated" .= IntegerMapping
, "total_orphans_updated" .= IntegerMapping
]
]
, "tasks_data"
.= object
[ "properties"
.= object
[ "tid" .= KWMapping
, "ttype" .= KWMapping
, "crawler_name" .= KWMapping
, "updated_at" .= DateIndexMapping
, "change_url" .= KWMapping
, "severity" .= KWMapping
, "priority" .= KWMapping
, "score" .= IntegerMapping
, "url" .= KWMapping
, "prefix" .= KWMapping
, "title" .= TextAndKWMapping
, "_adopted" .= BoolMapping
]
]
]
<> cachedAuthorField
<> mergedCommitField
)
]

instance ToJSON ChangesIndexMapping where
toJSON ChangesIndexMapping =
object
[ "properties"
.= object
( [ "id" .= KWMapping
, "type" .= KWMapping
, "number" .= KWMapping
, "change_id" .= KWMapping
, "title" .= TextAndKWMapping
, "text" .= TextAndKWMapping
, "url" .= KWMapping
, "commit_count" .= IntegerMapping
, "additions" .= IntegerMapping
, "deletions" .= IntegerMapping
, "change_files_count" .= IntegerMapping
, "changed_files"
.= object
[ "properties"
.= object
[ "additions" .= IntegerMapping
, "deletions" .= IntegerMapping
, "path" .= KWMapping
]
]
, "commits"
.= object
[ "properties"
.= object
[ "sha" .= KWMapping
, "author" .= AuthorIndexMapping
, "committer" .= AuthorIndexMapping
, "authored_at" .= DateIndexMapping
, "committed_at" .= DateIndexMapping
, "additions" .= IntegerMapping
, "deletions" .= IntegerMapping
, "title" .= object ["type" .= ("text" :: Text)]
]
]
, "repository_prefix" .= KWMapping
, "repository_fullname" .= KWMapping
, "repository_shortname" .= KWMapping
, "author" .= AuthorIndexMapping
, "on_author" .= AuthorIndexMapping
, "committer" .= AuthorIndexMapping
, "merged_by" .= AuthorIndexMapping
, "branch" .= KWMapping
, "target_branch" .= KWMapping
, "created_at" .= DateIndexMapping
, "on_created_at" .= DateIndexMapping
, "merged_at" .= DateIndexMapping
, "updated_at" .= DateIndexMapping
, "closed_at" .= DateIndexMapping
, "state" .= KWMapping
, "duration" .= IntegerMapping
, "mergeable" .= KWMapping
, "labels" .= KWMapping
, "assignees"
.= object
[ "type" .= ("nested" :: Text)
, "properties" .= AuthorMapping
]
, "approval" .= KWMapping
, "draft" .= BoolMapping
, "self_merged" .= BoolMapping
, "crawler_metadata"
.= object
[ "properties"
.= object
[ "crawler_name" .= KWMapping
, "crawler_type" .= KWMapping
, "crawler_type_value" .= KWMapping
, "last_commit_at" .= DateIndexMapping
, "last_post_at" .= DateIndexMapping
, "total_docs_posted" .= IntegerMapping
, "total_changes_updated" .= IntegerMapping
, "total_change_events_updated" .= IntegerMapping
, "total_orphans_updated" .= IntegerMapping
]
]
, "tasks_data"
.= object
[ "properties"
.= object
[ "tid" .= KWMapping
, "ttype" .= KWMapping
, "crawler_name" .= KWMapping
, "updated_at" .= DateIndexMapping
, "change_url" .= KWMapping
, "severity" .= KWMapping
, "priority" .= KWMapping
, "score" .= IntegerMapping
, "url" .= KWMapping
, "prefix" .= KWMapping
, "title" .= TextAndKWMapping
, "_adopted" .= BoolMapping
]
]
]
<> cachedAuthorField
<> mergedCommitField
)
]
toJSON ChangesIndexMapping = schema

createIndex :: (IndexEffects es, Retry :> es, ToJSON mapping) => BH.IndexName -> mapping -> Eff es ()
createIndex indexName mapping = do
Expand All @@ -240,7 +243,7 @@ createIndex indexName mapping = do
retryPolicy = exponentialBackoff 500_000 <> limitRetries 7

configVersion :: ConfigVersion
configVersion = ConfigVersion 5
configVersion = ConfigVersion 6

configIndex :: BH.IndexName
configIndex = BH.IndexName "monocle.config"
Expand Down Expand Up @@ -373,13 +376,20 @@ upgradeConfigV5 = do
logInfo "Applying migration to schema V5 on workspace" ["index" .= indexName]
void $ esPutMapping indexName mergedCommitField

upgradeConfigV6 :: forall es. MonoQuery :> es => IndexEffects es => Eff es ()
upgradeConfigV6 = do
indexName <- getIndexName
logInfo "Applying migration to schema V6 on workspace" ["index" .= indexName]
void $ esPutMapping indexName ChangesIndexMapping

upgrades :: forall es. (E.Fail :> es, MonoQuery :> es) => IndexEffects es => [(ConfigVersion, Eff es ())]
upgrades =
[ (ConfigVersion 1, upgradeConfigV1)
, (ConfigVersion 2, upgradeConfigV2)
, (ConfigVersion 3, void upgradeConfigV3)
, (ConfigVersion 4, void upgradeConfigV4)
, (ConfigVersion 5, void upgradeConfigV5)
, (ConfigVersion 6, void upgradeConfigV6)
]

newtype ConfigVersion = ConfigVersion Integer
Expand Down

0 comments on commit e213766

Please sign in to comment.