Whats wrong with my PS1 Script?

Started by RobiWan, July 21, 2024, 07:16:41 PM

Previous topic - Next topic

RobiWan

Hi,

I have some small scripts yet. They are working but, here a example

param(
    [Parameter(Mandatory = $true,Position = 0)][string]$Filename
)

$PAGE_SIZE = 5000
$server="localhost"
$port="50519"
$protokoll="http"
$URI="$($protokoll)://$($server):$($port)"
$fileNames = @(get-content $Filename)
$windowName = (gci "$fileName").BaseName
$Match=@()
$PAGE = 0
# Write-Host -Object "Login in WebService"
$authenticate = Invoke-RestMethod -Uri "$URI/v1/authenticate" -Method Post -Body @{'id' = $env:USERNAME; 'password' = ''; 'appid' = '' }
$auth_token = $authenticate.auth_token
# Write-Host -Object "Login with Token $($auth_token)"

while ($true) {
    $result=Invoke-RestMethod -Uri "$URI/v1/files" -Method GET -Body @{'page' = $PAGE; 'pagesize' = $PAGE_SIZE; 'fields' = 'id,filename';'auth_token' = $auth_token}
    foreach($file in $result.files){
        foreach($name in $fileNames){
            if($file.fileName.ToLower() -eq $name.ToLower()){
                $Match+=$file.ID
                break;
            }
        }
    }
    if($result.files.length -lt $PAGE_SIZE){break}
    $PAGE++
    # Write-Host -Object "Page $PAGE"
}

Invoke-RestMethod -Method Post -Uri "$URI/v1/imatch/resultwindow/open" -Body @{'name' = "$windowName"; 'id' = $($Match -join ",");'auth_token' = $auth_token}
   

& 'C:\Users\robert\ownCloud\PowerShell\Fotografie\IMatch\Collect Files from File.ps1' "C:\Temp\ohneBewertung.txt"

All works, but it needs much more time than IMatch APP "Dateisuche und dann Stapelsuche". Do I have an error in my script/procedure?

Carlo Didier

I think it would be much faster to let iMatch do the search for you instead of searching in a PS1 loop that runs tons web requests.

Here's an example from one of my scripts:

$arrImageParts = ((Invoke-WebRequest -Uri "$webIMatch/search/filename?auth_token=&scope=database&pattern=^$strImageName\.&sortby=filename-Asc").Content | convertfrom-json).files

That's very fast.
Imatch is a databse and the most efficient and fastest way to do searches is always to use the internal engine of the database.




RobiWan

Is it possible that it can only work if only filename ( $strImageName ) without path is passed?


Mario

This is a regular expression. Keep the special meaning of characters like \ in mind wne you include the path in the pattern. See Escaping
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

RobiWan

#4
I thing we're talking past each other

