【问题标题】:Sitecore PowerShell fast Search in Script脚本中的 Sitecore PowerShell 快速搜索
【发布时间】:2015-12-28 11:57:34
【问题描述】:

我使用 Sitecore PowerShell Extensions 模块创建脚本,将关系从一项复制到相关项。

我使用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

警告:由于平台限制,此版本的 Sitecore 不支持参数 Where。

从 Sitecore 版本 7.5 开始支持此参数

有没有办法使用 PowerShell 以比使用 Get-ChildItem 更快的方式检索数据?

注意:如果我使用Get-Item .,则查询仅返回前 100 个项目。我还有很多东西。

【问题讨论】:

  • 如果不了解更多关于变量的信息,很难说。 Get-Childitem 的 exclude/include/filter 参数你试过了吗?

标签: powershell sitecore


【解决方案1】:

有几点需要考虑。

示例: 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

示例:快速查询获取项目

# 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

【讨论】:

  • 语法 fast:/ 在 Sitecore 9.02 中不再起作用...有什么想法或解决方法吗?将快速查询更改为慢速查询,它会应用最大返回结果 100....
  • 试试吧,让我知道它是否适合你,因为在 Sitecore 7.5 上工作的东西在 9.02 上停止工作,不确定问题出在 PowerShell 还是 Sitecore 本身......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-11
  • 1970-01-01
相关资源
最近更新 更多