Skip to content

Commit 6db51a8

Browse files
committed
Support indexing of MISSING and EMPTY values (#3866)
1 parent df6d2f2 commit 6db51a8

File tree

13 files changed

+307
-85
lines changed

13 files changed

+307
-85
lines changed

Diff for: src/main/java/redis/clients/jedis/search/FTSearchParams.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void addParams(CommandArguments args) {
142142
}
143143

144144
if (params != null && !params.isEmpty()) {
145-
args.add(PARAMS).add(params.size() * 2);
145+
args.add(PARAMS).add(params.size() << 1);
146146
params.entrySet().forEach(entry -> args.add(entry.getKey()).add(entry.getValue()));
147147
}
148148

Diff for: src/main/java/redis/clients/jedis/search/Query.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public void addParams(CommandArguments args) {
292292

293293
if (_params != null && _params.size() > 0) {
294294
args.add(SearchKeyword.PARAMS.getRaw());
295-
args.add(_params.size() * 2);
295+
args.add(_params.size() << 1);
296296
for (Map.Entry<String, Object> entry : _params.entrySet()) {
297297
args.add(entry.getKey());
298298
args.add(entry.getValue());

Diff for: src/main/java/redis/clients/jedis/search/Schema.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public VectorField(String name, VectorAlgo algorithm, Map<String, Object> attrib
365365
@Override
366366
public void addTypeArgs(CommandArguments args) {
367367
args.add(algorithm);
368-
args.add(attributes.size() * 2);
368+
args.add(attributes.size() << 1);
369369
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
370370
args.add(entry.getKey());
371371
args.add(entry.getValue());

Diff for: src/main/java/redis/clients/jedis/search/SearchProtocol.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public enum SearchKeyword implements Rawable {
5656
LANGUAGE_FIELD, SCORE, SCORE_FIELD, SCORER, PARAMS, AS, DIALECT, SLOP, TIMEOUT, INORDER,
5757
EXPANDER, MAXTEXTFIELDS, SKIPINITIALSCAN, WITHSUFFIXTRIE, NOSTEM, NOINDEX, PHONETIC, WEIGHT,
5858
CASESENSITIVE, LOAD, APPLY, GROUPBY, MAXIDLE, WITHCURSOR, DISTANCE, TERMS, INCLUDE, EXCLUDE,
59-
SEARCH, AGGREGATE, QUERY, LIMITED, COUNT, REDUCE;
59+
SEARCH, AGGREGATE, QUERY, LIMITED, COUNT, REDUCE, INDEXMISSING, INDEXEMPTY;
6060

6161
private final byte[] raw;
6262

Diff for: src/main/java/redis/clients/jedis/search/aggr/AggregationBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public AggregationBuilder limit(int count) {
6666

6767
public AggregationBuilder sortBy(SortedField... fields) {
6868
aggrArgs.add(SearchKeyword.SORTBY);
69-
aggrArgs.add(Integer.toString(fields.length * 2));
69+
aggrArgs.add(fields.length << 1);
7070
for (SortedField field : fields) {
7171
aggrArgs.add(field.getField());
7272
aggrArgs.add(field.getOrder());
@@ -172,7 +172,7 @@ public AggregationBuilder timeout(long timeout) {
172172

173173
public AggregationBuilder params(Map<String, Object> params) {
174174
aggrArgs.add(SearchKeyword.PARAMS);
175-
aggrArgs.add(params.size() * 2);
175+
aggrArgs.add(params.size() << 1);
176176
params.forEach((k, v) -> {
177177
aggrArgs.add(k);
178178
aggrArgs.add(v);

Diff for: src/main/java/redis/clients/jedis/search/querybuilder/QueryNode.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public QueryNode add(Node... nodes) {
6161
protected boolean shouldParenthesize(Parenthesize mode) {
6262
if (mode == Parenthesize.ALWAYS) {
6363
return true;
64-
}
65-
if (mode == Parenthesize.NEVER) {
64+
} else if (mode == Parenthesize.NEVER) {
6665
return false;
66+
} else {
67+
return children.size() > 1;
6768
}
68-
return children.size() > 1;
6969
}
7070

7171
@Override

Diff for: src/main/java/redis/clients/jedis/search/schemafields/GeoField.java

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package redis.clients.jedis.search.schemafields;
22

3-
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.GEO;
3+
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.*;
44

55
import redis.clients.jedis.CommandArguments;
66
import redis.clients.jedis.search.FieldName;
77

88
public class GeoField extends SchemaField {
99

10+
private boolean indexMissing;
11+
private boolean sortable;
12+
private boolean noIndex;
13+
1014
public GeoField(String fieldName) {
1115
super(fieldName);
1216
}
@@ -29,9 +33,36 @@ public GeoField as(String attribute) {
2933
return this;
3034
}
3135

36+
public GeoField indexMissing() {
37+
this.indexMissing = true;
38+
return this;
39+
}
40+
41+
public GeoField sortable() {
42+
this.sortable = true;
43+
return this;
44+
}
45+
46+
public GeoField noIndex() {
47+
this.noIndex = true;
48+
return this;
49+
}
50+
3251
@Override
3352
public void addParams(CommandArguments args) {
3453
args.addParams(fieldName);
3554
args.add(GEO);
55+
56+
if (indexMissing) {
57+
args.add(INDEXMISSING);
58+
}
59+
60+
if (sortable) {
61+
args.add(SORTABLE);
62+
}
63+
64+
if (noIndex) {
65+
args.add(NOINDEX);
66+
}
3667
}
3768
}

Diff for: src/main/java/redis/clients/jedis/search/schemafields/GeoShapeField.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package redis.clients.jedis.search.schemafields;
22

3-
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.GEOSHAPE;
3+
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.*;
44

55
import redis.clients.jedis.CommandArguments;
66
import redis.clients.jedis.search.FieldName;
@@ -22,6 +22,9 @@ public enum CoordinateSystem {
2222

2323
private final CoordinateSystem system;
2424

25+
private boolean indexMissing;
26+
private boolean noIndex;
27+
2528
public GeoShapeField(String fieldName, CoordinateSystem system) {
2629
super(fieldName);
2730
this.system = system;
@@ -42,8 +45,26 @@ public GeoShapeField as(String attribute) {
4245
return this;
4346
}
4447

48+
public GeoShapeField indexMissing() {
49+
this.indexMissing = true;
50+
return this;
51+
}
52+
53+
public GeoShapeField noIndex() {
54+
this.noIndex = true;
55+
return this;
56+
}
57+
4558
@Override
4659
public void addParams(CommandArguments args) {
4760
args.addParams(fieldName).add(GEOSHAPE).add(system);
61+
62+
if (indexMissing) {
63+
args.add(INDEXMISSING);
64+
}
65+
66+
if (noIndex) {
67+
args.add(NOINDEX);
68+
}
4869
}
4970
}

Diff for: src/main/java/redis/clients/jedis/search/schemafields/NumericField.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package redis.clients.jedis.search.schemafields;
22

3-
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.NOINDEX;
4-
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.NUMERIC;
5-
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.SORTABLE;
3+
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.*;
64

75
import redis.clients.jedis.CommandArguments;
86
import redis.clients.jedis.search.FieldName;
97

108
public class NumericField extends SchemaField {
119

10+
private boolean indexMissing;
1211
private boolean sortable;
1312
private boolean noIndex;
1413

@@ -34,6 +33,11 @@ public NumericField as(String attribute) {
3433
return this;
3534
}
3635

36+
public NumericField indexMissing() {
37+
this.indexMissing = true;
38+
return this;
39+
}
40+
3741
/**
3842
* Sorts the results by the value of this field.
3943
*/
@@ -55,6 +59,10 @@ public void addParams(CommandArguments args) {
5559
args.addParams(fieldName);
5660
args.add(NUMERIC);
5761

62+
if (indexMissing) {
63+
args.add(INDEXMISSING);
64+
}
65+
5866
if (sortable) {
5967
args.add(SORTABLE);
6068
}

Diff for: src/main/java/redis/clients/jedis/search/schemafields/TagField.java

+50-28
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
public class TagField extends SchemaField {
1010

11-
private boolean sortable;
12-
private boolean sortableUNF;
13-
private boolean noIndex;
11+
private boolean indexMissing;
12+
private boolean indexEmpty;
1413
private byte[] separator;
1514
private boolean caseSensitive;
1615
private boolean withSuffixTrie;
16+
private boolean sortable;
17+
private boolean sortableUNF;
18+
private boolean noIndex;
1719

1820
public TagField(String fieldName) {
1921
super(fieldName);
@@ -37,39 +39,19 @@ public TagField as(String attribute) {
3739
return this;
3840
}
3941

40-
/**
41-
* Sorts the results by the value of this field.
42-
*/
43-
public TagField sortable() {
44-
this.sortable = true;
45-
return this;
46-
}
47-
48-
/**
49-
* Sorts the results by the value of this field without normalization.
50-
*/
51-
public TagField sortableUNF() {
52-
this.sortableUNF = true;
42+
public TagField indexMissing() {
43+
this.indexMissing = true;
5344
return this;
5445
}
5546

56-
/**
57-
* @see TextField#sortableUNF()
58-
*/
59-
public TagField sortableUnNormalizedForm() {
60-
return sortableUNF();
61-
}
62-
63-
/**
64-
* Avoid indexing.
65-
*/
66-
public TagField noIndex() {
67-
this.noIndex = true;
47+
public TagField indexEmpty() {
48+
this.indexEmpty = true;
6849
return this;
6950
}
7051

7152
/**
7253
* Indicates how the text contained in the attribute is to be split into individual tags.
54+
* @param separator
7355
*/
7456
public TagField separator(char separator) {
7557
if (separator < 128) {
@@ -97,11 +79,51 @@ public TagField withSuffixTrie() {
9779
return this;
9880
}
9981

82+
/**
83+
* Sorts the results by the value of this field.
84+
*/
85+
public TagField sortable() {
86+
this.sortable = true;
87+
return this;
88+
}
89+
90+
/**
91+
* Sorts the results by the value of this field without normalization.
92+
*/
93+
public TagField sortableUNF() {
94+
this.sortableUNF = true;
95+
return this;
96+
}
97+
98+
/**
99+
* @deprecated Use {@code TagField#sortableUNF()}.
100+
* @see TagField#sortableUNF()
101+
*/
102+
@Deprecated
103+
public TagField sortableUnNormalizedForm() {
104+
return sortableUNF();
105+
}
106+
107+
/**
108+
* Avoid indexing.
109+
*/
110+
public TagField noIndex() {
111+
this.noIndex = true;
112+
return this;
113+
}
114+
100115
@Override
101116
public void addParams(CommandArguments args) {
102117
args.addParams(fieldName);
103118
args.add(TAG);
104119

120+
if (indexMissing) {
121+
args.add(INDEXMISSING);
122+
}
123+
if (indexEmpty) {
124+
args.add(INDEXEMPTY);
125+
}
126+
105127
if (separator != null) {
106128
args.add(SEPARATOR).add(separator);
107129
}

0 commit comments

Comments
 (0)