Add book and chapter titles to search API results #5280
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Add the ability to include book and chapter titles in the
/api/search
endpoint results through an optionalinclude
parameter. This makes it easier for API consumers to show the full content hierarchy context for search results without additional API calls.Closes
API Request #5140
Implementation
New Features
include
parameter to/api/search
endpointtitles
- Includesbook_title
andchapter_title
for applicable entitiestags
- Include associated tags (existing functionality now controlled viainclude
)Multiple includes can be combined using comma separation.(if we want to extend on it.)
Changes
ApiEntityListFormatter::withRelatedTitles()
,ApiEntityListFormatter::loadRelatedTitles()
andSearchApiController::parseIncludes()
method.SearchApiController::$rules
SearchApiController::all()
ApiEntityListFormatter::format()
Technical Details
include
for it to be included. This behavior if problematic can be altered easily.)Testing
New test cases cover:
All existing tests pass without modification.
Documentation
The API documentation has been edited as well to cater to the new changes.
Example Request
GET /api/search?query=example&include=titles,tags
Example Response
PS
This is my first-ever contribution to open source projects. I kindly ask for a thorough review, and I'm eager to improve upon any mistakes I may have made.