Skip to content

Commit 2b4316f

Browse files
committed
fix & conditional output
1 parent 8e57f8d commit 2b4316f

File tree

4 files changed

+8
-22
lines changed

4 files changed

+8
-22
lines changed

.docker/docker-compose.yml

-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ services:
88
dockerfile: Dockerfile.test
99
volumes:
1010
- ../:/usr/src/app
11-
depends_on:
12-
- redis
1311
command: npm run test

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elasticsearch-dynamic-query",
3-
"version": "0.3.2",
3+
"version": "0.4.0",
44
"description": "A simple query builder, it will helps to develop DSL query for elasticsearch",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/parser/statement.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,7 @@ export class Statement {
116116
* type is Text, then add a Like condition to the conditions array
117117
*/
118118
private setEqCondition() {
119-
if ([DataTypeEnum.ID, DataTypeEnum.NUMBER, DataTypeEnum.BOOLEAN].includes(this.getType())) {
120-
this.setCondition(this.getEqCondition(this.data.conditions.$eq));
121-
}
122-
123-
if (this.getType() === DataTypeEnum.TEXT) {
124-
this.setLikeCondition(this.data.conditions.$eq);
125-
}
119+
this.setCondition(this.getEqCondition(this.data.conditions.$eq));
126120
}
127121

128122
/**
@@ -139,13 +133,7 @@ export class Statement {
139133
* data type is Text, then add a new NotLike condition to the conditions array
140134
*/
141135
private setNotEqCondition() {
142-
if ([DataTypeEnum.ID, DataTypeEnum.NUMBER, DataTypeEnum.BOOLEAN].includes(this.getType())) {
143-
this.condtions.push(new Neq(this.getKey(), this.data.conditions.$neq));
144-
}
145-
146-
if (this.getType() === DataTypeEnum.TEXT) {
147-
this.setNotLikeCondition(this.data.conditions.$neq);
148-
}
136+
this.condtions.push(new Neq(this.getKey(), this.data.conditions.$neq));
149137
}
150138

151139
/**

tests/compound-bool.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('$eq (TEXT) Conditional Operator', async () => {
2020
bool: {
2121
must: [
2222
{
23-
match: {
23+
term: {
2424
title: title
2525
}
2626
}
@@ -74,7 +74,7 @@ test('$neq (TEXT) Conditional Operator', async () => {
7474
bool: {
7575
must_not: [
7676
{
77-
match: {
77+
term: {
7878
title: title
7979
}
8080
}
@@ -680,7 +680,7 @@ test('$or (Partial) Conditional Operator', async () => {
680680
bool: {
681681
must: [
682682
{
683-
match: {
683+
term: {
684684
title: title
685685
}
686686
}
@@ -773,7 +773,7 @@ test('Multi Conditional Operator (1)', async () => {
773773
bool: {
774774
must: [
775775
{
776-
match: {
776+
term: {
777777
title: title
778778
}
779779
},
@@ -785,7 +785,7 @@ test('Multi Conditional Operator (1)', async () => {
785785
],
786786
must_not: [
787787
{
788-
match: {
788+
term: {
789789
title: anotherTitle
790790
}
791791
},

0 commit comments

Comments
 (0)