ols4 icon indicating copy to clipboard operation
ols4 copied to clipboard

Add split synonym types to v1 search endpoint

Open Copilot opened this issue 1 month ago • 1 comments
trafficstars

Overview

This PR addresses the issue "Return synonyms in v1 search endpoint" by adding support for returning synonyms split into different OBO synonym types while maintaining full backward compatibility.

Changes Made

The v1 search API (/api/search) now supports four new optional fields in the fieldList parameter:

  • exact_synonyms - Returns exact synonyms from hasExactSynonym property
  • related_synonyms - Returns related synonyms from hasRelatedSynonym property
  • narrow_synonyms - Returns narrow synonyms from hasNarrowSynonym property
  • broad_synonyms - Returns broad synonyms from hasBroadSynonym property

Usage Examples

Request specific synonym types:

GET /api/search?q=disease&fieldList=iri,label,exact_synonyms,related_synonyms

Response:

{
  "response": {
    "docs": [
      {
        "iri": "http://example.org/disease",
        "label": "Disease",
        "exact_synonyms": ["illness", "disorder"],
        "related_synonyms": ["sickness"]
      }
    ]
  }
}

Backward compatibility maintained:

GET /api/search?q=disease&fieldList=iri,label,synonym

Response (unchanged):

{
  "response": {
    "docs": [
      {
        "iri": "http://example.org/disease",
        "label": "Disease", 
        "synonym": ["illness", "disorder", "sickness"]
      }
    ]
  }
}

Technical Details

  • Zero Breaking Changes: The existing synonym field remains completely unchanged
  • On-Demand Fields: New synonym type fields are only included when explicitly requested in fieldList
  • Leverages Existing Data: Uses the OBO synonym categorization already stored in the system through existing JsonHelper methods
  • Consistent Format: Returns arrays of strings matching the existing synonym field format

Files Changed

  • backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SearchController.java - Added handling for new synonym type fields and updated API documentation

The implementation is minimal and surgical, requiring only a few lines of code to expose the synonym categorization that was already present in the data but not accessible through the search API.

Original prompt

This section details on the original issue you should resolve

<issue_title>Return synonyms in v1 search endpoint</issue_title> <issue_description>Should be split into different types of synonym </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes EBISPOT/ols4#993

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Sep 26 '25 15:09 Copilot