private buildQueryString()

in source/packages/services/assetlibrary/src/search/search.lite.dao.ts [37:103]


    private buildQueryString(request: SearchRequestModel) : string {

        logger.debug(`search.lite.dao buildQueryString: in: request: ${JSON.stringify(request)}`);

        const filters: string[]= [];

        // if a group is provided, that becomes the starting point
        if (request.ancestorPath!==undefined) {
            const field = this.isDevice(request.types) ? 'thingGroupNames' : 'parentGroupNames';
            filters.push(`${field}:${request.ancestorPath}`);
        }

        // filtering by custom types
        if (this.isDevice(request.types)) {
            const customType = request.types.filter(t => t !== TypeCategory.Device && t !== TypeCategory.Group)[0];
            if (customType!==undefined && customType!==null) {
                filters.push(`thingTypeName:${customType}`);
            }
        }

        if (request.eq!==undefined) {
            Object.keys(request.eq).forEach( key => {
                filters.push(`${this.getFilterKey(key)}:${request.eq[key]}`);
            });
        }
        if (request.neq!==undefined) {
            Object.keys(request.neq).forEach( key => {
                filters.push(`NOT ${this.getFilterKey(key)}:${request.neq[key]}`);
            });
        }
        if (request.lt!==undefined) {
            Object.keys(request.lt).forEach( key => {
                filters.push(`${this.getFilterKey(key)}<${request.lt[key]}`);
            });
        }
        if (request.lte!==undefined) {
            Object.keys(request.lte).forEach( key => {
                filters.push(`${this.getFilterKey(key)}<=${request.lte[key]}`);
            });
        }
        if (request.gt!==undefined) {
            Object.keys(request.gt).forEach( key => {
                filters.push(`${this.getFilterKey(key)}>${request.gt[key]}`);
            });
        }
        if (request.gte!==undefined) {
            Object.keys(request.gte).forEach( key => {
                filters.push(`${this.getFilterKey(key)}>=${request.gte[key]}`);
            });
        }
        if (request.startsWith!==undefined) {
            Object.keys(request.startsWith).forEach(key => {
                filters.push(`${this.getFilterKey(key)}:${request.startsWith[key]}*`);
            });
        }
        if (request.endsWith!==undefined) {
            throw new Error('NOT_SUPPORTED');
        }
        if (request.contains!==undefined) {
            throw new Error('NOT_SUPPORTED');
        }

        const filtersAsString = filters.join(' ');
        logger.debug(`search.lite.dao buildQueryString: filters: ${filtersAsString}`);

        return filtersAsString;
    }