99from marshmallow import ValidationError
1010import json
1111import numpy as np
12+ from urllib .parse import unquote
1213from .solr_result_cache import with_solr_cache
1314
1415# Custom JSON encoder to handle NumPy and pandas types
@@ -311,14 +312,13 @@ def __str__(self):
311312
312313def encode_brackets (text ):
313314 """
314- Encodes brackets in the given text.
315+ Encodes square brackets in the given text to prevent breaking markdown link syntax.
316+ Parentheses are NOT encoded as they don't break markdown syntax.
315317
316318 :param text: The text to encode.
317- :return: The text with brackets encoded.
319+ :return: The text with square brackets encoded.
318320 """
319- return (text .replace ('(' , '%28' )
320- .replace (')' , '%29' )
321- .replace ('[' , '%5B' )
321+ return (text .replace ('[' , '%5B' )
322322 .replace (']' , '%5D' ))
323323
324324def encode_markdown_links (df , columns ):
@@ -1055,12 +1055,16 @@ def _get_instances_from_solr(short_form: str, return_dataframe=True, limit: int
10551055 template_label = template_anatomy .get ('label' , '' )
10561056 if template_anatomy .get ('symbol' ) and len (template_anatomy .get ('symbol' , '' )) > 0 :
10571057 template_label = template_anatomy .get ('symbol' )
1058+ # Decode URL-encoded strings from SOLR (e.g., ME%28R%29 -> ME(R))
1059+ template_label = unquote (template_label )
10581060 template_short_form = template_anatomy .get ('short_form' , '' )
10591061
10601062 # Prefer symbol over label for anatomy (matching Neo4j behavior)
10611063 anatomy_label = anatomy .get ('label' , '' )
10621064 if anatomy .get ('symbol' ) and len (anatomy .get ('symbol' , '' )) > 0 :
10631065 anatomy_label = anatomy .get ('symbol' )
1066+ # Decode URL-encoded strings from SOLR (e.g., ME%28R%29 -> ME(R))
1067+ anatomy_label = unquote (anatomy_label )
10641068 anatomy_short_form = anatomy .get ('short_form' , '' )
10651069
10661070 if template_label and anatomy_label :
@@ -1077,6 +1081,8 @@ def _get_instances_from_solr(short_form: str, return_dataframe=True, limit: int
10771081 template_label = template_anatomy .get ('label' , '' )
10781082 if template_anatomy .get ('symbol' ) and len (template_anatomy .get ('symbol' , '' )) > 0 :
10791083 template_label = template_anatomy .get ('symbol' )
1084+ # Decode URL-encoded strings from SOLR (e.g., ME%28R%29 -> ME(R))
1085+ template_label = unquote (template_label )
10801086 template_short_form = template_anatomy .get ('short_form' , '' )
10811087 if template_label and template_short_form :
10821088 template_formatted = f"[{ template_label } ]({ template_short_form } )"
@@ -1085,6 +1091,8 @@ def _get_instances_from_solr(short_form: str, return_dataframe=True, limit: int
10851091 anatomy_label = anatomy .get ('label' , 'Unknown' )
10861092 if anatomy .get ('symbol' ) and len (anatomy .get ('symbol' , '' )) > 0 :
10871093 anatomy_label = anatomy .get ('symbol' )
1094+ # Decode URL-encoded strings from SOLR (e.g., ME%28R%29 -> ME(R))
1095+ anatomy_label = unquote (anatomy_label )
10881096 anatomy_short_form = anatomy .get ('short_form' , '' )
10891097
10901098 row = {
0 commit comments