ManagedProperty.Weight 属性
请注意:此 API 现在已过时。
获取或设置托管属性粗细设置。
命名空间: Microsoft.Office.Server.Search.Administration
程序集: Microsoft.Office.Server.Search(位于 Microsoft.Office.Server.Search.dll 中)
语法
声明
<ObsoleteAttribute("This property is deprecated. It does not take effect on ranking, please use RankingModel class.")> _
Public Property Weight As Single
Get
Set
用法
Dim instance As ManagedProperty
Dim value As Single
value = instance.Weight
instance.Weight = value
[ObsoleteAttribute("This property is deprecated. It does not take effect on ranking, please use RankingModel class.")]
public float Weight { get; set; }
属性值
类型:System.Single
双精度浮点数的搜索架构中指定托管属性的权重值。
备注
粗细设置适用于相关性框架中,而且会影响托管属性的相对重要性的等级计算期间。
在SharePoint 企业级搜索中的相关性的详细信息,请参阅Enterprise Search Relevance Architecture Overview和Improving Relevance。
示例
下面的代码示例更改托管属性粗细设置。在此示例中使用的代码的分步演练,请参见How to: Change the Weight Setting for a Managed Property。
Prerequisites
确保已创建了一个共享服务提供程序。
Project References
运行本示例之前,在控制台应用程序代码项目中添加以下项目引用:
Microsoft.SharePoint
Microsoft.Office.Server
Microsoft.Office.Server.Search
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.Office.Server.Search.Administration;
namespace PropertyWeightSample
{
class Program
{
static void Main(string[] args)
{
try
{
if (args.Length != 2)
{
Usage();
return;
}
/*
Replace <SiteName> with the name of a site using the Shared Service Provider.
*/
string strURL = "http://<SiteName>";
Schema sspSchema = new Schema(SearchContext.GetContext(new SPSite(strURL)));
ManagedPropertyCollection properties = sspSchema.AllManagedProperties;
string strPropertyName = args[0].ToLower();
float newWeight = Convert.ToSingle(args[1]);
if (!properties.Contains(strPropertyName))
{
Console.WriteLine(strPropertyName + " property does not exist.");
return;
}
foreach (ManagedProperty property in properties)
{
if (property.Name.ToLower() == strPropertyName)
{
property.Weight = newWeight;
Console.WriteLine("Weight value changed for " + strPropertyName + " property.");
Console.WriteLine("NAME: " + property.Name + " WEIGHT: " + property.Weight.ToString());
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Usage();
}
}
private static void Usage()
{
Console.WriteLine("Change Property Weight");
Console.WriteLine("Usage: PropertyWeightSample.exe ManagedPropertyName <WeightValue>");
Console.WriteLine("<WeightValue>: Must be formatted as a float.");
}
}
}