diff --git a/Azure_DevOps_Server_2019/Re-IndexingCodeRepository.ps1 b/Azure_DevOps_Server_2019/Re-IndexingCodeRepository.ps1
index e701fef..0304c09 100644
--- a/Azure_DevOps_Server_2019/Re-IndexingCodeRepository.ps1
+++ b/Azure_DevOps_Server_2019/Re-IndexingCodeRepository.ps1
@@ -16,8 +16,11 @@ Param(
[string]$CollectionName,
[Parameter(Mandatory=$True, Position=5, HelpMessage="Update the tfvc/git repository name here.")]
- [string]$RepositoryName
-)
+ [string]$RepositoryName,
+
+ [Parameter(Mandatory=$False, Position=5, HelpMessage="Set the name for the project of the repository here if there are multiple repositories with the same name.")]
+ [string]$ProjectName=""
+ )
Import-Module .\Common.psm1 -Force
@@ -27,9 +30,13 @@ ImportSQLModule
$CollectionID = ValidateCollectionName $SQLServerInstance $ConfigurationDatabaseName $CollectionName
+if([string]::IsNullOrWhiteSpace($ProjectName)) {
+ $ProjectName = "" # make sure it's just an empty string if project name is null or whitespace
+}
+
if(IsExtensionInstalled $SQLServerInstance $CollectionDatabaseName "IsCollectionIndexed")
{
- $addDataParams = "IndexingUnitType='$IndexingUnitType'","CollectionId='$CollectionID'","RepositoryName='$RepositoryName'","RepositoryType='$IndexingUnitType'"
+ $addDataParams = "IndexingUnitType='$IndexingUnitType'","CollectionId='$CollectionID'","RepositoryName='$RepositoryName'","RepositoryType='$IndexingUnitType'","ProjectName='$ProjectName'"
$SqlFullPath = Join-Path $PWD -ChildPath 'SqlScripts\AddCodeRe-IndexingJobData.sql'
Invoke-Sqlcmd -InputFile $SqlFullPath -serverInstance $SQLServerInstance -database $CollectionDatabaseName -Variable $addDataParams
Write-Host "Added the job data as '$addDataParams'" -ForegroundColor Cyan
diff --git a/Azure_DevOps_Server_2019/SqlScripts/AddCodeRe-IndexingJobData.sql b/Azure_DevOps_Server_2019/SqlScripts/AddCodeRe-IndexingJobData.sql
index 6ca638c..834697c 100644
--- a/Azure_DevOps_Server_2019/SqlScripts/AddCodeRe-IndexingJobData.sql
+++ b/Azure_DevOps_Server_2019/SqlScripts/AddCodeRe-IndexingJobData.sql
@@ -16,13 +16,37 @@ DECLARE @RepositoryName nvarchar(max) = $(RepositoryName)
-- Update the type of repository, use 'Git_Repository' for git repos and 'TFVC_Repository' for TFVC projects.
DECLARE @RepositoryType varchar(30) = $(RepositoryType)
+-- **UPDATE**
+-- Set the name for the project of the repository here if there are multiple repositories with the same name, this can be any string.
+DECLARE @ProjectName nvarchar(max) = $(ProjectName)
+
DECLARE @CollectionId uniqueidentifier = $(CollectionId)
DECLARE @RepositoryId varchar(50)
if(@IndexingUnitType <> 'Collection')
BEGIN
- SELECT @RepositoryId = TFSEntityId from Search.tbl_IndexingUnit
- where TFSEntityAttributes Like '%'+@RepositoryName+'%' and IndexingUnitType Like '%Repository%'
- and PartitionId > 0
+ if(@ProjectName <> '')
+ BEGIN
+ SELECT @RepositoryId = TFSEntityId
+ from [Search].[tbl_IndexingUnit] siu
+ inner join [dbo].[tbl_GitRepository] grp
+ on siu.PartitionId = grp.PartitionId
+ and siu.TFSEntityId = grp.RepositoryId
+ and siu.EntityType = 'Code'
+ inner join [dbo].[tbl_Dataspace] dsp
+ on grp.PartitionId = dsp.PartitionId
+ and grp.DataspaceId = dsp.DataspaceId
+ inner join [dbo].[tbl_projects] prj
+ on dsp.PartitionId = prj.PartitionId
+ and dsp.[DataspaceIdentifier] = prj.[project_id]
+ where grp.Name = @RepositoryName and IndexingUnitType Like '%Repository%' and prj.project_Name = @ProjectName
+ and siu.PartitionId > 0
+ END
+ ELSE
+ BEGIN
+ SELECT @RepositoryId = TFSEntityId from Search.tbl_IndexingUnit
+ where TFSEntityAttributes Like '%'+@RepositoryName+'%' and IndexingUnitType Like '%Repository%'
+ and PartitionId > 0
+ END
if(@RepositoryId is null)
BEGIN