0

我正在尝试使用以下代码为某些字段启用同义词映射:

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:这些字段是可搜索的和字符串类型的。

4

1 回答 1

1

在同义词映射的定义中,'@' 将字符串内容标记为逐字字面量,并且规则变为 dolve,douve => dove\n,末尾带有“\n”。此同义词规则将查询“dolve”重写为“dove\n”。如果您删除“@”前缀或删除同义词定义中的新行“\n”,同义词将按预期工作。

内特

于 2018-08-20T22:18:05.993 回答