MCPcopy Create free account
hub / github.com/github/docs / getHighlightConfiguration

Function getHighlightConfiguration

middleware/api/es-search.js:394–428  ·  view source on GitHub ↗
(query, highlights)

Source from the content-addressed store, hash-verified

392// many highlights in the search result UI, we can come back here
393// and change it to something more appropriate.
394function getHighlightConfiguration(query, highlights) {
395 const fields = {}
396 if (highlights.includes('title')) {
397 fields.title = {
398 fragment_size: 200,
399 number_of_fragments: 1,
400 }
401 }
402 if (highlights.includes('headings')) {
403 fields.headings = { fragment_size: 150, number_of_fragments: 2 }
404 }
405 if (highlights.includes('content')) {
406 // The 'no_match_size' is so we can display *something* for the
407 // preview if there was no highlight match at all within the content.
408 fields.content = {
409 fragment_size: 150,
410 number_of_fragments: 1,
411 no_match_size: 150,
412
413 highlight_query: {
414 match_phrase_prefix: {
415 content: {
416 query,
417 },
418 },
419 },
420 }
421 }
422
423 return {
424 pre_tags: ['<mark>'],
425 post_tags: ['</mark>'],
426 fields,
427 }
428}

Callers 1

getSearchResultsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected