From 36bf17e3236a555e6d1193466141be880b280db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wieland=20Sch=C3=B6bl?= Date: Tue, 20 Aug 2019 14:39:24 +0200 Subject: [PATCH] feat: add support for @filterable tag --- src/mapping.ts | 17 +++++++++++++++-- src/mappings/definitions/fieldmap.ts | 9 ++++++++- src/mappings/mapping-definitions.ts | 4 ++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/mapping.ts b/src/mapping.ts index e82e4cb8..db2d97e0 100644 --- a/src/mapping.ts +++ b/src/mapping.ts @@ -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`); } diff --git a/src/mappings/definitions/fieldmap.ts b/src/mappings/definitions/fieldmap.ts index 9151b775..7937f1bf 100644 --- a/src/mappings/definitions/fieldmap.ts +++ b/src/mappings/definitions/fieldmap.ts @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ -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, +}; diff --git a/src/mappings/mapping-definitions.ts b/src/mappings/mapping-definitions.ts index 4f0635ed..2fda98b9 100644 --- a/src/mappings/mapping-definitions.ts +++ b/src/mappings/mapping-definitions.ts @@ -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 *