Regarding the storage of query parameter Code<T>.
https://github.com/FirelyTeam/spark/blob/d9889ad7003c91eabfc6a302416fdf1ef4de8766/src/Spark.Engine/Search/ElementIndexer.cs#L476-L479
https://github.com/FirelyTeam/spark/blob/d9889ad7003c91eabfc6a302416fdf1ef4de8766/src/Spark.Engine/Search/ElementIndexer.cs#L494-L507
Why is the storage design different between Code and Code<T>?
That's a good question that I do not really have a good answer to. I see this is code that was written before my time, and generally I have just let the stuff that supposedly work just stay that way.
Have you verified that they do indeed get stored differently to the searchindex? Admittedly it has passed some time since I last looked at this part of the code.
Yes, they are stored differently.
In patient resource, gender is code<T> type, and the storage structure in searchindex is { gender : { code : "male" } }.
In codesystem resource, the code of concept is code type, and the storage structure in searchindex is { code : [ "01" , "02"] }.
In the search standard of fhir, the types of code and code<T> are both token types, so should the mode of code<T> be used when storing?