脚本中的Sitecore PowerShell快速搜索
我使用Sitecore PowerShell扩展模块创建脚本,将关系从一个项复制到相关项 我使用脚本中的Sitecore PowerShell快速搜索,powershell,sitecore,Powershell,Sitecore,我使用Sitecore PowerShell扩展模块创建脚本,将关系从一个项复制到相关项 我使用getchilditem获取所有与特定字段相关的项目 Get-ChildItem -Recurse . | Where-Object { $_.TemplateName -match $'myTemplate' -and $_.Fields[$fromfield].Value -ne $null -and $_.Fields[$fromfield].Value -ne "" }
getchilditem
获取所有与特定字段相关的项目
Get-ChildItem -Recurse . | Where-Object {
$_.TemplateName -match $'myTemplate' -and
$_.Fields[$fromfield].Value -ne $null -and
$_.Fields[$fromfield].Value -ne ""
} | ForEach-Object {
}
因为数据太大,所以我花了大约1分钟来获取所有项目
因此,我尝试使用查找项目
来加快搜索过程
Find-Item -Index 'sitecore_mastre_index' -Where 'TemplateName = @0' -WhereValues 'myTemplate'
它给了我以下警告,注意我使用的是Sitecore 7.2版
警告:由于平台限制,此版本的Sitecore不支持其中的参数
从Sitecore 7.5版开始支持此参数
是否有一种方法可以比使用Get ChildItem
更快地使用PowerShell检索数据
注意:如果使用
Get Item.
查询只返回前100个项目。我有更多的项目。 有一些事情要考虑。
示例:获取子项# 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
示例:使用快速查询获取项目
# 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
我们编写的这本书可能也会证明是有益的。
如果不了解更多变量,就很难判断。您是否尝试过Get Childitem的排除/包括/筛选参数?在Sitecore 9.02中,语法fast:/不再有效。。。有什么想法或解决办法吗?将快速查询更改为慢速查询,它将应用最大返回结果100…尝试一下,并让我知道它是否适用于您,因为Sitecore 7.5上的工作在9.02上停止,不确定问题是与PowerShell还是Sitecore本身有关。。。