feat: add support for @filterable tag

This commit is contained in:
Wieland Schöbl
2019-08-20 14:39:24 +02:00
parent 8bb09994de
commit 36bf17e323
3 changed files with 27 additions and 3 deletions

View File

@@ -25,7 +25,7 @@ import {
Type, TypeParameterType,
UnionType,
} from 'typedoc/dist/lib/models';
import {fieldmap} from './mappings/definitions/fieldmap';
import {fieldmap, filterableMap, filterableTagName} from './mappings/definitions/fieldmap';
import {premaps} from './mappings/definitions/premap';
import {settings} from './mappings/definitions/settings';
import {dynamicTypes, ElasticsearchDataType, typemap} from './mappings/definitions/typemap';
@@ -335,7 +335,6 @@ function readFieldTags(prev: ElasticsearchValue, path: string, tags?: CommentTag
prev.fields = {};
}
if (tag.text.trim() === '') {
// merge the fields
prev.fields = {...prev.fields, ...fieldmap[tag.tagName].default};
} else if (typeof fieldmap[tag.tagName][tag.text.trim()] !== 'undefined') {
// merge the fields
@@ -343,6 +342,20 @@ function readFieldTags(prev: ElasticsearchValue, path: string, tags?: CommentTag
} else if (!fieldmap[tag.tagName].ignore.includes(tag.text.trim())) {
composeErrorMessage(path, 'tag', tag.tagName, `Not implemented tag param "${tag.text.trim()}"`);
}
} else if (tag.tagName === filterableTagName) {
if (typeof prev.fields === 'undefined') {
prev.fields = {};
}
if ('type' in prev) {
const type = filterableMap[prev.type];
if (typeof type !== 'undefined') {
prev.fields = {...prev.fields, ...{raw: {type: type}}};
} else {
composeErrorMessage(path, 'tag', tag.tagName, `Not implemented for ${prev.type}`);
}
} else {
composeErrorMessage(path, 'tag', tag.tagName, 'Not applicable for object types');
}
} else {
composeErrorMessage(path, 'tag', tag.tagName, `Not implemented tag`);
}

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ElasticsearchFieldmap} from '../mapping-definitions';
import {ElasticsearchFieldmap, ElasticsearchFilterableMap} from '../mapping-definitions';
import {ElasticsearchDataType} from './typemap';
export enum analyzers {
@@ -48,3 +48,10 @@ export const fieldmap: ElasticsearchFieldmap = {
ignore: ['price'],
},
};
export const filterableTagName = 'filterable';
export const filterableMap: ElasticsearchFilterableMap = {
date: ElasticsearchDataType.keyword,
text: ElasticsearchDataType.keyword,
};

View File

@@ -109,6 +109,10 @@ export interface ElasticsearchDynamicTemplate {
};
}
export interface ElasticsearchFilterableMap {
[name: string]: ElasticsearchDataType;
}
/**
* The Fieldmap contains all tag names for fields and the corresponding fields
*