* In this function, you can use your custom Elastic Search query for the * full-text search feature. * * By default, Axe API uses a simple full-text search. * * @example * get getSearchQuery(params: IElasticSearchParameters) { * return { * // your query * }
(params: IElasticSearchParameters)
| 431 | * @tutorial https://axe-api.com/reference/model-get-search-query.html |
| 432 | */ |
| 433 | getSearchQuery(params: IElasticSearchParameters): any { |
| 434 | const { req, model, relation, parentModel, text } = params; |
| 435 | // Creating the basic search query |
| 436 | const query: any = { |
| 437 | bool: { |
| 438 | must: [ |
| 439 | { |
| 440 | query_string: { |
| 441 | query: `*${text}*`, |
| 442 | analyze_wildcard: true, |
| 443 | }, |
| 444 | }, |
| 445 | ], |
| 446 | }, |
| 447 | }; |
| 448 | |
| 449 | // If there is any parent query, we should be able to that parent conditions |
| 450 | // to the ElasticSearch query. |
| 451 | const parentIndexQuery = getParentIndexQuery(req, relation, parentModel); |
| 452 | if (Object.keys(parentIndexQuery).length > 0) { |
| 453 | query.bool.must.push({ |
| 454 | term: parentIndexQuery, |
| 455 | }); |
| 456 | } |
| 457 | |
| 458 | // If there is a deletedAtColumn, it means that this table support soft-delete |
| 459 | if (model.instance.deletedAtColumn) { |
| 460 | query.bool.must_not = { |
| 461 | exists: { |
| 462 | field: model.instance.deletedAtColumn, |
| 463 | }, |
| 464 | }; |
| 465 | } |
| 466 | |
| 467 | return { |
| 468 | query, |
| 469 | sort: [ |
| 470 | { |
| 471 | _score: { |
| 472 | order: "desc", |
| 473 | }, |
| 474 | }, |
| 475 | ], |
| 476 | }; |
| 477 | } |
| 478 | |
| 479 | private hasStringValue() { |
| 480 | const tester: Record<string, any> = this.validations; |
no test coverage detected