Compartir a través de


: ManagedProperty.Weight (Propiedad) (Microsoft.Office.Server.Search.Administration)

Gets or sets the weight setting for a managed property.

Espacio de nombres:
Ensamblado: Microsoft.Office.Server.Search (in microsoft.office.server.search.dll)

Sintaxis

'Declaración
Public Property Weight As Single
'Uso
Dim instance As ManagedProperty
Dim value As Single

value = instance.Weight

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

Valor de propiedad

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

Comentarios

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 Enterprise Search, see Introducción a la arquitectura de relevancia del motor de búsqueda Enterprise Search and Mejora de la relevancia.

Ejemplo

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 Procedimiento para cambiar el valor de peso de una propiedad administrada.

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

Vea también

Referencia

ManagedProperty (Clase)
ManagedProperty (Miembros)
Microsoft.Office.Server.Search.Administration (Espacio de nombres)