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

Function getSearchResults

middleware/api/es-search.js:33–163  ·  view source on GitHub ↗
({
  indexName,
  query,
  page,
  size,
  debug,
  sort,
  topics,
  includeTopics,
  usePrefixSearch,
  highlights,
})

Source from the content-addressed store, hash-verified

31
32// The true work horse that actually performs the Elasticsearch query
33export async function getSearchResults({
34 indexName,
35 query,
36 page,
37 size,
38 debug,
39 sort,
40 topics,
41 includeTopics,
42 usePrefixSearch,
43 highlights,
44}) {
45 if (topics && !Array.isArray(topics)) {
46 throw new Error("'topics' has to be an array")
47 }
48 const t0 = new Date()
49 const client = getClient()
50 const from = size * (page - 1)
51
52 const matchQueries = getMatchQueries(query.trim(), {
53 usePrefixSearch,
54 fuzzy: {
55 minLength: 3,
56 maxLength: 20,
57 },
58 })
59
60 const matchQuery = {
61 bool: {
62 should: matchQueries,
63 },
64 }
65
66 const topicsFilter = (topics || []).map((topic) => {
67 return {
68 term: {
69 // Remember, 'topics' is a keyword field, meaning you need
70 // to filter by "Webhooks", not "webhooks"
71 topics: topic,
72 },
73 }
74 })
75 if (topicsFilter.length) {
76 matchQuery.bool.filter = topicsFilter
77 }
78
79 const highlightFields = highlights || DEFAULT_HIGHLIGHT_FIELDS
80 const highlight = getHighlightConfiguration(query, highlightFields)
81
82 const searchQuery = {
83 highlight,
84 from,
85 size,
86
87 // COMMENTED out because of ES 7.11.
88 // Once we're on ES >7.11 we can add this option in.
89 // // Since we know exactly which fields from the source we're going
90 // // need we can specify that here. It's an inclusion list.

Callers

nothing calls this directly

Calls 4

getClientFunction · 0.85
getMatchQueriesFunction · 0.85
getHitsFunction · 0.85

Tested by

no test coverage detected