ManagedProperty.Weight 属性 (Microsoft.Office.Server.Search.Administration)

Gets or sets the weight setting for a managed property.

命名空间: Microsoft.Office.Server.Search.Administration
程序集: Microsoft.Office.Server.Search (在 microsoft.office.server.search.dll 中)

语法

声明
Public Property Weight As Single
用法
Dim instance As ManagedProperty
Dim value As Single

value = instance.Weight

instance.Weight = value
public float Weight { get; set; }

属性值

A double-precision, floating-point number that specifies the weight value for a managed property in the search schema.

备注

The weight setting applies to the relevance framework, and impacts the relative importance of a managed property during the ranking calculation.

For more information about relevance in 企业级搜索, see 企业级搜索相关性体系结构概述 and 改进相关性.

示例

The following code example changes the weight setting for a managed property. For a step-by-step walkthrough of the code used in this sample, see 如何:更改托管属性的权重设置.

Prerequisites

Ensure a Shared Service Provider is already created.

Project References

Add the following Project References in your console application code project before running this sample:

  • 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.");
        }
    }
}

另请参阅

参考

ManagedProperty 类
ManagedProperty 成员
Microsoft.Office.Server.Search.Administration 命名空间