启用 azure 搜索同义词
enable azure search synonyms
我正在尝试使用以下代码为某些字段启用同义词映射:
public ActionResult ConfigFieldToUseSynonyn()
{
string searchServiceName = "xxx";
string apiKey = "123123123123123123123123123";
SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(apiKey));
var index = serviceClient.Indexes.Get("produtos");
index.Fields[2].SynonymMaps = new string[] { "marca-synonymmap" };
index.Fields[7].SynonymMaps = new string[] { "marca-synonymmap" };
serviceClient.Indexes.CreateOrUpdate(index, accessCondition: AccessCondition.IfNotChanged(index));
return Content("OK");
}
并使用以下代码定义:
public ActionResult Synonym()
{
string searchServiceName = "xxx";
string apiKey = "123123123123123123123123123";
SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(apiKey));
var indexClient = serviceClient.Indexes.GetClient("produtos");
var synonymMap = new SynonymMap()
{
Name = "marca-synonymmap",
Format = "solr",
Synonyms = @"
dolve, douve => dove\n
"
};
serviceClient.SynonymMaps.CreateOrUpdate(synonymMap);
return Content("OK");
}
当我尝试使用 "dolve" 查找产品时,它没有映射到 "dove"。我错过了什么?
PS:那些字段是可搜索的并且是字符串类型的。
在synonymmap的定义中,'@'将字符串内容标记为逐字文字,规则变为dolve, douve => dove\n,以"\n"结尾。此同义词规则将查询 'dolve' 重写为 'dove\n'。如果您删除“@”前缀或删除同义词定义中的新行“\n”,同义词将按预期工作。
内特
我正在尝试使用以下代码为某些字段启用同义词映射:
public ActionResult ConfigFieldToUseSynonyn()
{
string searchServiceName = "xxx";
string apiKey = "123123123123123123123123123";
SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(apiKey));
var index = serviceClient.Indexes.Get("produtos");
index.Fields[2].SynonymMaps = new string[] { "marca-synonymmap" };
index.Fields[7].SynonymMaps = new string[] { "marca-synonymmap" };
serviceClient.Indexes.CreateOrUpdate(index, accessCondition: AccessCondition.IfNotChanged(index));
return Content("OK");
}
并使用以下代码定义:
public ActionResult Synonym()
{
string searchServiceName = "xxx";
string apiKey = "123123123123123123123123123";
SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(apiKey));
var indexClient = serviceClient.Indexes.GetClient("produtos");
var synonymMap = new SynonymMap()
{
Name = "marca-synonymmap",
Format = "solr",
Synonyms = @"
dolve, douve => dove\n
"
};
serviceClient.SynonymMaps.CreateOrUpdate(synonymMap);
return Content("OK");
}
当我尝试使用 "dolve" 查找产品时,它没有映射到 "dove"。我错过了什么?
PS:那些字段是可搜索的并且是字符串类型的。
在synonymmap的定义中,'@'将字符串内容标记为逐字文字,规则变为dolve, douve => dove\n,以"\n"结尾。此同义词规则将查询 'dolve' 重写为 'dove\n'。如果您删除“@”前缀或删除同义词定义中的新行“\n”,同义词将按预期工作。
内特