Partager via


ManagedProperty.Weight, propriété (Microsoft.Office.Server.Search.Administration)

Gets or sets the weight setting for a managed property.

Espace de noms : Microsoft.Office.Server.Search.Administration
Assembly : Microsoft.Office.Server.Search (dans microsoft.office.server.search.dll)

Syntaxe

'Déclaration
Public Property Weight As Single
'Utilisation
Dim instance As ManagedProperty
Dim value As Single

value = instance.Weight

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

Valeur de la propriété

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

Remarques

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 Recherche de contenu d'entreprise, see Présentation de l'architecture de pertinence de la recherche de contenu d'entreprise and Amélioration de la pertinence.

Exemple

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 Procédure : modifier le paramètre Poids d'une propriété gérée.

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

Voir aussi

Référence

ManagedProperty, classe
Membres ManagedProperty
Microsoft.Office.Server.Search.Administration, espace de noms