
committed by
Kara Erickson

parent
9931bd7576
commit
96f9f03d25
@ -31,9 +31,6 @@ module.exports = function generateKeywordsProcessor(log, readFilesProcessor) {
|
||||
var propertiesToIgnore;
|
||||
var docTypesToIgnore;
|
||||
|
||||
// Keywords start with "ng:" or one of $, _ or a letter
|
||||
var KEYWORD_REGEX = /^((ng:|[$_a-z])[\w\-_]+)/;
|
||||
|
||||
// Load up the keywords to ignore, if specified in the config
|
||||
if (this.ignoreWordsFile) {
|
||||
var ignoreWordsPath = path.resolve(readFilesProcessor.basePath, this.ignoreWordsFile);
|
||||
@ -52,20 +49,33 @@ module.exports = function generateKeywordsProcessor(log, readFilesProcessor) {
|
||||
|
||||
// If the heading contains a name starting with ng, e.g. "ngController", then add the
|
||||
// name without the ng to the text, e.g. "controller".
|
||||
function preprocessText(text) {
|
||||
return text.replace(/(^|\s)([nN]g([A-Z]\w*))/g, '$1$2 $3');
|
||||
function tokenize(text) {
|
||||
const rawTokens = text.split(/[\s\/]+/mg);
|
||||
const tokens = [];
|
||||
rawTokens.forEach(token => {
|
||||
// Strip off unwanted trivial characters
|
||||
token = token
|
||||
.trim()
|
||||
.replace(/^[_\-"'`({[<$*)}\]>.]+/, '')
|
||||
.replace(/[_\-"'`({[<$*)}\]>.]+$/, '');
|
||||
// Ignore tokens that contain weird characters
|
||||
if (/^[\w.\-]+$/.test(token)) {
|
||||
tokens.push(token.toLowerCase());
|
||||
const ngTokenMatch = /^[nN]g([A-Z]\w*)/.exec(token);
|
||||
if (ngTokenMatch) {
|
||||
tokens.push(ngTokenMatch[1].toLowerCase());
|
||||
}
|
||||
}
|
||||
});
|
||||
return tokens;
|
||||
}
|
||||
|
||||
function extractWords(text, words, keywordMap) {
|
||||
var tokens = preprocessText(text).toLowerCase().split(/[.\s,`'"#]+/mg);
|
||||
var tokens = tokenize(text);
|
||||
tokens.forEach(function(token) {
|
||||
var match = token.match(KEYWORD_REGEX);
|
||||
if (match) {
|
||||
var key = match[1];
|
||||
if (!keywordMap[key]) {
|
||||
keywordMap[key] = true;
|
||||
words.push(key);
|
||||
}
|
||||
if (!keywordMap[token]) {
|
||||
words.push(token);
|
||||
keywordMap[token] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -116,7 +126,7 @@ module.exports = function generateKeywordsProcessor(log, readFilesProcessor) {
|
||||
|
||||
// Attach all this search data to the document
|
||||
doc.searchTerms = {
|
||||
titleWords: preprocessText(doc.searchTitle),
|
||||
titleWords: tokenize(doc.searchTitle).join(' '),
|
||||
headingWords: headingWords.sort().join(' '),
|
||||
keywords: words.sort().join(' '),
|
||||
members: members.sort().join(' ')
|
||||
|
@ -80,7 +80,7 @@ describe('generateKeywords processor', () => {
|
||||
];
|
||||
processor.$process(docs);
|
||||
const keywordsDoc = docs[docs.length - 1];
|
||||
expect(keywordsDoc.data[0].titleWords).toEqual('class PublicExport');
|
||||
expect(keywordsDoc.data[0].titleWords).toEqual('class publicexport');
|
||||
});
|
||||
|
||||
it('should add heading words to the search terms', () => {
|
||||
@ -141,7 +141,7 @@ describe('generateKeywords processor', () => {
|
||||
];
|
||||
processor.$process(docs);
|
||||
const keywordsDoc = docs[docs.length - 1];
|
||||
expect(keywordsDoc.data[0].titleWords).toEqual('ngController Controller');
|
||||
expect(keywordsDoc.data[0].titleWords).toEqual('ngcontroller controller');
|
||||
expect(keywordsDoc.data[0].headingWords).toEqual('model ngmodel');
|
||||
expect(keywordsDoc.data[0].keywords).toContain('class');
|
||||
expect(keywordsDoc.data[0].keywords).toContain('ngclass');
|
||||
@ -163,7 +163,7 @@ describe('generateKeywords processor', () => {
|
||||
[{
|
||||
'title':'SomeClass',
|
||||
'type':'class',
|
||||
'titleWords':'SomeClass',
|
||||
'titleWords':'someclass',
|
||||
'headingWords':'heading some someclass',
|
||||
'keywords':'api class documentation for is someclass the',
|
||||
'members':''
|
||||
|
Reference in New Issue
Block a user