Consider mapping API for Search synonym maps
Currently the methods to create or update synonym maps accepts lists of strings in Apache SOLR format, eg:
[
"U.S.,Unites States, USA",
"Washington,Wash=>WA",
]
The reasoning for this this is that in many "real world" usage scenarios synonyms will be specified in this format in files with hundred or thousands of lines. However, during the UX study, every participant commented that this API was "unpythonic" and expressed a preference for a dict/mapping option in the API. Perhaps it is worth adding a more Python convenience API for "simple" usage.
It's clear enough how the second case with a "directional" mapping can be accommodated:
{
"WA", ["Washington", "Wash"],
...
}
It's less clear how the first case where "everything is equally synonymous" could be handled. Perhaps with sets? Or perhaps only the second form gets the convenience treatment.
cc @xiangyan99 @heaths
The SOLR format is more expressive than that. That only works for some cases. In actuality, the service team has asked that we not have specialized support for things like this that only work in examples anyway. In practice, devs will be specifying the content of large files of these aliases and other things SOLR can do. So, you need to have methods that take a string (the entire content, new lines and all encoded) and, optionally, a buffer that is idiomatic to Python that would represent a file (not a path). Taking a list of strings or a dict should actually be removed as its not practical for anything other than simple examples.
Taking a list of strings or a dict should actually be removed as its not practical for anything other than simple examples.
But there will be some people who will actually have simple cases, and wouldn't start with having to create a file just to have to read a file. Are you saying we should go out of our way to make life more difficult for them?
FWIW, a text file in python is essentially a list of strings, e.g you could pass the result of fp.readlines() directly to the current API (which is why the current API is the way it is). I don't disagree that taking the entire contents as one with string with newlines is also a reasonable thing to do.
BTW:
The SOLR format is more expressive than that.
In that case the REST API docs are very confusing on this point, because the link to them I gave above states "The Apache Solr format supports equivalent and explicit synonym mappings" and directly shows only these two possibilities, not any others.
Even if Search only supports those two mappings, the ask from @brjohnstmsft was not to have something that only works for samples, i.e. the list of strings or a map. Practically, these would never be used as developers are importing thousands of them from a file, hence only a single string synonyms or a buffer representing a file.
You could still show a sample that builds a dict, serializes it to a string separated by newlines, and pass that as the sole synonyms string. I plan on doing something like that for C# samples:
// Practically, this content would normally come from a file, but as an example:
string[] synonyms = new[]
{
"Washington, Wash. => WA",
"AC, air cond. => air conditioning",
};
SynonymMap map = new SynonymMap("name", string.Join("\n", synonyms));
Per the guidelines, we should do what's idiomatic for the language, while balancing that with real-world usage. This observation is key:
FWIW, a text file in python is essentially a list of strings, e.g you could pass the result of fp.readlines() directly to the current API (which is why the current API is the way it is).
@bryevdv I think that's a fine reason for Python to be different and accept a list of strings, if that's more idiomatic. Accepting a dict really would be optimizing for samples though, as @heaths mentioned.
Close as won't fix. Will reopen if receiving customer requests.