MCPcopy Index your code
hub / github.com/angular/angular / parseResult

Method parseResult

adev/shared-docs/services/search.service.ts:89–128  ·  view source on GitHub ↗
(response: SearchResponses<unknown>)

Source from the content-addressed store, hash-verified

87 }
88
89 private parseResult(response: SearchResponses<unknown>): SearchResultItem[] | undefined {
90 if (!response) {
91 return;
92 }
93
94 const result: AlgoliaSearchResult = response.results[0];
95 if (!result || !('hits' in result)) {
96 return;
97 }
98
99 const items = result.hits as unknown as SearchResult[];
100
101 return this.getUniqueSearchResultItems(items).map((hitItem: SearchResult): SearchResultItem => {
102 const content = hitItem._snippetResult.content;
103 const hierarchy = hitItem._snippetResult.hierarchy;
104 const category = hitItem.hierarchy?.lvl0 ?? null;
105
106 const lvl1Value = hierarchy?.lvl1?.value || hitItem.hierarchy?.lvl1;
107
108 const sublabelSnippet = this.getBestSnippetForMatch(hitItem);
109
110 // If no lvl1, promote sublabel to label to avoid empty titles
111 const label = lvl1Value || sublabelSnippet || '';
112
113 const hasSubLabel = lvl1Value && (hierarchy?.lvl2 || hierarchy?.lvl3 || hierarchy?.lvl4);
114
115 return {
116 id: hitItem.objectID,
117 type: hitItem.hierarchy.lvl0 === 'Tutorials' ? 'code' : 'doc',
118 url: hitItem.url,
119
120 labelHtml: this.parseLabelToHtml(label),
121 subLabelHtml: this.parseLabelToHtml(hasSubLabel ? sublabelSnippet : null),
122 contentHtml: content ? this.parseLabelToHtml(content.value) : null,
123 package: category === 'Reference' ? extractPackageNameFromUrl(hitItem.url) : null,
124
125 category: hitItem.hierarchy?.lvl0 ?? null,
126 };
127 });
128 }
129
130 private getBestSnippetForMatch(result: SearchResult): string {
131 const hierarchy = result._snippetResult.hierarchy;

Callers 1

searchWithQueryMethod · 0.95

Calls 5

parseLabelToHtmlMethod · 0.95
mapMethod · 0.80

Tested by

no test coverage detected