你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。

添加计分概要文件以提高搜索分数

Note

Foundry IQ (Azure AI 搜索) 提供直接索引和查询 API 以及用于托管检索的高级知识库和知识库 API。 使用 Azure 门户、REST API 或 Azure SDK 配置这些功能,或将代理连接到 Microsoft Foundry 门户中的知识库。

Important

本文中标记为(预览)的功能为公共预览版,受Microsoft Azure预览版补充使用条款的约束。 有关 Foundry IQ(Azure AI 搜索)特有的预览术语,请参阅预览功能。

计分概要文件用于根据用户定义的条件来提升或降低匹配文档的排名。 本文介绍如何指定和分配计分概要文件,以便根据提供的参数提升搜索分数。 可以根据以下内容创建计分概要文件:

  • 加权字符串字段,其提升基于指定字段中找到的匹配项。 例如,在“主题”字段中找到的匹配项被认为比“说明”字段中找到的匹配项更相关。

  • 数值字段的函数,包括日期和地理坐标。 数值内容函数支持提升距离(适用于地理坐标)、新鲜度(适用于日期时间字段)、范围和数量级。

  • 字符串集合(标签)的函数。 如果集合中的任何项都与查询匹配,标记函数将提升文档的搜索分数。

  • 一个 随机函数(预览), 用于分配伪随机分数,而不是提升字段。

  • (预览版)不同提升的聚合。 在单个计分配置文件中,可以指定多个评分函数,然后设置 "functionAggregation": "product"。 对所有函数进行高度评分的文档处于优先顺序,同时取消在一个或多个字段中评分较弱的文档。

可以通过在 Azure 门户中编辑其 JSON 定义或通过任何 Azure SDK 中的 创建或更新索引 REST 或等效索引更新 API 等 API 以编程方式将计分配置文件添加到索引。 没有索引重新生成要求,因此可以添加、修改或删除评分配置文件,而不会影响索引文档。

在本文结束时,您将能够创建和应用评分配置文件,以基于字段权重、新鲜度、距离或自定义条件提升搜索相关性。

Prerequisites

  • 一份 Azure 订阅。 免费创建一个。

  • Foundry IQ(Azure AI 搜索)服务。 创建服务或查找现有服务。

  • 包含文本或数字(非函数)字段的搜索索引。

  • 权限:示例使用基于角色的访问。 若要创建或更新带有评分配置文件的索引,请分配搜索服务参与者角色。若要加载文档,请分配搜索索引数据参与者角色。若要使用评分配置文件执行查询,请分配搜索索引数据读取者角色。 有关详细信息,请参阅使用角色进行连接。

  • 对于随机函数,请使用 REST API 版本 2026-11-01-preview。 随机评分在 2026-10-01 中不可用。

  • 安装 SDK(可选):

    • Python: pip install azure-search-documents azure-identity
    • C#: dotnet add package Azure.Search.Documents 和 dotnet add package Azure.Identity

Tip

对于即时代码示例,请跳到 评分配置文件定义。

计分概要文件的规则

可以在 关键字搜索、矢量搜索、混合搜索和 语义重排序中使用计分配置文件。 基于字段的计分配置文件适用于非向量字段,因此索引需要可以提升或加权的文本或数字字段。 随机函数是一个例外:它不针对任何字段,并且会替换相似性分数,而不是提升它们。

索引中最多可以有 100 个计分配置文件(请参阅 服务限制),但在任何给定查询中一次只能指定一个配置文件。

可以将语义排名与计分配置文件结合使用,同时在完成语义排序后再应用该计分概要文件。 否则,当多个排名或相关性功能发挥作用时,语义排名是最后一步。 搜索评分的工作原理 说明了操作顺序。

额外的规则 特别适用于函数。

Note

不熟悉相关概念? 在 Foundry IQ 中访问相关性和评分 以获取背景信息。 还可以在 YouTube 上观看此视频片段,了解基于 BM25 排名结果的评分配置文件。

计分概要文件定义

计分概要文件在索引架构中定义。 它由加权字段、函数和参数组成。

