ols4
ols4 copied to clipboard
Fix local parameter to use isDefiningOntology and remove confusing imported field
The local parameter in the search API was not working correctly. When set to true, it should only return terms that are defined in their own ontology (e.g., only EFO terms when searching within EFO), but it was incorrectly returning imported terms from other ontologies like HP.
Root Cause
The implementation in V1SearchController.java was using the imported field to filter results:
if (isLocal) {
solrQuery.addFilterQuery(IMPORTED.getText() + ":false");
}
However, the imported field indicates whether an entity was loaded via owl:import, which is not useful for this purpose because:
- Many ontologies import parts of themselves from separate files
- Many ontologies that reference terms don't use
owl:imports
Solution
Changed the filter to use the isDefiningOntology field instead:
if (isLocal) {
solrQuery.addFilterQuery(IS_DEFINING_ONTOLOGY.getText() + ":true");
}
The isDefiningOntology field correctly identifies whether an entity is actually defined in the specific ontology being searched, which is exactly what the local parameter should filter on.
Additionally, completely removed the confusing imported field from the codebase since it was no longer needed and was causing confusion:
- Removed
IMPORTEDfield definition fromDefinedFields.java - Removed all logic that sets the imported property in
OntologyGraph.javaduring data loading - Updated 508 test expected output files to remove the imported field from JSON responses
Verification
- The
V1SelectControlleralready uses this correct implementation, confirming the approach - Code compiles successfully after removing all imported field references
- Field definitions confirm
isDefiningOntologymeans "Whether this entity is defined in this ontology or not"
Expected Result
Search queries like https://www.ebi.ac.uk/ols4/api/search?q=asthma&ontology=efo&local=true will now correctly return only EFO terms and exclude HP terms or other imported terms. The confusing imported field will no longer appear in API responses.
Fixes #879.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.