我使用 Sitecore PowerShell 扩展模块创建脚本,将关系从一个项目复制到相关项目。
我使用 Get-ChildItem
获取与特定字段相关的所有项目
Get-ChildItem -Recurse . | Where-Object {
$_.TemplateName -match $'myTemplate' -and
$_.Fields[$fromfield].Value -ne $null -and
$_.Fields[$fromfield].Value -ne ""
} | ForEach-Object {
}
因为数据很大,我花了大约 1 分钟来获取所有项目。
所以我尝试使用 Find-Item
来加快搜索过程
Find-Item -Index 'sitecore_mastre_index' -Where 'TemplateName = @0' -WhereValues 'myTemplate'
它给了我以下警告,请注意我使用的是 Sitecore 7.2 版
WARNING: The parameter Where is not supported on this version of Sitecore due to platform limitations.
This parameter is supported starting from Sitecore Version 7.5
有没有一种方法可以比使用 Get-ChildItem
更快地使用 PowerShell 检索数据?
注意:如果我使用 Get-Item .
,查询仅返回前 100 个项目。我还有很多东西。
最佳答案
有几件事需要考虑。
示例: Get-ChildItem
# Essentially touches all of the items in the database.
# It's one of the most common ways to query the items,
# but should be a narrow path.
Get-ChildItem -Path "master:\" -Recurse
示例:查找项目
# This example is what you need to query the index.
# You can chain together multiple Criteria by making a comma separated list of hashtables.
# Piping to the Initialize-Item command will convert SearchResultItem to Item.
# PS master:\> help Find-Item -Examples
Find-Item -Index sitecore_master_index -Criteria @{Filter = "Equals"; Field = "_templatename"; Value = "Sample Item"} | Initialize-Item
示例:快速查询的Get-Item
# This example takes advantage of the fast query. Substitute for your use case.
$query = "fast:/sitecore//*[@@templatename='Sample Item']"
Get-Item -Path "master:" -Query $query
我们整理的这本书也可能对您有所帮助。 https://www.gitbook.com/book/sitecorepowershell/sitecore-powershell-extensions/details
关于powershell - Sitecore PowerShell 在脚本中快速搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34493108/