0

I'm trying to enable a synonym map to some fields using the following code:

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

and the definition using the following code:

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

when I'm trying to find products using "dolve" it's not mapping to "dove". What am I missing?

PS: those fields are searchable and string type.

Jayendran
  • 9,638
  • 8
  • 60
  • 103
Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90

1 Answers1

1

In the definition of the synonymmap, the '@' marks the string content as a verbatim literal and the rule becomes dolve, douve => dove\n, with the "\n" in the end. This synonym rule rewrites the query 'dolve' to 'dove\n'. Synonyms will work as expected if you remove the '@' prefix or remove the new line '\n' in the synonym definition.

Nate

Nate Ko
  • 923
  • 5
  • 7