feat: exact match search
This commit is contained in:
parent
e65fb9f5d9
commit
6e9145e3cc
4 changed files with 26 additions and 4 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue