typesense / typesense/typesense
Phrase query in double quotes returns hits but empty highlights
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 26.6k
- Forks
- 973
- Avg merge
- 18h 45m
- Merged PRs (30d)
- 4
Description
Bug Description
When searching with an exact phrase wrapped in double quotes (for example "apple"), Typesense returns matching documents (found > 0) but both highlights and highlight are empty.
The same query without quotes (apple) returns highlights correctly.
This appears to affect phrase search highlighting specifically.
Reproduction Steps
Unquoted query: q=apple (highlights expected and present)
curl -sS -G \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
"${TYPESENSE_HOST}/collections/${COLLECTION}/documents/search" \
--data-urlencode "q=apple" \
--data-urlencode "query_by=title,tags,content" \
--data-urlencode "per_page=1" \
--data-urlencode "highlight_full_fields=*" \
| jq '{found, highlights: .hits[0].highlights, highlight: .hits[0].highlight}'
Quoted phrase query: q="apple" (highlights expected but empty)
curl -sS -G \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
"${TYPESENSE_HOST}/collections/${COLLECTION}/documents/search" \
--data-urlencode "q=\"apple\"" \
--data-urlencode "query_by=title,tags,content" \
--data-urlencode "per_page=1" \
--data-urlencode "highlight_full_fields=*" \
| jq '{found, highlights: .hits[0].highlights, highlight: .hits[0].highlight}'
Same quoted query + highlight_query=apple (still empty in my tests)
curl -sS -G \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
"${TYPESENSE_HOST}/collections/${COLLECTION}/documents/search" \
--data-urlencode "q=\"apple\"" \
--data-urlencode "query_by=title,tags,content" \
--data-urlencode "per_page=1" \
--data-urlencode "highlight_full_fields=*" \
--data-urlencode "highlight_query=apple" \
| jq '{found, highlights: .hits[0].highlights, highlight: .hits[0].highlight}'
Expected vs Actual
Expected behavior
For exact phrase queries (wrapped in double quotes), matching documents should still return highlight snippets in hits[*].highlights / hits[*].highlight, similar to unquoted queries.
Actual behavior
Quoted phrase queries return matching hits (found > 0) but:
hits[0].highlightsis[]hits[0].highlightis{}
No error is returned; highlights are simply empty.
Environment
- Typesense version:
v30.1 - Operating system:
Linux x86_64(containerized setup) - Client library & version:
None (direct HTTP via curl)
(Also observed when called through Laravel Scout, but reproducible with curl alone.)
Schema / Configuration
Include any relevant schema definitions, JSON payloads, or config files:
{
"name": "phrase_highlight_bug_demo",
"fields": [
{ "name": "id", "type": "string" },
{ "name": "title", "type": "string" },
{ "name": "tags", "type": "string[]" },
{ "name": "content", "type": "string" }
]
}
Search parameters used in reproduction:
{
"query_by": "title,tags,content",
"highlight_full_fields": "*",
"per_page": 1
}
Additional Context
I also tested these parameters with the quoted query:
highlight_query=applehighlight_query="apple"highlight_strategy=alwaysenable_highlight_v1=true
In my tests, none of these restored highlights for the quoted phrase query.
If this is intended behavior, please clarify the recommended way to get highlights for exact phrase searches in a single request.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the quoted and unquoted curl requests against Typesense v30.1, then trace the phrase-search highlighting path in the search implementation. Done means an exact phrase such as "apple" returns matching documents with populated hits[].highlights and hits[].highlight, while the existing unquoted behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, search
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100