Works
$strImageName = "pict0980"
$arrImageParts = ((Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=^$strImageName\.&sortby=filename-Asc").Content | convertfrom-json).files

Not working
$strImageName = "pict0980.mrw"
$arrImageParts = ((Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=^$strImageName\.&sortby=filename-Asc").Content | convertfrom-json).files

Not working
$strImageName = "pict0980\.mrw"
$arrImageParts = ((Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=^$strImageName\.&sortby=filename-Asc").Content | convertfrom-json).files

Not working

$strImageName = "C:\\DSLR\\DSLR-RAW\\ExtHDD\ 2501\\Dynax7D\\2006\\09\\17\\pict0980\.mrw"
$arrImageParts = ((Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=^$strImageName\.&sortby=filename-Asc").Content | convertfrom-json).files

Not working
$strImageName = "C:\DSLR\DSLR-RAW\ExtHDD 2501\Dynax7D\2006\09\17\pict0980.mrw"
$arrImageParts = ((Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=^$strImageName\.&sortby=filename-Asc").Content | convertfrom-json).files

The above script was created from this one.

Mario

#5
I'm no PowerShell expert, sorry. And I don't have the resources to debug user-written scripts.
If things work in the File Finder app, the API is OK. Same endpoint.

You're sure about this:?

^$strImageName\.
When the variable holds ""pict0980.mrw" you're sending this regexp, right?

^pict0980.mrw\.

This cannot work.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

RobiWan

Ok understand.

let me ask a different question. Why the first one doesn't work and the second one works?


PowerShell  > (Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=ExtHDD").content

{"files":[],"hiddenByStacks":0}


PowerShell  > (Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=_rr52024.cr3").content
{"files":[{"id":216011,"ts":45489.813102,"tsmd":0.000000,"tsCreated":"2023:05:04T10:21:38.193","tsLastModified":"2023:05:04T06:00:04.0","tsLastWriteBackUtc":0.000000,"tsLastWriteBack":0.000000,"index":0,"folderId":1714,"folder":"C:\\DSLR\\DSLR-RAW\\ExtHDD 2508\\EOS R5\\2023\\05\\04\\","name":"_rr52024.cr3","namene":"_rr52024","ext":".cr3","fileName":"C:\\DSLR\\DSLR-RAW\\ExtHDD 2508\\EOS R5\\2023\\05\\04\\_rr52024.cr3","size":53537366,"crc":3658268326,"ltid":"2A45C54B-1E54-4A2B-A7B6-D3B78BDE3A15","class":"image","format":"CRW","mimeType":"text/plain","lastUpdated":"2023-05-04T08:00:04","lastUpdatedUTC":"2023-05-04T06:00:04","dateTime":"2023-05-04T08:00:03","dateTimeUTC":"2023-05-04T06:00:03","dateTimeOriginal":"2023-05-04T08:00:03","dateTimeLocal":"2023-05-04T08:00:03","dateTimeOffset":120,"offline":false,"protected":false,"readOnly":false,"pending":false,"pendingWb":false,"width":8352,"height":5586,"longEdge":8352,"shortEdge":5586,"portrait":false,"bpp":24,"rating":2,"label":"","stackState":0,"stackId":0,"stackColor":"","versionState":0,"history":[{"event":{"type":1,"name":"added","id":216011,"id2":0,"dateTime":"2023-11-11T10:07:30","title":"","text":"","user":"robert"}},{"event":{"type":2,"name":"updated","id":216011,"id2":0,"dateTime":"2023-11-11T11:14:12","title":"","text":"","user":"robert"}}],"gps":{"lat":39.862600,"lon":-5.023578,"alt":408.300000},"collections":[13,34,54,10002,11001],"roi":{"v":false,"t":0.000000,"r":1.000000,"b":1.000000,"l":0.000000}},{"id":226011,"ts":45489.823727,"tsmd":0.000000,"tsCreated":"2023:10:01T10:22:57.458","tsLastModified":"2023:09:26T09:24:26.0","tsLastWriteBackUtc":0.000000,"tsLastWriteBack":0.000000,"index":1,"folderId":1719,"folder":"C:\\DSLR\\DSLR-RAW\\ExtHDD 2508\\EOS R5\\2023\\09\\26\\","name":"_rr52024.cr3","namene":"_rr52024","ext":".cr3","fileName":"C:\\DSLR\\DSLR-RAW\\ExtHDD 2508\\EOS R5\\2023\\09\\26\\_rr52024.cr3","size":53712982,"crc":2044429776,"ltid":"3E26B778-AA74-44B1-B3FF-59E58E0D453D","class":"image","format":"CRW","mimeType":"text/plain","lastUpdated":"2023-09-26T11:24:26","lastUpdatedUTC":"2023-09-26T09:24:26","dateTime":"2023-09-26T11:24:25","dateTimeUTC":"2023-09-26T09:24:25","dateTimeOriginal":"2023-09-26T11:24:25","dateTimeLocal":"2023-09-26T11:24:25","dateTimeOffset":120,"offline":false,"protected":false,"readOnly":false,"pending":false,"pendingWb":false,"width":8352,"height":5586,"longEdge":8352,"shortEdge":5586,"portrait":false,"bpp":24,"rating":2,"label":"","stackState":0,"stackId":0,"stackColor":"","versionState":0,"history":[{"event":{"type":1,"name":"added","id":226011,"id2":0,"dateTime":"2023-11-11T10:13:46","title":"","text":"","user":"robert"}},{"event":{"type":2,"name":"updated","id":226011,"id2":0,"dateTime":"2023-11-11T12:34:20","title":"","text":"","user":"robert"}}],"gps":{"lat":54.188267,"lon":7.883228,"alt":38.620000},"collections":[13,34,54,10002,11001],"roi":{"v":false,"t":0.000000,"r":1.000000,"b":1.000000,"l":0.000000}}],"hiddenByStacks":0}


"ExtHDD" is a part of path where many images are stored, so I think I should receive many results back.
I did not say that the API does not work. At the moment I'm trying to get an overview of the whole thing.


Mario

Again, regexp.

pattern=ExtHDD  => Find all files containing ExtHDD

pattern=_rr52024.cr3 => The . must be escaped to make it work => pattern=_rr52024\.cr3
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

David_H

Quote from: RobiWan on July 22, 2024, 06:43:23 PMOk understand.

let me ask a different question. Why the first one doesn't work and the second one works?


PowerShell  > (Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=ExtHDD").content

{"files":[],"hiddenByStacks":0}


PowerShell  > (Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=_rr52024.cr3").content
{"files":[{"id":216011,"ts":45489.813102,"tsmd":0.000000,"tsCreated":"2023:05:04T10:21:38.193","tsLastModified":"2023:05:04T06:00:04.0","tsLastWriteBackUtc":0.000000,"tsLastWriteBack":0.000000,"index":0,"folderId":1714,"folder":"C:\\DSLR\\DSLR-RAW\\ExtHDD 2508\\EOS R5\\2023\\05\\04\\","name":"_rr52024.cr3","namene":"_rr52024","ext":".cr3","fileName":"C:\\DSLR\\DSLR-RAW\\ExtHDD 2508\\EOS R5\\2023\\05\\04\\_rr52024.cr3","size":53537366,"crc":3658268326,"ltid":"2A45C54B-1E54-4A2B-A7B6-D3B78BDE3A15","class":"image","format":"CRW","mimeType":"text/plain","lastUpdated":"2023-05-04T08:00:04","lastUpdatedUTC":"2023-05-04T06:00:04","dateTime":"2023-05-04T08:00:03","dateTimeUTC":"2023-05-04T06:00:03","dateTimeOriginal":"2023-05-04T08:00:03","dateTimeLocal":"2023-05-04T08:00:03","dateTimeOffset":120,"offline":false,"protected":false,"readOnly":false,"pending":false,"pendingWb":false,"width":8352,"height":5586,"longEdge":8352,"shortEdge":5586,"portrait":false,"bpp":24,"rating":2,"label":"","stackState":0,"stackId":0,"stackColor":"","versionState":0,"history":[{"event":{"type":1,"name":"added","id":216011,"id2":0,"dateTime":"2023-11-11T10:07:30","title":"","text":"","user":"robert"}},{"event":{"type":2,"name":"updated","id":216011,"id2":0,"dateTime":"2023-11-11T11:14:12","title":"","text":"","user":"robert"}}],"gps":{"lat":39.862600,"lon":-5.023578,"alt":408.300000},"collections":[13,34,54,10002,11001],"roi":{"v":false,"t":0.000000,"r":1.000000,"b":1.000000,"l":0.000000}},{"id":226011,"ts":45489.823727,"tsmd":0.000000,"tsCreated":"2023:10:01T10:22:57.458","tsLastModified":"2023:09:26T09:24:26.0","tsLastWriteBackUtc":0.000000,"tsLastWriteBack":0.000000,"index":1,"folderId":1719,"folder":"C:\\DSLR\\DSLR-RAW\\ExtHDD 2508\\EOS R5\\2023\\09\\26\\","name":"_rr52024.cr3","namene":"_rr52024","ext":".cr3","fileName":"C:\\DSLR\\DSLR-RAW\\ExtHDD 2508\\EOS R5\\2023\\09\\26\\_rr52024.cr3","size":53712982,"crc":2044429776,"ltid":"3E26B778-AA74-44B1-B3FF-59E58E0D453D","class":"image","format":"CRW","mimeType":"text/plain","lastUpdated":"2023-09-26T11:24:26","lastUpdatedUTC":"2023-09-26T09:24:26","dateTime":"2023-09-26T11:24:25","dateTimeUTC":"2023-09-26T09:24:25","dateTimeOriginal":"2023-09-26T11:24:25","dateTimeLocal":"2023-09-26T11:24:25","dateTimeOffset":120,"offline":false,"protected":false,"readOnly":false,"pending":false,"pendingWb":false,"width":8352,"height":5586,"longEdge":8352,"shortEdge":5586,"portrait":false,"bpp":24,"rating":2,"label":"","stackState":0,"stackId":0,"stackColor":"","versionState":0,"history":[{"event":{"type":1,"name":"added","id":226011,"id2":0,"dateTime":"2023-11-11T10:13:46","title":"","text":"","user":"robert"}},{"event":{"type":2,"name":"updated","id":226011,"id2":0,"dateTime":"2023-11-11T12:34:20","title":"","text":"","user":"robert"}}],"gps":{"lat":54.188267,"lon":7.883228,"alt":38.620000},"collections":[13,34,54,10002,11001],"roi":{"v":false,"t":0.000000,"r":1.000000,"b":1.000000,"l":0.000000}}],"hiddenByStacks":0}


"ExtHDD" is a part of path where many images are stored, so I think I should receive many results back.
I did not say that the API does not work. At the moment I'm trying to get an overview of the whole thing.



Because you are asking it to search on the filename. ExtHDD is in the PATH, not the filename (rr52024.cr3).

Try the v1/folders endpoint ($URI/v1/folders?auth_token=&contains=ExtHDD ) instead.

RobiWan

Quote from: David_H on July 22, 2024, 07:23:06 PMBecause you are asking it to search on the filename. ExtHDD is in the PATH, not the filename (rr52024.cr3).

Hmm, ExtHDD is a part of filename I mean.

id                 : 226011
ts                 : 45489,823727
tsmd               : 0,000000
tsCreated          : 2023:10:01T10:22:57.458
tsLastModified     : 2023:09:26T09:24:26.0
tsLastWriteBackUtc : 0,000000
tsLastWriteBack    : 0,000000
index              : 59
folderId           : 1719
folder             : C:\DSLR\DSLR-RAW\ExtHDD 2508\EOS R5\2023\09\26\
name               : _rr52024.cr3
namene             : _rr52024
ext                : .cr3
fileName           : C:\DSLR\DSLR-RAW\ExtHDD 2508\EOS R5\2023\09\26\_rr52024.cr3
size               : 53712982
crc                : 2044429776
ltid               : 3E26B778-AA74-44B1-B3FF-59E58E0D453D
class              : image
format             : CRW
mimeType           : text/plain
lastUpdated        : 2023-09-26T11:24:26
lastUpdatedUTC     : 2023-09-26T09:24:26
dateTime           : 2023-09-26T11:24:25
dateTimeUTC        : 2023-09-26T09:24:25
dateTimeOriginal   : 2023-09-26T11:24:25
dateTimeLocal      : 2023-09-26T11:24:25
dateTimeOffset     : 120
offline            : False
protected          : False
readOnly           : False
pending            : False
pendingWb          : False
width              : 8352
height             : 5586
longEdge           : 8352
shortEdge          : 5586
portrait           : False
bpp                : 24
rating             : 2
label              :
stackState         : 0
stackId            : 0
stackColor         :
versionState       : 0
history            : {@{event=}, @{event=}}
gps                : @{lat=54,188267; lon=7,883228; alt=38,620000}
collections        : {13, 34, 54, 10002...}
roi                : @{v=False; t=0,000000; r=1,000000; b=1,000000; l=0,000000}

Mario

#10
Fix the non-escaped . and it will work. See my post.
the endpoint searches the entire path so I'm sure it will work if you get your regexp right. Escape the . (issue 2) and don't add an extra . after the extension (issue 1). See my posts above.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

David_H

Quote from: RobiWan on July 22, 2024, 07:34:19 PM
Quote from: David_H on July 22, 2024, 07:23:06 PMBecause you are asking it to search on the filename. ExtHDD is in the PATH, not the filename (rr52024.cr3).

Hmm, ExtHDD is a part of filename I mean.

I agree...
I have one -     "fileName": "j:\\photography\\2006\\06\\2006_06_18\\IMG_4196.CR2",

localhost:40000/v1/search/filename?auth_token=&scope=database&pattern=IMG_4196\.cr2
Matches that one fine

One would expect that the following :
localhost:40000/v1/search/filename?auth_token=&scope=database&pattern=2006_06_18
Would return it also (like your ExtHDD), but it doesn't (returns nothing)...
If the pattern is changed to :
localhost:40000/v1/search/filename?auth_token=&scope=database&pattern=2006

Then it returns any where the name has 2006 in it; not the filename.

David_H

Quote from: David_H on July 22, 2024, 09:26:36 PMlocalhost:40000/v1/search/filename?auth_token=&scope=database&pattern=2006

Then it returns any where the name has 2006 in it; not the filename.


Try something like the following powershell (replacing the 2024_07_20 with the folder filter of your choice). It can probably be made much neater, but the idea is it finds all folders matching the contains, takes their Ids, puts them into a query that selects all files where their folder matches the supplied Ids, puts the results into an idlist (folderMatch), then selects the idlist... It may break if there's too many folder Ids.

$folders = (Invoke-RestMethod -Uri "$URI/v1/folders?auth_token=&contains=2024_07_20")
$IdList = ($folders.folders | Select Id).Id -join ','
$query = "{""folders"":{""id"":[$IdList]}}"
$idList = (Invoke-RestMethod -Uri "$URI/v1/files/query?auth_token=&fields=idlist&idlistname=folderMatch&query=$query")
$results = (Invoke-RestMethod -Uri "$URI/v1/files?auth_token=&idlist=folderMatch&fields=id,name,namene,ext,filename,size").files


RobiWan

OK guys I will try it again - short as possible

1. I never rename files. This means I have a lot files with name  _rr52024.cr3 as example. But thy are of course in different paths stored.
2. I have list of files like this one:
C:\ExtHDD\ExtHDD 2508\robert\Fotografie\DSLR\ExtHDD 2508\EOS R5\RAW\2024\04\13\_rr54969.cr3
C:\ExtHDD\ExtHDD 2508\robert\Fotografie\DSLR\ExtHDD 2508\EOS R5\RAW\2024\04\13\_rr54970.cr3
C:\ExtHDD\ExtHDD 2508\robert\Fotografie\DSLR\ExtHDD 2508\EOS R5\RAW\2024\04\13\_rr54971.cr3
C:\ExtHDD\ExtHDD 2508\robert\Fotografie\DSLR\ExtHDD 2508\EOS R5\RAW\2024\04\13\_rr54972.cr3

3. If I set
$filename = " _rr54969.cr3"
than with this code
((Invoke-WebRequest -Uri "$URI/v1/search/filename?auth_token=&scope=database&pattern=$filename").content  | convertfrom-json).files
I receive all files with this name


id                 : 218956
ts                 : 45486,564525
tsmd               : 0,000000
tsCreated          : 2023:07:18T15:02:07.545
tsLastModified     : 2023:07:14T13:45:06.0
tsLastWriteBackUtc : 0,000000
tsLastWriteBack    : 0,000000
index              : 0
folderId           : 1828
folder             : C:\DSLR\DSLR-RAW\ExtHDD 2508\EOS R5\2023\07\14\
name               : _rr54969.cr3
namene             : _rr54969
ext                : .cr3
fileName           : C:\DSLR\DSLR-RAW\ExtHDD 2508\EOS R5\2023\07\14\_rr54969.cr3
size               : 58548822
crc                : 866395556
ltid               : 18ADB646-961B-45DF-B072-B73B1FABD8F7
class              : image
format             : CRW
mimeType           : text/plain
lastUpdated        : 2023-07-14T15:45:06
lastUpdatedUTC     : 2023-07-14T13:45:06
dateTime           : 2023-07-14T15:44:54
dateTimeUTC        : 2023-07-14T13:44:54
dateTimeOriginal   : 2023-07-14T15:44:54
dateTimeLocal      : 2023-07-14T15:44:54
dateTimeOffset     : 120
offline            : False
protected          : False
readOnly           : False
pending            : False
pendingWb          : False
width              : 8352
height             : 5586
longEdge           : 8352
shortEdge          : 5586
portrait           : False
bpp                : 24
rating             : -1
label              :
stackState         : 0
stackId            : 0
stackColor         :
versionState       : 0
history            : {@{event=}, @{event=}}
gps                : @{lat=45,609040; lon=14,511700; alt=891,400000}
collections        : {13, 34, 54, 10007...}
roi                : @{v=False; t=0,000000; r=1,000000; b=1,000000; l=0,000000}

id                 : 241914
ts                 : 45489,827928
tsmd               : 0,000000
tsCreated          : 2024:04:13T13:17:53.0
tsLastModified     : 2024:04:13T13:17:53.0
tsLastWriteBackUtc : 45395,554086
tsLastWriteBack    : 45395,637419
index              : 1
folderId           : 1877
folder             : C:\DSLR\DSLR-RAW\ExtHDD 2508\EOS R5\2024\04\13\
name               : _rr54969.cr3
namene             : _rr54969
ext                : .cr3
fileName           : C:\DSLR\DSLR-RAW\ExtHDD 2508\EOS R5\2024\04\13\_rr54969.cr3
size               : 45792854
crc                : 341950696
ltid               : F87955F7-840B-4401-B146-D8E25277213B
class              : image
format             : CRW
mimeType           : text/plain
lastUpdated        : 2024-04-13T15:17:53
lastUpdatedUTC     : 2024-04-13T13:17:53
dateTime           : 2024-04-13T15:17:52
dateTimeUTC        : 2024-04-13T13:17:52
dateTimeOriginal   : 2024-04-13T15:17:52
dateTimeLocal      : 2024-04-13T15:17:52
dateTimeOffset     : 120
offline            : False
protected          : False
readOnly           : False
pending            : False
pendingWb          : False
width              : 8352
height             : 5586
longEdge           : 8352
shortEdge          : 5586
portrait           : False
bpp                : 24
rating             : -1
label              :
stackState         : 0
stackId            : 0
stackColor         :
versionState       : 0
history            : {@{event=}, @{event=}, @{event=}, @{event=}}
gps                : @{lat=54,186507; lon=7,902730; alt=10,200000}
collections        : {13, 34, 54, 75...}
roi                : @{v=False; t=0,000000; r=1,000000; b=1,000000; l=0,000000}

It doesn't matter whether I escape the "." with "\" or not.

But the problem ist - it will not work with
$filename = " C:\ExtHDD\ExtHDD 2508\robert\Fotografie\DSLR\ExtHDD 2508\EOS R5\RAW\2024\04\13\_rr54969.cr3"
Here, too, it doesn't matter whether I mask the existing "\" with another "\" and also mask the white space with "\". It simply does not work.
And I just want to know - am I making a mistake and if so where or is it simply not possible to pass the complete path?



RobiWan

With this code:

param(
    [Parameter(Mandatory = $true, Position = 0)][string]$FileName
)

$PAGE_SIZE = 5000
$server = "localhost"
$port = "50519"
$protokoll = "http"
$URI = "$($protokoll)://$($server):$($port)"
$fileNames = @(Get-Content $FileName)
$fileNamesSet = New-Object -TypeName 'System.Collections.Generic.HashSet[string]'
$windowName = (Get-Item $FileName).BaseName
$Match = [System.Collections.Generic.List[System.String]]::new()
$PAGE = 0

# Login to WebService
$authenticate = Invoke-RestMethod -Uri "$URI/v1/authenticate" -Method Post -Body @{ 'id' = $env:USERNAME; 'password' = ''; 'appid' = '' }
$auth_token = $authenticate.auth_token

$fileNames | ForEach-Object {
$filenamesSet.Add($_) | Out-Null
}

while ($true) {
    $result = Invoke-RestMethod -Uri "$URI/v1/files" -Method GET -Body @{ 'page' = $PAGE; 'pagesize' = $PAGE_SIZE; 'fields' = 'id,filename'; 'auth_token' = $auth_token }
    foreach ($file in $result.files) {
        if ($fileNamesSet.Contains($file.filename)) {
            $Match.Add($file.id)
        }
    }
    if ($result.files.Length -lt $PAGE_SIZE) { break }
    $PAGE++
}

Invoke-RestMethod -Method Post -Uri "$URI/v1/imatch/resultwindow/open" -Body @{ 'name' = "$windowName"; 'id' = $($Match -join ","); 'auth_token' = $auth_token }

I need 55 Sec to find/ select 10000 files.
Imatch search APP needs for the same files, 15 Sec.


David_H

Quote from: RobiWan on July 22, 2024, 10:42:15 PMI need 55 Sec to find/ select 10000 files.
Imatch search APP needs for the same files, 15 Sec.


I'm pretty sure the files app optimizes the call; if I read the code for it right, and you are looking for something like

ExtHDD 2508\EOS R5\2023\07\14\_rr54969.cr3

It will search for all files matching _rr54969.cr3

Then in the results, it'll compare the full filename to the rest of the query, and add it to the results if there's a match. If you're looking for multiple files, it'll query for all matching leaf filenames, then loop round and compare the results full name to the input query and add matching results.

Mario

I've tried this URL in my web browser:

http://127.0.0.1:50519/v1/search/filename?auth_token=&scope=database&pattern=^a.*&sortby=filename-Asc&fields=id,name,folder

This searches the entire database for files beginning with a and returns the id, filename and folder for each matching file.
For a database with 102,000 files, this takes only 0.15s to return the result (a few hundred files).

If you want to find specific files in specific folders, either use the scope=folders parameter and specify the paths of the folders to search in the path= parameter.

Or run the search just with the file name as I did and then iterate over the result and look at the folder element to filter by folder name.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook