feat: exact match search

This commit is contained in:
Methapon2001 2023-12-14 15:35:18 +07:00
parent e65fb9f5d9
commit 6e9145e3cc
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
4 changed files with 26 additions and 4 deletions

View file

@ -15,12 +15,18 @@ export class SearchController extends Controller {
@Security("bearerAuth")
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
public async searchFile(@Body() search: Search): Promise<StorageFile[]> {
const type = ["match", "match_phrase"] as const;
const result = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
index: DEFAULT_INDEX,
query: {
bool: {
must: search.AND?.map((v) => ({ match: { [v.field]: v.value } })),
should: search.OR?.map((v) => ({ match: { [v.field]: v.value } })),
must: search.AND?.map((v) => ({
[type[search.exact || v.exact ? 1 : 0]]: { [v.field]: v.value },
})),
should: search.OR?.map((v) => ({
[type[search.exact || v.exact ? 1 : 0]]: { [v.field]: v.value },
})),
},
},
size: 10000,