Skip to content

Commit 42eb3bf

Browse files
committed
Release 1.224.2025
1 parent 3acb68b commit 42eb3bf

11 files changed

Lines changed: 359 additions & 578 deletions

Functions/GenXdev.AI.Queries/Export-ImageIndex.ps1

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ indexcachedimages
184184
function Export-ImageIndex {
185185

186186
[CmdletBinding()]
187+
[OutputType([GenXdev.Helpers.ImageSearchResult[]], [GenXdev.Helpers.ImageSearchResult])]
187188
[Alias('indeximages')]
188189

189190
param(
@@ -637,7 +638,7 @@ function Export-ImageIndex {
637638
) -CreateDirectory -DeleteExistingFile -ErrorAction SilentlyContinue
638639

639640
# define backup file path for database
640-
$DatabaseBackupFilePath = "${DatabaseFilePath}.backup.db"
641+
$DatabaseBackupFilePath = GenXdev.FileSystem\Expand-Path "${DatabaseFilePath}.backup.db" -DeleteExistingFile -CreateDirectory
641642

642643
# check if the database file exists after expansion and handle backup
643644
if ([IO.File]::Exists($DatabaseFilePath)) {
@@ -1109,19 +1110,20 @@ CREATE INDEX IF NOT EXISTS idx_images_scene_confidence_range ON Images(scene_con
11091110
# set found results to true when images are found
11101111
$Info.FoundResults = $true
11111112

1112-
# copy identical parameter values for Find-Image function call
1113-
$findImageParams = GenXdev.Helpers\Copy-IdenticalParamValues `
1113+
1114+
# set image directories for Find-Image from configured sources
1115+
$imageCollectionParams = GenXdev.Helpers\Copy-IdenticalParamValues `
11141116
-BoundParameters $PSBoundParameters `
1115-
-FunctionName 'GenXdev.AI\Find-Image' `
1117+
-FunctionName 'GenXdev.AI\Get-AIImageCollection' `
11161118
-DefaultValues (
11171119
Microsoft.PowerShell.Utility\Get-Variable -Scope Local `
11181120
-ErrorAction SilentlyContinue
11191121
)
11201122

1121-
# set image directories for Find-Image from configured sources
1122-
$imageCollectionParams = GenXdev.Helpers\Copy-IdenticalParamValues `
1123+
# copy identical parameter values for Find-Image function call
1124+
$findImageParams = GenXdev.Helpers\Copy-IdenticalParamValues `
11231125
-BoundParameters $PSBoundParameters `
1124-
-FunctionName 'GenXdev.AI\Get-AIImageCollection' `
1126+
-FunctionName 'GenXdev.AI\Find-Image' `
11251127
-DefaultValues (
11261128
Microsoft.PowerShell.Utility\Get-Variable -Scope Local `
11271129
-ErrorAction SilentlyContinue
@@ -1140,22 +1142,18 @@ CREATE INDEX IF NOT EXISTS idx_images_scene_confidence_range ON Images(scene_con
11401142

11411143
# define internal function to insert a single image into database
11421144
function insertImage {
1143-
param($image, $Info)
1145+
param([GenXdev.Helpers.ImageSearchResult] $image, $Info)
11441146

11451147
process {
11461148

1149+
11471150
# clear previous lookup data for this image
11481151
$lookupQueries.Clear()
11491152
$lookupParams.Clear()
11501153
$Info.FoundResults = $true
11511154

11521155
try {
11531156

1154-
# convert image object to json and back for deep copy to prevent modification
1155-
$image = $image |
1156-
Microsoft.PowerShell.Utility\ConvertTo-Json -Depth 20 |
1157-
Microsoft.PowerShell.Utility\ConvertFrom-Json
1158-
11591157
$Info.TotalImages++
11601158

11611159
# build parameters for main image record insert with null checks
@@ -1429,9 +1427,9 @@ CREATE INDEX IF NOT EXISTS idx_images_scene_confidence_range ON Images(scene_con
14291427
$lookupParams.Clear()
14301428

14311429
# insert keywords if present for searchable metadata
1432-
if ($image.keywords -and $image.keywords.Count -gt 0) {
1430+
if ($image.description -and $image.description.keywords -and $image.description.keywords.Count -gt 0) {
14331431

1434-
foreach ($keyword in $image.keywords) {
1432+
foreach ($keyword in $image.description.keywords) {
14351433

14361434
$lookupQueries.Add(
14371435
('INSERT INTO ImageKeywords (image_id, ' +
@@ -1573,8 +1571,13 @@ CREATE INDEX IF NOT EXISTS idx_images_scene_confidence_range ON Images(scene_con
15731571
$InputObject |
15741572
Microsoft.PowerShell.Core\ForEach-Object {
15751573

1576-
$Info.FoundResults = $true
1577-
insertImage $PSItem $Info
1574+
try {
1575+
insertImage $PSItem $Info
1576+
$Info.FoundResults = $true
1577+
}
1578+
catch {
1579+
Microsoft.PowerShell.Utility\Write-Verbose "[Export-ImageIndex] Exception: $($_.Exception.Message)"
1580+
}
15781581
}
15791582
}
15801583
else {
@@ -1583,8 +1586,13 @@ CREATE INDEX IF NOT EXISTS idx_images_scene_confidence_range ON Images(scene_con
15831586
GenXdev.AI\Find-Image @findImageParams |
15841587
Microsoft.PowerShell.Core\ForEach-Object {
15851588

1586-
$Info.FoundResults = $true
1587-
insertImage $PSItem $Info
1589+
try {
1590+
insertImage $PSItem $Info
1591+
$Info.FoundResults = $true
1592+
}
1593+
catch {
1594+
Microsoft.PowerShell.Utility\Write-Verbose "[Export-ImageIndex] Exception: $($_.Exception.Message)"
1595+
}
15881596
}
15891597
}
15901598
}
@@ -1622,15 +1630,13 @@ CREATE INDEX IF NOT EXISTS idx_images_scene_confidence_range ON Images(scene_con
16221630

16231631
}
16241632
catch {
1625-
16261633
# rollback on error to maintain database integrity
16271634
$transaction.Rollback()
1628-
16291635
Microsoft.PowerShell.Utility\Write-Verbose (
16301636
'Transaction rolled back due to error: ' +
16311637
"$($_.Exception.Message)"
16321638
)
1633-
1639+
Microsoft.PowerShell.Utility\Write-Verbose "[Export-ImageIndex] Exception: $($_.Exception.Message)"
16341640
throw $_
16351641
}
16361642

0 commit comments

Comments
 (0)