68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import { ApiExtraModels, ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
|
import { IsArray, IsDefined, IsInt, IsObject, IsOptional } from "class-validator";
|
|
import { EsPit } from "../../interfaces/elastic/es-pit.interface";
|
|
import { EsQuery } from "../../interfaces/elastic/es-query.interface"
|
|
|
|
/**
|
|
* List of allowed properties in this DTO
|
|
*/
|
|
const allowedProperties = ['query'];
|
|
|
|
/**
|
|
* Elasticsearch multi-match query DTO
|
|
*/
|
|
@ApiExtraModels()
|
|
export class EsMultimatchQueryDto {
|
|
/**
|
|
* Offset from the start of the list of hits
|
|
*/
|
|
@IsOptional()
|
|
@IsInt()
|
|
@ApiPropertyOptional({
|
|
description: 'Offset from the start of the list of hits',
|
|
example: 5,
|
|
})
|
|
public from?: number;
|
|
|
|
/**
|
|
* Maximum number of elements returned by Elasticsearch
|
|
*/
|
|
@IsOptional()
|
|
@IsInt()
|
|
@ApiPropertyOptional({
|
|
description: 'Maximum number of elements returned by Elasticsearch',
|
|
example: 30
|
|
})
|
|
public size?: number;
|
|
|
|
/**
|
|
* The search query object passed to Elasticsearch
|
|
*/
|
|
@IsDefined()
|
|
@IsObject()
|
|
@ApiProperty({
|
|
description: 'Search query object passed to Elasticsearch',
|
|
example: {
|
|
multi_match: {
|
|
query: 'Maths',
|
|
fields: [
|
|
'title',
|
|
'content'
|
|
]
|
|
}
|
|
},
|
|
})
|
|
private readonly query: Object;
|
|
|
|
/**
|
|
* Constructs a multi-match
|
|
*/
|
|
constructor(query: string = '', fields: Array<string> = ['content']) {
|
|
this.query = {
|
|
multi_match: {
|
|
query: query,
|
|
fields: fields
|
|
}
|
|
}
|
|
}
|
|
} |