以下定义展示了一个名为“geo”的简单概要文件。 此示例用于提升在“hotelName”字段中具有搜索词的结果。 它还使用 distance 函数优先提升在当前位置 10 公里范围内的结果。 如果有人搜索“inn”一词,而“inn”恰好是酒店名称的一部分,包含当前位置 10 公里范围内带有“inn”的酒店的文档会在搜索结果中的较高位置出现。

"scoringProfiles": [
  {  
    "name":"geo",
    "text": {  
      "weights": {  
        "hotelName": 5
      }                              
    },
    "functions": [
      {  
        "type": "distance",
        "boost": 5,
        "fieldName": "location",
        "interpolation": "logarithmic",
        "distance": {
          "referencePointParameter": "currentLocation",
          "boostingDistance": 10
        }                        
      }                                      
    ]                     
  }            
]

参考: scoringProfiles | scoringFunction | 距离函数

有关更多方案,请参阅本文中 有关新鲜度、距离 和 加权文本和函数 的示例。

使用计分配置文件进行查询

import os
from azure.identity import DefaultAzureCredential
from azure.search.documents import SearchClient

# Set up the client
endpoint = os.environ["AZURE_SEARCH_ENDPOINT"]
index_name = "hotels"
credential = DefaultAzureCredential()

client = SearchClient(endpoint=endpoint, index_name=index_name, credential=credential)

# Execute search with scoring profile
results = client.search(
    search_text="inn",
    scoring_profile="geo",
    scoring_parameters=["currentLocation--122.123,44.77233"],
    select=["HotelName", "Description", "Rating"]
)

for result in results:
    print(f"{result['HotelName']} (Score: {result['@search.score']})")

参考: SearchClient.search | scoring_profile 参数

将计分概要文件添加到搜索索引

  1. 从索引定义开始。 可以在现有索引中添加和更新计分概要文件,而无需重新生成它。 使用 “获取索引 ”拉取现有索引,并使用 “创建”或“更新索引” 请求发布修订。

  2. 粘贴到本文中提供的模板中。

  3. 提供符合命名约定的名称。

  4. 指定提升条件。 单个配置文件可以包含文本加权字段和/或函数。 随机配置文件仅包含一个随机函数,没有文本权重或其他函数。

应以迭代方式使用数据集,该数据集将帮助你证明或否定给定概要文件的效力。

可以在 Azure 门户中定义计分配置文件,如以下屏幕截图所示,也可以通过 REST API 或 Azure SDK 以编程方式定义,例如 .NET 或 Python 客户端库中的 ScoringProfile 类。

显示Azure门户中的“添加计分配置文件”选项的屏幕截图。

Template

此模板展示了基于字段的评分配置文件。 随机函数采用不同的结构,不包含fieldName或boost。请参见随机排列结果(预览)。 有关属性的描述,请参阅 REST API 参考。

