Forum Discussion
Submit-PnpSearchQuery Filter on Date
- Mar 18, 2024
Correction... that wasn't returning quite the right results also... however... this is:
$SearchQuery = "(NOT RefinableDate01>1900-01-01 Path:" + $SiteURL +"/Reports/)"This was a useful resource:
https://www.techmikael.com/2023/04/filter-on-managed-properties-in-search.html
I figured it out. You need to do a couple of things first..... Go into SharePoint Admin Center and set one of the RefinableDateXX fields to your custom date field in the Advance Search Settings. Then do a full index of the document library. Give this 24 hours. Once indexed you need to use the -Refiner switch. So find all files in the library and then refine the results for those with 1900-01-01 as the date (SharePoints Empty Date Value).
$SearchQuery = "(Path:" + $SiteURL +"/Reports/)"
$Refiner = "RefinableDate01(discretize=manual/1900-01-01)"
Connect-PnPOnline -Url $SiteURL -Interactive
Write-Host "Searching for: $SearchQuery" -ForegroundColor Cyan
$SearchResults = Submit-PnPSearchQuery -Query $SearchQuery -All -SortList @{Created="Descending"} -Refiners $Refiner
Correction... that wasn't returning quite the right results also... however... this is:
$SearchQuery = "(NOT RefinableDate01>1900-01-01 Path:" + $SiteURL +"/Reports/)"This was a useful resource:
https://www.techmikael.com/2023/04/filter-on-managed-properties-in-search.html