当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint 搜索查询建议

作者:精品下载站 日期:2024-12-14 13:42:35 浏览:12 分类:玩电脑

SharePoint 搜索查询建议


搜索建议是 SharePoint 2010 中引入的重要新功能之一,并在 SharePoint 2013 中得到增强。搜索查询建议是当用户键入搜索查询时出现在搜索框下方的单词。 (也称为预查询建议)。

自动生成 SharePoint 搜索建议:
当用户单击该查询的任何搜索结果至少六次时,该查询将自动添加到搜索建议中。从技术上讲,每天,名为“准备查询建议”的 SharePoint 计时器作业都会处理编译它们。因此,对于不同的结果源和网站集,自动查询建议可能会有所不同。

尽管搜索查询建议是根据用户搜索自动填充的,但手动添加搜索查询建议以宣传 SharePoint 的特定区域会很有帮助。不是吗?

如何使用 PowerShell 添加 SharePoint 2013 搜索建议

让我们使用 PowerShell 脚本添加 SharePoint 2010 搜索建议。


Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

    #Set the Terms to add in Search Suggestions
    $SearchSuggestions = @("Crescent", "Crescent Policies", "Crescent News", "Crescent Tech", "Crescent Employee Of the Month", "Crescent Travel Request")

    #Get the Search Service Application "Search Service Application" - Your's maybe in a different name
    $ssa = Get-SPEnterpriseSearchServiceapplication -Identity "Search Service Application" 

    #Process Each Search Term
    foreach ($Suggestion in $SearchSuggestions)
    {
        New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language en-US -Type QuerySuggestionAlwaysSuggest -Name $Suggestion
    }

    #Trigger the Timerjob
    $timerJob = Get-SPTimerJob "Prepare query suggestions"
    $timerJob.RunNow()

也可以将它们放在 CSV 文件中并导入,而不是将它们放在硬编码数组中:


$csvfile = "D:\SearchSuggestions.csv" #with header "Suggestion"
$KeyWordsData = Import-Csv $csvfile
...

foreach ($Row in $KeywordsData)
{
  New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language en-US -Type QuerySuggestionAlwaysSuggest -Name $Row.Suggestion
}
...

您可以通过导航到中央管理和管理服务应用程序页面来获取搜索服务应用程序名称。

SharePoint 2010 搜索查询建议不起作用?运行计时器作业:“准备查询建议”。另外,请确保在搜索框 Web 部件属性中启用 SharePoint 2010 显示查询建议选项!

[玩转系统] SharePoint 搜索查询建议

结果:当用户在搜索框中键入关键字时,搜索中心会提供建议来帮助完成查询

[玩转系统] SharePoint 搜索查询建议

要获取所有 SharePoint 2013 搜索查询建议:


#Get the Search Service Application "Search Service Application" by its name
$ssa = Get-SPEnterpriseSearchServiceapplication -Identity "Search Service Application" 
#Get all  Search Query suggestion
Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $ssa

使用 PowerShell 删除搜索建议


Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

#Get the Search Service Application "Search Service Application" by its name
$ssa = Get-SPEnterpriseSearchServiceapplication -Identity "Search Service Application" 

#Remove Search Query Suggestion "Crescent Employee Of the Month"
Remove-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language En-Us -Type QuerySuggestionAlwaysSuggest -Identity "Crescent Employee Of the Month"

#Trigger the Timerjob for the changes to take effect
$timerJob = Get-SPTimerJob "Prepare query suggestions"
$timerJob.RunNow()

如何手动添加 SharePoint 2013 搜索查询建议:

前往中央管理 >> 管理服务应用程序 >> 搜索服务应用程序 >> 点击查询建议链接左侧导航。从这里,您可以启用/禁用、导入/导出自定义搜索查询建议。

[玩转系统] SharePoint 搜索查询建议

顺便说一句,导入查询建议会覆盖已创建的任何现有手动查询建议!所以,先导出,修改,然后再导入!

[玩转系统] SharePoint 搜索查询建议

SharePoint 2013 搜索查询建议中的新增功能:
SharePoint 2013 中的情况略有不同,因为它允许在 SSA/网站集/网站级别自定义搜索参数。因此,我们有一个附加参数“Owner”来指定范围。此外,SharePoint 2013 中的查询建议与结果源也得到了改进。每天为每个结果源(每个网站集)生成查询建议。


Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

#Set the Terms to add in Search Suggestions
$SearchSuggestions = @("Crescent", "Crescent Policies", "Crescent News", "Crescent Tech", "Crescent Employee Of the Month", "Crescent Travel Request")

#Get the default search service application
$ssa = Get-SPEnterpriseSearchServiceApplication
#You can also use: Get-SPEnterpriseSearchServiceapplication -Identity "Search Service Application" 

$owner = Get-SPEnterpriseSearchOwner -level SSA

#Process Each Search Term
foreach ($Suggestion in $SearchSuggestions)
{
   New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name $Suggestion -Owner $owner
}
#Trigger the SharePoint 2013 query suggestions timer job
Start-SPTimerJob -Identity "Prepare query suggestions"

不要忘记运行 SharePoint 2013 查询建议计时器作业!

在 SharePoint 2013 中删除 SSA 级别的搜索建议:


Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

#Get the default search service application
$ssa = Get-SPEnterpriseSearchServiceApplication

#Set the Query Suggestion Level
$owner = Get-SPEnterpriseSearchOwner -level SSA

#Get All Existing phrases
$SuggestionList = Get-SPEnterpriseSearchLanguageResourcePhrase  -SearchApplication $ssa -Owner $Owner -Language En-Us -Type QuerySuggestionAlwaysSuggest #-SourceId $ResultSource.Id

#Remove Them All
$SuggestionList |  Remove-SPEnterpriseSearchLanguageResourcePhrase -Type QuerySuggestionAlwaysSuggest -Language "en-us" -Owner $Owner 

#Trigger the SharePoint 2013 query suggestions timer job
Start-SPTimerJob -Identity "Prepare query suggestions"

在 SharePoint 2013 中的网站级别添加查询建议:


Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

#Set the Terms to add in Search Suggestions
$SearchSuggestions = @("Crescent", "Crescent Policies", "Crescent News", "Crescent Tech", "Crescent Employee Of the Month", "Crescent Travel Request")

#Get the default search service application
$ssa = Get-SPEnterpriseSearchServiceApplication

$Web = Get-SPweb -Identity "https://sharepoint.crescent.com/sites/operations/"

$owner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $web 

$FederationManager  = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager -ArgumentList $ssa

$ResultSource = $FederationManager.GetSourceByName("Local SharePoint Results", $owner)

#Process Each Search Term
foreach ($Suggestion in $SearchSuggestions)
{
   New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name $Suggestion -Owner $owner -SourceId $ResultSource.Id
}

#Its also  possible to use PowerShell to Import Search Suggestions from text file using PowerShell
#$ssap = Get-SPEnterpriseSearchServiceApplicationProxy
#Import-SPEnterpriseSearchPopularQueries -SearchApplicationProxy $ssap -Filename "D:\querySuggestions.txt" -ResultSource $source -Web $web

#Trigger the timer job
Start-SPTimerJob -Identity "Prepare query suggestions"

这就对了!您已将查询建议添加到 SharePoint 搜索框。现在您开始输入 SharePoint,它将带来 SharePoint 建议。

[玩转系统] SharePoint 搜索查询建议

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