MCPcopy Create free account
hub / github.com/angular/angular / parseResult

Method parseResult

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

Source from the content-addressed store, hash-verified

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

Callers 1

searchWithQueryMethod · 0.95

Calls 5

parseLabelToHtmlMethod · 0.95
mapMethod · 0.80

Tested by

no test coverage detected