Daniel
06/12/2021, 11:19 AM"hits": [
{
"highlights": [
{
"field": "company_name",
"snippet": "<mark>Stark</mark> Industries"
}
],
"document": {
"id": "124",
"company_name": "Stark Industries",
"num_employees": 5215,
"country": "USA"
}
}
]
Would the highlights ever include more than one highlight per field?
"highlights": [
{
"field": "content",
"snippet": "<mark>Hawaii</mark> is the big wave island."
},
{
"field": "content",
"snippet": "for the <mark>Hawaii</mark> surf competition."
}
],
This makes the frontend code a lot more complex as you need to parse the array and see if the field matches:
PSEUDO CODE
temp = result.highlights.filter(el => {
if el.field === my-field-name
})
if temp.length === 0
// print highlight
// if temp.length > 1
// print first instance or list all highlights for this field
// else print document.content
However if the highlights was returned as an object it would be a lot easier on the frontend:
<p>{{ result.highlights.content ?? result.document.content }}</p>
Kishore Nallan
06/12/2021, 11:21 AMWould the highlights ever include more than one highlight per field?When you are querying multiple fields, each matching field is highlighted.
Daniel
06/12/2021, 11:22 AMKishore Nallan
06/12/2021, 11:23 AMDaniel
06/12/2021, 11:24 AM"hits": [
{
"highlights": {
"company_name": {
"snippet": "<mark>Stark</mark> Industries",
...
},
"content": {
"snippet": "<mark>Hawaii</mark> is the big wave island.",
...
},
},
"document": {
"id": "124",
"company_name": "Stark Industries",
"num_employees": 5215,
"country": "USA"
}
}
]
}
Kishore Nallan
06/12/2021, 11:24 AMfield_name -> highlight
Daniel
06/12/2021, 11:25 AMDaniel
06/12/2021, 11:26 AMKishore Nallan
06/12/2021, 11:26 AMKishore Nallan
06/12/2021, 11:26 AMKishore Nallan
06/12/2021, 11:27 AMKishore Nallan
06/12/2021, 11:28 AMDaniel
06/12/2021, 11:29 AM*Ho-oponopono*
in my documents so I’m quite impressed that Typesense finds it.Kishore Nallan
06/12/2021, 11:32 AM