"scoringProfiles": [  
  {   
    "name": "name of scoring profile",   
    "text": (optional, only applies to searchable fields) {   
      "weights": {   
        "searchable_field_name": relative_weight_value (positive #'s),   
        ...   
      }   
    },   
    "functions": (optional) [  
      {   
        "type": "magnitude | freshness | distance | tag",   
        "boost": # (positive number used as multiplier for raw score != 1),   
        "fieldName": "(...)",   
        "interpolation": "constant | linear (default) | quadratic | logarithmic",   

        "magnitude": {
          "boostingRangeStart": #,   
          "boostingRangeEnd": #,   
          "constantBoostBeyondRange": true | false (default)
        }  

        // ( - or -)  

        "freshness": {
          "boostingDuration": "..." (value representing timespan over which boosting occurs)   
        }  

        // ( - or -)  

        "distance": {
          "referencePointParameter": "...", (parameter to be passed in queries to use as reference location)   
          "boostingDistance": # (the distance in kilometers from the reference location where the boosting range ends)   
        }   

        // ( - or -)  

        "tag": {
          "tagsParameter":  "..."(parameter to be passed in queries to specify a list of tags to compare against target field)   
        }
      }
    ],   
    "functionAggregation": (optional, applies only when functions are specified) "sum (default) | average | minimum | maximum | firstMatching"   
  }   
],   
"defaultScoringProfile": (optional) "...", 

使用文本加权字段

当字段上下文很重要且查询包含 searchable 字符串字段时,使用文本加权字段。 例如,如果查询包含“airport”一词,则您可能喜欢 HotelName 字段中的“airport”,而不是“说明”字段。

加权字段是由一个 searchable 字段和一个用作乘数的正数组成的名称-值对。 如果 HotelName 的原始字段分数为 3,则该字段的提升分数将变为 6,这将导致父文档本身的总分更高。

"scoringProfiles": [  
    {  
      "name": "boostSearchTerms",  
      "text": {  
        "weights": {  
          "HotelName": 2,  
          "Description": 5 
        }  
      }  
    }
]

使用函数

当简单的相对权重不足或不适用时,请使用函数,例如距离和新鲜度的情况(即对数值数据的计算)。 多个函数可以共享配置文件,但配置文件包含随机函数时除外。 有关 Foundry IQ 中使用的 EDM 数据类型的详细信息,请参阅 支持的数据类型。

Function Description 用例
distance 按照远近程度或地理位置进行提升。 此函数仅可与 Edm.GeographyPoint 字段结合使用。 用于“查找附近位置”场景。
freshness 按照日期/时间字段 (Edm.DateTimeOffset) 中的值进行提升。 设置 boostingDuration 以指定表示发生提升的时间跨度的值。 在您想要强调近期(较新)日期时使用。 还可以提升一些项目的优先级,例如带有未来日期的日历事件——相比那些时间更久远的事件,更接近当前时间的事件可获得更高的权重。 范围的一端固定为当前时间。
magnitude 数量级是文档值(如日期或位置)与引用点(如“now”或目标位置)之间的计算距离。 它是评分函数的输入,并确定应用增益的程度。 根据数字字段的值范围改变排名。 该值必须是整数或浮点数。 对于星级评分 1 到 4,这里应为 1。 对于超过 50% 的利润率,这里应为 50。 此函数仅可与 Edm.Double 和 Edm.Int 字段结合使用。 对于 magnitude 函数,如果想要反转模式(例如,将价格较低项提升至价格较高项之上),可以将范围反转为从高到低。 假设价格范围从 100 美元到 1 美元,可以将 boostingRangeStart 设为 100、boostingRangeEnd 设为 1 以提升价格较低的项。 当想要提高利润率、评级、点击次数、下载次数、最高价格、最低价格或下载次数时使用。 当两个项目相关时,将首先显示具有较高分级的项目。
标签 按照搜索文档和查询字符串通用的标记进行提升。 tagsParameter 中提供了标记。 此函数仅可与类型为 Edm.String 和 Collection(Edm.String) 的搜索字段结合使用。 具有标记字段时使用。 如果列表中的给定标记本身是逗号分隔的列表,则可在查询时在字段上使用文本规范化器来去除逗号(将逗号字符映射到空格)。 此方法将列表“展平”,使所有条目成为用逗号分隔的单个长字符串。

随机函数(预览版)在没有字段输入的情况下分配伪随机分数。 新鲜度评分和距离评分是数量级评分的一种特殊情况,其中数量级是通过日期时间字段或地理字段自动计算的。

使用函数的规则

  • 仅对属性为 filterable的字段应用基于字段的函数。 函数 random 未指定 fieldName 或 boost。
  • 对函数类型(“freshness”、“magnitude”、“distance”、“tag”、“random”)使用小写形式。
  • 函数不能包含 null 值或空值。
  • 基于字段的函数每个函数定义只能有一个字段。 若要在同一配置文件中使用两次magnitude,请提供两个magnitude定义,每个字段对应一个定义。
  • 配置文件 random 最多包含一个 random 函数,没有其他函数类型,也没有文本权重。

随机化结果(预览版)

使用type: "random"为匹配的文档分配伪随机分数。 省略fieldName、boost和interpolation。 Random 不支持非默认内插或与其他函数或文本权重的组合。

Important

在2026-11-01-preview版 REST API 中,随机评分函数处于预览阶段。

对于可重复的请求,请将 random.seedParameter 设置为查询时评分参数的名称。 名称以字母开头,最多包含 16 个字母或数字。 在查询时恰好提供一个有符号 64 位整数。

以下无键工作流创建示例索引、上传四个文档,并查询种子值为 42 的随机评分配置文件。 使用 Foundry IQ 服务,其中标识具有 先决条件中列出的角色。

安装最新的预览版 azure-search-documents 包和 azure-identity 包:

pip install --pre azure-search-documents
pip install azure-identity

将AZURE_SEARCH_ENDPOINT环境变量设置为你的 Foundry IQ 服务终结点,然后运行以下代码:

import os

from azure.identity import DefaultAzureCredential
from azure.search.documents import SearchClient
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import (
    RandomScoringFunction,
    RandomScoringParameters,
    ScoringProfile,
    SearchableField,
    SearchFieldDataType,
    SearchIndex,
    SimpleField,
)

endpoint = os.environ["AZURE_SEARCH_ENDPOINT"]
index_name = "random-scoring-demo"
credential = DefaultAzureCredential()

index_client = SearchIndexClient(
    endpoint=endpoint,
    credential=credential,
)

index = SearchIndex(
    name=index_name,
    fields=[
        SimpleField(
            name="id",
            type=SearchFieldDataType.STRING,
            key=True,
            filterable=True,
            sortable=True,
        ),
        SearchableField(
            name="content",
            type=SearchFieldDataType.STRING,
        ),
        SimpleField(
            name="category",
            type=SearchFieldDataType.STRING,
            filterable=True,
        ),
    ],
    scoring_profiles=[
        ScoringProfile(
            name="randomSeeded",
            functions=[
                RandomScoringFunction(
                    parameters=RandomScoringParameters(
                        seed_parameter="seed"
                    )
                )
            ],
        ),
        ScoringProfile(
            name="randomUnseeded",
            functions=[RandomScoringFunction()],
        ),
    ],
)

index_client.create_or_update_index(index)

search_client = SearchClient(
    endpoint=endpoint,
    index_name=index_name,
    credential=credential,
)

documents = [
    {
        "id": "1",
        "content": "Astronomy uses telescopes to observe distant stars.",
        "category": "random-fixture",
    },
    {
        "id": "2",
        "content": "Botanical gardens cultivate orchids and roses.",
        "category": "random-fixture",
    },
    {
        "id": "3",
        "content": "Sailing navigation uses charts and compasses.",
        "category": "random-fixture",
    },
    {
        "id": "4",
        "content": "Cooking vegetables requires controlled heat.",
        "category": "random-fixture",
    },
]

search_client.upload_documents(documents=documents)

results = list(
    search_client.search(
        search_text="*",
        select=["id", "content"],
        top=4,
        include_total_count=True,
        scoring_profile="randomSeeded",
        scoring_parameters=["seed-42"],
    )
)

参考: SearchIndexClient |

设置内插

插值设定了用于提升新鲜度和距离的斜率形状。 由于分数从高到低变化,评分曲线始终向下倾斜。 内插决定了向下斜率的曲线,以及随着文档日期越来越久远,提升分数的变化程度。 省略随机评分的内插;仅接受默认值 linear 。

Interpolation Description
linear 对于介于最大值和最小范围内的项目,将逐步递减地应用提升。 建议在需要相关性逐渐减弱时使用。 Linear 是计分概要文件的默认内插。
constant 对于起始和结束范围内的项,将对排名结果应用恒定提升。 无论年龄如何,当你想要一个固定处罚时,请使用此值。
quadratic 二次函数在初始阶段下降得较慢,随后在接近末端范围时加速下降,并且在该阶段下降幅度更大。 当你需要十分偏向最新的文档,并显著降低较旧文档的权重时,请使用这种插值方式。 标记评分函数中不允许使用此内插选项。
logarithmic 对数函数最初以更快的速度递减,然后当接近结束范围时,以较小的变化速率减少。 当你对最近的内容有强烈偏好,但随着文档变旧,对时间变化不那么敏感时,建议使用这种方式。 标记评分函数中不允许使用此内插选项。

365 天范围内的常量、线性、对数和二次内插的斜率形状示意图

为 freshness 函数设置 boostingDuration

boostingDuration 是 freshness 函数的属性。 使用它设置一个有效期,超过这个有效期之后,针对特定文档的提升将停止。 例如,要在 10 天促销期内提升某个产品系列或品牌,应针对这些文档将 10 天期限指定为 "P10D"。

boostingDuration 必须采用 XSD“dayTimeDuration”值格式(即 ISO 8601 持续时间值的一个受限子集)。 它的模式为:“P[nD][T[nH][nM][nS]]”。

下表提供几个示例。

Duration boostingDuration
1 天 "P1D"
2 天 12 小时 "P2DT12H"
15 分钟 "PT15M"
30 天 5 小时 10 分钟 6.334 秒 "P30DT5H10M6.334S"
1 年 “365D”

有关更多示例,请参阅 XML 架构:数据类型(W3.org 网站)。

示例:通过新鲜度或距离提升

提升曲线的形状(常量、线性、对数、二次)会影响得分在整个范围内变化的剧烈程度。

使用新鲜度函数时,如果希望对最近的日期有更显著的提升效果,请选择二次插值。 二次函数放大了最近日期和较近位置的影响,并在范围的远端以较慢的速度逐渐减小。 相比之下,对数曲线在远端更急剧地移动。

下面是一个示例评分配置,展示了如何基于新鲜度来提升分值。

{
    "name": "docs-index",
    "fields": [
      { "name": "id", "type": "Edm.String", "key": true, "filterable": true },
      { "name": "title", "type": "Edm.String", "searchable": true },
      { "name": "content", "type": "Edm.String", "searchable": true },
      { "name": "lastUpdated", "type": "Edm.DateTimeOffset", "filterable": true, "sortable": true }
    ],
    "scoringProfiles": [
      {
        "name": "freshnessBoost",
        "text": {
          "weights": {
            "content": 1.0
          }
        },
        "functions": [
          {
            "type": "freshness",
            "fieldName": "lastUpdated",
            "boost": 2.0,
            "interpolation": "quadratic",
            "parameters": {
              "boostingDuration": "P365D"
            }
          }
        ]
    }
  ]
}
  • 该 freshness 函数计算从“现在”到 lastUpdated 的幅度。
  • 当使用二次插值并设置正向加权时,最近日期的文档会获得更高的提升,而较旧的文档加权效果会迅速减弱。
  • "boostingDuration": "P365D" 定义了用于评估新鲜度的时间窗口,例如提升日期在过去一年内的文档的权重。
  • "interpolation": "quadratic" 这意味着,对于离当前日期更近的文档来说,提升效果更强,对于较旧的文档来说,效果会更加明显。

在下一个示例中,线性内插为 30 天时段内的最新内容提供了稳定的首选项。 如果需要让该信号在与其他相关性因素的竞争中占优势,可以提高加权幅度。

{
  "name": "freshness30_linear",
  "functions": [
    {
      "type": "freshness",
      "fieldName": "lastUpdated",
      "boost": 3.0,
      "interpolation": "linear",
      "parameters": { "boostingDuration": "P30D" }
    }
  ]
}

参考: freshness 函数 | boostingDuration

示例:通过加权文本和函数进行提升操作

Tip

请参阅此博客文章和笔记本,了解在矢量和生成式 AI 场景中使用评分配置文件和文档提升的演示。

以下示例演示具有两个计分概要文件的索引架构(boostGenre、newAndHighlyRated)。 针对此索引的任何查询(包含任一概要文件作为查询参数)将使用此概要文件对结果集进行计分。

boostGenre 概要文件使用加权文本字段来提升 albumTitle、genre 和 artistName 字段中找到的匹配项。 这些字段各自提升 1.5、5 和 2。 为什么“genre”的提升比其他字段高得多? 如果对有点同质的数据进行搜索(与 musicstoreindex 中的“流派”一样),则可能需要相对权重的较大方差。 例如,在 musicstoreindex 中,“rock”既作为流派显示,又显示在采用相同组句方式的流派说明中。 如果希望流派超过流派描述,流派字段需要更高的相对权重。

{  
  "name": "musicstoreindex",  
  "fields": [  
    { "name": "key", "type": "Edm.String", "key": true },  
    { "name": "albumTitle", "type": "Edm.String" },  
    { "name": "albumUrl", "type": "Edm.String", "filterable": false },  
    { "name": "genre", "type": "Edm.String" },  
    { "name": "genreDescription", "type": "Edm.String", "filterable": false },  
    { "name": "artistName", "type": "Edm.String" },  
    { "name": "orderableOnline", "type": "Edm.Boolean" },  
    { "name": "rating", "type": "Edm.Int32" },  
    { "name": "tags", "type": "Collection(Edm.String)" },  
    { "name": "price", "type": "Edm.Double", "filterable": false },  
    { "name": "margin", "type": "Edm.Int32", "retrievable": false },  
    { "name": "inventory", "type": "Edm.Int32" },  
    { "name": "lastUpdated", "type": "Edm.DateTimeOffset" }  
  ],  
  "scoringProfiles": [  
    {  
      "name": "boostGenre",  
      "text": {  
        "weights": {  
          "albumTitle": 1.5,  
          "genre": 5,  
          "artistName": 2  
        }  
      }  
    },  
    {  
      "name": "newAndHighlyRated",  
      "functions": [  
        {  
          "type": "freshness",  
          "fieldName": "lastUpdated",  
          "boost": -10,  
          "interpolation": "quadratic",  
          "freshness": {  
            "boostingDuration": "P365D"  
          }  
        },  
        {
          "type": "magnitude",  
          "fieldName": "rating",  
          "boost": 10,  
          "interpolation": "linear",  
          "magnitude": {  
            "boostingRangeStart": 1,  
            "boostingRangeEnd": 5,  
            "constantBoostBeyondRange": false  
          }  
        }  
      ]  
    }  
  ]
}  

示例:函数聚合

Note

此功能目前以预览版提供,可通过 latest preview REST API 和提供该功能的 Azure SDK 预览包提供。

在单个计分配置文件中,可以指定多个评分函数,然后设置 "functionAggregation": "product"。 对所有函数进行高度评分的文档处于优先顺序,同时取消在一个或多个字段中评分较弱的文档。

在此示例中,创建一个计分配置文件,其中包含两个提升函数,这些函数分别通过rating和baseRate进行提升,接着将functionAggregation设置为product。

### Create a new index
PUT {{url}}/indexes/hotels-scoring?api-version=2026-11-01-preview
Content-Type: application/json
api-key: {{key}}

{
    "name": "hotels-scoring",  
    "fields": [
        {"name": "HotelId", "type": "Edm.String", "key": true, "filterable": true, "facetable": true},
        {"name": "HotelName", "type": "Edm.String", "searchable": true, "filterable": false, "sortable": true, "facetable": true},
        {"name": "Description", "type": "Edm.String", "searchable": true, "filterable": false, "sortable": false, "facetable": true, "analyzer": "en.lucene"},
        {"name": "Category", "type": "Edm.String", "searchable": true, "filterable": true, "sortable": true, "facetable": true},
        {"name": "Tags", "type": "Collection(Edm.String)", "searchable": true, "filterable": true, "sortable": false, "facetable": true},
        {"name": "ParkingIncluded", "type": "Edm.Boolean", "filterable": true, "sortable": true, "facetable": true},
        {"name": "LastRenovationDate", "type": "Edm.DateTimeOffset", "filterable": true, "sortable": true, "facetable": true},
        {"name": "Rating", "type": "Edm.Double", "filterable": true, "sortable": true, "facetable": true},
        {"name": "BaseRate", "type": "Edm.Double", "filterable": true, "sortable": true, "facetable": true },
        {"name": "Address", "type": "Edm.ComplexType", 
            "fields": [
            {"name": "StreetAddress", "type": "Edm.String", "filterable": false, "sortable": false, "facetable": true, "searchable": true},
            {"name": "City", "type": "Edm.String", "searchable": true, "filterable": true, "sortable": true, "facetable": true},
            {"name": "StateProvince", "type": "Edm.String", "searchable": true, "filterable": true, "sortable": true, "facetable": true},
            {"name": "PostalCode", "type": "Edm.String", "searchable": true, "filterable": true, "sortable": true, "facetable": true}
            ]
        }
    ],
    "scoringProfiles": [
        {
            "name": "productAggregationProfile",
            "functions": [
                {
                    "type": "magnitude",
                    "fieldName": "Rating",
                    "boost": 2.0,
                    "interpolation": "linear",
                    "magnitude": {
                        "boostingRangeStart": 1.0,
                        "boostingRangeEnd": 5.0,
                        "constantBoostBeyondRange": false
                    }
                },
                {
                    "type": "magnitude",
                    "fieldName": "BaseRate",
                    "boost": 1.5,
                    "interpolation": "linear",
                    "magnitude": {
                        "boostingRangeStart": 50.0,
                        "boostingRangeEnd": 400.0,
                        "constantBoostBeyondRange": false
                    }
                }
            ],
            "functionAggregation": "product"
        }
    ],
    "defaultScoringProfile": "productAggregationProfile"
}

下一个请求将使用可搜索的内容加载索引,这些内容用于测试概况。

### Upload documents to the index
POST {{url}}/indexes/hotels-scoring/docs/index?api-version=2026-11-01-preview
Content-Type: application/json
api-key: {{key}}

  {
        "value": [
        {
        "@search.action": "upload",
        "HotelId": "1",
        "HotelName": "Stay-Kay City Hotel",
        "Description": "This classic hotel is fully-refurbished and ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Times Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",
        "Category": "Boutique",
        "Tags": [ "view", "air conditioning", "concierge" ],
        "ParkingIncluded": false,
        "LastRenovationDate": "2022-01-18T00:00:00Z",
        "Rating": 3.60,
        "BaseRate": 200.0,
        "Address": 
            {
            "StreetAddress": "677 5th Ave",
            "City": "New York",
            "StateProvince": "NY",
            "PostalCode": "10022"
            } 
        },
        {
        "@search.action": "upload",
        "HotelId": "2",
        "HotelName": "Old Century Hotel",
        "Description": "The hotel is situated in a nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts. The hotel also regularly hosts events like wine tastings, beer dinners, and live music.",
         "Category": "Boutique",
        "Tags": [ "pool", "free wifi", "concierge" ],
        "ParkingIncluded": false,
        "LastRenovationDate": "2019-02-18T00:00:00Z",
        "Rating": 3.60,
        "BaseRate": 150.0,
        "Address": 
            {
            "StreetAddress": "140 University Town Center Dr",
            "City": "Sarasota",
            "StateProvince": "FL",
            "PostalCode": "34243"
            } 
        },
        {
        "@search.action": "upload",
        "HotelId": "3",
        "HotelName": "Gastronomic Landscape Hotel",
        "Description": "The Gastronomic Landscape Hotel stands out for its culinary excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services.",
        "Category": "Suite",
        "Tags": [ "restaurant", "bar", "continental breakfast" ],
        "ParkingIncluded": true,
        "LastRenovationDate": "2015-09-20T00:00:00Z",
        "Rating": 4.80,
        "BaseRate": 350.0,
        "Address": 
            {
            "StreetAddress": "3393 Peachtree Rd",
            "City": "Atlanta",
            "StateProvince": "GA",
            "PostalCode": "30326"
            } 
        },
        {
        "@search.action": "upload",
        "HotelId": "4",
        "HotelName": "Sublime Palace Hotel",
        "Description": "Sublime Palace Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 19th century resort, updated for every modern convenience.",
        "Tags": [ "concierge", "view", "air conditioning" ],
        "ParkingIncluded": true,
        "LastRenovationDate": "2020-02-06T00:00:00Z",
        "Rating": 4.60,
        "BaseRate": 275.0,
        "Address": 
            {
            "StreetAddress": "7400 San Pedro Ave",
            "City": "San Antonio",
            "StateProvince": "TX",
            "PostalCode": "78216"
            }
        }
    ]
}

运行查询,使用计分概要文件中的条件根据高评分和高基础速率提升结果。 聚合提升分数,以进一步增强在这两个功能中均获得高分的结果。

### Search with boost
POST {{url}}/indexes/hotels-scoring/docs/search?api-version=2026-11-01-preview
Content-Type: application/json
api-key: {{key}}

{
    "search": "expensive and good hotels",
    "count": true,
    "select": "HotelId, HotelName, Description, Rating, BaseRate",
    "scoringProfile": "productAggregationProfile"
}

此查询的最高响应是“文体景观酒店”,搜索分数几乎是下一个最接近的匹配项的两倍。 这家特别的酒店具有最高的评级和最高的基价,因此两个函数的复合将推动该匹配位居榜首。

{
  "@odata.count": 4,
  "value": [
    {
      "@search.score": 1.0541908,
      "HotelId": "3",
      "HotelName": "Gastronomic Landscape Hotel",
      "Description": "The Gastronomic Hotel stands out for its culinary excellence under the management of William Dough, who advises on and oversees all of the Hotel\u2019s restaurant services.",
      "Rating": 4.8,
      "BaseRate": 350.0
    },
    {
      "@search.score": 0.53451097,
      "HotelId": "2",
      "HotelName": "Old Century Hotel",
      "Description": "The hotel is situated in a nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts. The hotel also regularly hosts events like wine tastings, beer dinners, and live music.",
      "Rating": 3.6,
      "BaseRate": 150.0
    },
    {
      "@search.score": 0.53185254,
      "HotelId": "1",
      "HotelName": "Stay-Kay City Hotel",
      "Description": "This classic hotel is fully-refurbished and ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Times Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",
      "Rating": 3.6,
      "BaseRate": 200.0
    },
    {
      "@search.score": 0.44853577,
      "HotelId": "4",
      "HotelName": "Sublime Palace Hotel",
      "Description": "Sublime Palace Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 19th century resort, updated for every modern convenience.",
      "Rating": 4.6,
      "BaseRate": 275.0
    }
  ]
}

调优建议

  • 开始保守:将范围提高到 1.25–2.0;只有当最新性真正具有决定性时才增加。

  • 窗口大小建议:P30D 适用于热点内容;P90D 或 P180D 适用于中等时效性内容;P365D 适用于长尾内容。

  • 内插选项:

    • 使用二次插值时,能对最近内容给予更强的加权。
    • 如果需要稳定渐变,则为线性。
    • 使用对数插值时,偏好较为温和。
  • 聚合:如果合并多个函数,则求和最简单;当希望单个信号主宰时切换到最大值

排查计分概要文件问题

使用下表诊断计分配置文件的常见问题。

問题 可能的原因 决议
未应用计分配置文件 未在查询中指定概要文件名称 使用确切的概要文件名称将 scoringProfile 参数添加到搜索请求。
未观察到提升效果 字段未标记为 filterable 函数只能应用于属性为 filterable的字段。 更新索引架构。
意外排名结果 提升值过低或过高 从 1.25–2.0 范围内的提升值开始,并根据测试进行调整。
新鲜度未提升最近文档 boostingDuration 过短或格式错误 验证持续时间格式(例如“P30D”为 30 天),并根据需要延长窗口。
距离函数不起作用 字段不是 Edm.GeographyPoint 距离函数仅适用于 Edm.GeographyPoint 字段。
标记函数未返回提升 标记与查询值不匹配 请确保tagsParameter与搜索请求的scoringParameters中的值相匹配。
配置文件存在,但查询失败 配置文件中的字段名称无效 确保评分配置文件中的所有字段名称都存在于索引架构中。