Can i exclude a 'highlight' field? Search Paramete...
# community-help
s
Can i exclude a 'highlight' field? Search Parameters
{
q: '8223',
query_by: [
'id_1',
'id_2',
],
filter_by: 'id_4:=23456',
exclude_fields: ['highlight'],
limit: 2
}
Result:
{
facet_counts: [],
found: 51,
hits: [
{
document: {
id: '50',
id_1: '82237e7b23c8d00c10',
id_2: '822352dd4972780d06',
id_3: '82237e7b98c8d01919',
id_4: '23456',
id_5: '8345937493845',
id_6: '947693749839',
id_7: '9834758374587',
id_8: '822399482342',
id_9: '893745876231'
},
highlight: {
id_1: {
matched_tokens: [ '8223' ],
snippet: '<mark>8223</mark>7e7b23c8d00c10'
},
id_2: {
matched_tokens: [ '8223' ],
snippet: '<mark>8223</mark>52dd4972780d06'
}
},
highlights: [
{
field: 'id_1',
matched_tokens: [ '8223' ],
snippet: '<mark>8223</mark>7e7b23c8d00c10'
},
{
field: 'id_2',
matched_tokens: [ '8223' ],
snippet: '<mark>8223</mark>52dd4972780d06'
}
],
text_match: 578730089005449300,
text_match_info: {
best_field_score: '1108074561536',
best_field_weight: 15,
fields_matched: 1,
num_tokens_dropped: 0,
score: '578730089005449337',
tokens_matched: 1,
typo_prefix_score: 1
}
},
{
document: {
id: '49',
id_1: '82237e7b23c8d00c10',
id_2: '822352dd4972780d06',
id_3: '82237e7b98c8d01919',
id_4: '23456',
id_5: '8345937493845',
id_6: '947693749839',
id_7: '9834758374587',
id_8: '822399482342',
id_9: '893745876231'
},
highlight: {
id_1: {
matched_tokens: [ '8223' ],
snippet: '<mark>8223</mark>7e7b23c8d00c10'
},
id_2: {
matched_tokens: [ '8223' ],
snippet: '<mark>8223</mark>52dd4972780d06'
}
},
highlights: [
{
field: 'id_1',
matched_tokens: [ '8223' ],
snippet: '<mark>8223</mark>7e7b23c8d00c10'
},
{
field: 'id_2',
matched_tokens: [ '8223' ],
snippet: '<mark>8223</mark>52dd4972780d06'
}
],
text_match: 578730089005449300,
text_match_info: {
best_field_score: '1108074561536',
best_field_weight: 15,
fields_matched: 1,
num_tokens_dropped: 0,
score: '578730089005449337',
tokens_matched: 1,
typo_prefix_score: 1
}
}
],
out_of: 51,
page: 1,
request_params: {
collection_name: 'sample',
first_q: '8223',
per_page: 2,
q: '8223'
},
search_cutoff: false,
search_time_ms: 0
}
k
You can only specify which fields to highlight via
highlight_fields
d
Hi @Kishore Nallan! I have a use case where I'd also like to exclude the "highlight" field to use "highlights" instead, though I know "highlights" is supposed to be deprecated. In my collection when performing exact searching on an array, the payload for "highlights" can be much smaller than "highlight" (see below for a quick example). If this was queried on long arrays, highlight would return elements with empty matched tokens as well...
Copy code
"highlight": {
    "arraystring": [
      {
        "matched_tokens": [],
        "snippet": "b b",
        "value": "b b"
      },
      {
        "matched_tokens": [
          "this",
          "is",
          "a",
          "test"
        ],
        "snippet": "<mark>this</mark> <mark>is</mark> <mark>a</mark> <mark>test</mark>",
        "value": "<mark>this</mark> <mark>is</mark> <mark>a</mark> <mark>test</mark>"
      },
      {
        "matched_tokens": [
          "a"
        ],
        "snippet": "<mark>a</mark> b c d e g",
        "value": "<mark>a</mark> b c d e g"
      },
      {
        "matched_tokens": [
          "test",
          "test"
        ],
        "snippet": "<mark>test</mark> <mark>test</mark>",
        "value": "<mark>test</mark> <mark>test</mark>"
      }
    ]
  },
  "highlights": [
    {
      "field": "arraystring",
      "indices": [
        1,
        2,
        3
      ],
      "matched_tokens": [
        [
          "this",
          "is",
          "a",
          "test"
        ],
        [
          "a"
        ],
        [
          "test",
          "test"
        ]
      ],
      "snippets": [
        "<mark>this</mark> <mark>is</mark> <mark>a</mark> <mark>test</mark>",
        "<mark>a</mark> b c d e g",
        "<mark>test</mark> <mark>test</mark>"
      ],
      "values": [
        "<mark>this</mark> <mark>is</mark> <mark>a</mark> <mark>test</mark>",
        "<mark>a</mark> b c d e g",
        "<mark>test</mark> <mark>test</mark>"
      ]
    }
k
It's not possible to get this behavior with the
highlight
object but we've an open issue to make this configurable: https://github.com/typesense/typesense/issues/962
d
Ah I see! Is there any current plan to address this in the near future? I noticed there was a recent tag on this.
k
We will prioritize for the next release, but no timeline yet.
d
Gotcha... in that case, I may be interested in implementing this within a fork for self hosting. I’ve been looking at the collection.cpp file and may have a good idea for a potential approach
k
Happy to accept a PR
👀 1