Automattic / Automattic/jetpack
Search API: improve highlight output
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
#### Is your feature request related to a problem? Please describe.
When working on the new product layout, we discovered that the `highlight` output from the site search endpoint does two unexpected things:
* When there is no search query, still returns a highlight
* Returns an array with an empty string (`[ "" ]`) rather than `null` when content is empty.

#### Describe the solution you'd like
* If no search query is specified, don't return a `highlight`.
* If highlight content is empty, return `null`.
#### Describe alternatives you've considered
We currently work around "When there is no search query, still returns a highlight" in the application itself by hiding the highlight when there is no search query (see https://github.com/Automattic/jetpack/pull/18868#issuecomment-805165772). We would rather the API dealt with this logic.
#### Additional context
Raised by @jsnmoon when working through feedback on https://github.com/Automattic/jetpack/pull/18868.
Contributor guide
Research direction
Start at the site search endpoint and trace how its highlight output is produced for requests without a query and for empty content. Confirm that no highlight is returned without a query and that empty highlight content is represented as null, then verify both response cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, search
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100