mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(docs-infra): add member name to search index without ignore list (#46060)
Previously classs, interface and enum members where filtered with the default word ignore list. This lead to poor search results if a search for a member on the ignore list was performed. PR Close #46060
This commit is contained in:
committed by
Alex Rickabaugh
parent
45ed2b7584
commit
42db488ed7
@@ -27,6 +27,8 @@ module.exports = function generateKeywordsProcessor(log) {
|
||||
|
||||
const dictionary = new Map();
|
||||
|
||||
const emptySet = new Set();
|
||||
|
||||
// Keywords to ignore
|
||||
const ignoreWords = new Set(this.ignoreWords);
|
||||
log.debug('Words to ignore', ignoreWords);
|
||||
@@ -53,7 +55,7 @@ module.exports = function generateKeywordsProcessor(log) {
|
||||
}
|
||||
}
|
||||
|
||||
const memberTokens = extractMemberTokens(doc, ignoreWords, dictionary);
|
||||
const memberTokens = extractMemberTokens(doc, dictionary);
|
||||
|
||||
// Extract all the keywords from the headings
|
||||
let headingTokens = [];
|
||||
@@ -161,22 +163,22 @@ module.exports = function generateKeywordsProcessor(log) {
|
||||
tokens.push(dictionary.get(token));
|
||||
}
|
||||
|
||||
function extractMemberTokens(doc, ignoreWords, dictionary) {
|
||||
function extractMemberTokens(doc, dictionary) {
|
||||
if (!doc) return [];
|
||||
|
||||
let memberContent = [];
|
||||
|
||||
if (doc.members) {
|
||||
doc.members.forEach(member => memberContent.push(...tokenize(member.name, ignoreWords, dictionary)));
|
||||
doc.members.forEach(member => memberContent.push(...tokenize(member.name, emptySet, dictionary)));
|
||||
}
|
||||
if (doc.statics) {
|
||||
doc.statics.forEach(member => memberContent.push(...tokenize(member.name, ignoreWords, dictionary)));
|
||||
doc.statics.forEach(member => memberContent.push(...tokenize(member.name, emptySet, dictionary)));
|
||||
}
|
||||
if (doc.extendsClauses) {
|
||||
doc.extendsClauses.forEach(clause => memberContent.push(...extractMemberTokens(clause.doc, ignoreWords, dictionary)));
|
||||
doc.extendsClauses.forEach(clause => memberContent.push(...extractMemberTokens(clause.doc, dictionary)));
|
||||
}
|
||||
if (doc.implementsClauses) {
|
||||
doc.implementsClauses.forEach(clause => memberContent.push(...extractMemberTokens(clause.doc, ignoreWords, dictionary)));
|
||||
doc.implementsClauses.forEach(clause => memberContent.push(...extractMemberTokens(clause.doc, dictionary)));
|
||||
}
|
||||
|
||||
return memberContent;
|
||||
|
||||
@@ -176,6 +176,40 @@ describe('generateKeywords processor', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should add member doc properties contained in the ignored word list to the search terms', async () => {
|
||||
const processor = createProcessor();
|
||||
const docs = await processor.$process([
|
||||
{
|
||||
docType: 'class',
|
||||
name: 'PublicExport',
|
||||
searchTitle: 'class PublicExport',
|
||||
vFile: { headings: { h2: ['heading A'] } },
|
||||
content: 'Some content with ngClass in it.',
|
||||
members: [
|
||||
{ name: 'some' },
|
||||
{ name: 'none' },
|
||||
{ name: 'get' },
|
||||
{ name: 'put' },
|
||||
],
|
||||
statics: [
|
||||
{ name: 'zero' },
|
||||
{ name: 'one' },
|
||||
{ name: 'next' },
|
||||
{ name: 'index' },
|
||||
],
|
||||
},
|
||||
]);
|
||||
const keywordsDoc = docs[docs.length - 1];
|
||||
expect(keywordsDoc.data).toEqual({
|
||||
dictionary: 'class publicexport content ngclass some none get put zero on next index head',
|
||||
pages: [
|
||||
jasmine.objectContaining({
|
||||
members: [4, 5, 6, 7, 8, 9, 10, 11]
|
||||
})
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it('should add inherited member doc properties to the search terms', async () => {
|
||||
const processor = createProcessor();
|
||||
const parentClass = {
|
||||
@@ -229,6 +263,60 @@ describe('generateKeywords processor', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should add inherited member doc properties contained in the ignored word list to the search terms', async () => {
|
||||
const processor = createProcessor();
|
||||
const parentClass = {
|
||||
docType: 'class',
|
||||
name: 'ParentClass',
|
||||
members: [
|
||||
{ name: 'one' },
|
||||
],
|
||||
statics: [
|
||||
{ name: 'zero' },
|
||||
],
|
||||
};
|
||||
const parentInterface = {
|
||||
docType: 'interface',
|
||||
name: 'ParentInterface',
|
||||
members: [
|
||||
{ name: 'index' },
|
||||
]
|
||||
};
|
||||
|
||||
const childClass = {
|
||||
docType: 'class',
|
||||
name: 'Child',
|
||||
members: [
|
||||
{ name: 'next' }
|
||||
],
|
||||
statics: [
|
||||
{ name: 'get' }
|
||||
],
|
||||
extendsClauses: [{ doc: parentClass }],
|
||||
implementsClauses: [{ doc: parentInterface }]
|
||||
};
|
||||
const docs = await processor.$process([childClass, parentClass, parentInterface]);
|
||||
const keywordsDoc = docs[docs.length - 1];
|
||||
expect(keywordsDoc.data).toEqual({
|
||||
dictionary: 'class child next get on zero index parentclass interfac parentinterfac',
|
||||
pages: [
|
||||
jasmine.objectContaining({
|
||||
title: 'Child',
|
||||
members: [2, 3, 4, 5, 6]
|
||||
}),
|
||||
jasmine.objectContaining({
|
||||
title: 'ParentClass',
|
||||
members: [4, 5]
|
||||
}),
|
||||
jasmine.objectContaining({
|
||||
title: 'ParentInterface',
|
||||
members: [6]
|
||||
})
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it('should include both stripped and unstripped "ng" prefixed tokens', async () => {
|
||||
const processor = createProcessor();
|
||||
const docs = await processor.$process([
|
||||
|
||||
Reference in New Issue
Block a user