Skip to content

Commit

Permalink
fix & conditional output
Browse files Browse the repository at this point in the history
  • Loading branch information
hashemirafsan committed Sep 8, 2022
1 parent 8e57f8d commit 2b4316f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ services:
dockerfile: Dockerfile.test
volumes:
- ../:/usr/src/app
depends_on:
- redis
command: npm run test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elasticsearch-dynamic-query",
"version": "0.3.2",
"version": "0.4.0",
"description": "A simple query builder, it will helps to develop DSL query for elasticsearch",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
16 changes: 2 additions & 14 deletions src/parser/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,7 @@ export class Statement {
* type is Text, then add a Like condition to the conditions array
*/
private setEqCondition() {
if ([DataTypeEnum.ID, DataTypeEnum.NUMBER, DataTypeEnum.BOOLEAN].includes(this.getType())) {
this.setCondition(this.getEqCondition(this.data.conditions.$eq));
}

if (this.getType() === DataTypeEnum.TEXT) {
this.setLikeCondition(this.data.conditions.$eq);
}
this.setCondition(this.getEqCondition(this.data.conditions.$eq));
}

/**
Expand All @@ -139,13 +133,7 @@ export class Statement {
* data type is Text, then add a new NotLike condition to the conditions array
*/
private setNotEqCondition() {
if ([DataTypeEnum.ID, DataTypeEnum.NUMBER, DataTypeEnum.BOOLEAN].includes(this.getType())) {
this.condtions.push(new Neq(this.getKey(), this.data.conditions.$neq));
}

if (this.getType() === DataTypeEnum.TEXT) {
this.setNotLikeCondition(this.data.conditions.$neq);
}
this.condtions.push(new Neq(this.getKey(), this.data.conditions.$neq));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/compound-bool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('$eq (TEXT) Conditional Operator', async () => {
bool: {
must: [
{
match: {
term: {
title: title
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ test('$neq (TEXT) Conditional Operator', async () => {
bool: {
must_not: [
{
match: {
term: {
title: title
}
}
Expand Down Expand Up @@ -680,7 +680,7 @@ test('$or (Partial) Conditional Operator', async () => {
bool: {
must: [
{
match: {
term: {
title: title
}
}
Expand Down Expand Up @@ -773,7 +773,7 @@ test('Multi Conditional Operator (1)', async () => {
bool: {
must: [
{
match: {
term: {
title: title
}
},
Expand All @@ -785,7 +785,7 @@ test('Multi Conditional Operator (1)', async () => {
],
must_not: [
{
match: {
term: {
title: anotherTitle
}
},
Expand Down

0 comments on commit 2b4316f

Please sign in to comment.