Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support indexing of MISSING and EMPTY values #3866

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void addParams(CommandArguments args) {
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/search/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void addParams(CommandArguments args) {

if (_params != null && _params.size() > 0) {
args.add(SearchKeyword.PARAMS.getRaw());
args.add(_params.size() * 2);
args.add(_params.size() << 1);
for (Map.Entry<String, Object> entry : _params.entrySet()) {
args.add(entry.getKey());
args.add(entry.getValue());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/search/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public VectorField(String name, VectorAlgo algorithm, Map<String, Object> attrib
@Override
public void addTypeArgs(CommandArguments args) {
args.add(algorithm);
args.add(attributes.size() * 2);
args.add(attributes.size() << 1);
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
args.add(entry.getKey());
args.add(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public enum SearchKeyword implements Rawable {
LANGUAGE_FIELD, SCORE, SCORE_FIELD, SCORER, PARAMS, AS, DIALECT, SLOP, TIMEOUT, INORDER,
EXPANDER, MAXTEXTFIELDS, SKIPINITIALSCAN, WITHSUFFIXTRIE, NOSTEM, NOINDEX, PHONETIC, WEIGHT,
CASESENSITIVE, LOAD, APPLY, GROUPBY, MAXIDLE, WITHCURSOR, DISTANCE, TERMS, INCLUDE, EXCLUDE,
SEARCH, AGGREGATE, QUERY, LIMITED, COUNT, REDUCE;
SEARCH, AGGREGATE, QUERY, LIMITED, COUNT, REDUCE, INDEXMISSING, INDEXEMPTY;

private final byte[] raw;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public AggregationBuilder limit(int count) {

public AggregationBuilder sortBy(SortedField... fields) {
aggrArgs.add(SearchKeyword.SORTBY);
aggrArgs.add(Integer.toString(fields.length * 2));
aggrArgs.add(fields.length << 1);
for (SortedField field : fields) {
aggrArgs.add(field.getField());
aggrArgs.add(field.getOrder());
Expand Down Expand Up @@ -172,7 +172,7 @@ public AggregationBuilder timeout(long timeout) {

public AggregationBuilder params(Map<String, Object> params) {
aggrArgs.add(SearchKeyword.PARAMS);
aggrArgs.add(params.size() * 2);
aggrArgs.add(params.size() << 1);
params.forEach((k, v) -> {
aggrArgs.add(k);
aggrArgs.add(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public QueryNode add(Node... nodes) {
protected boolean shouldParenthesize(Parenthesize mode) {
if (mode == Parenthesize.ALWAYS) {
return true;
}
if (mode == Parenthesize.NEVER) {
} else if (mode == Parenthesize.NEVER) {
return false;
} else {
return children.size() > 1;
}
return children.size() > 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package redis.clients.jedis.search.schemafields;

import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.GEO;
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.*;

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.search.FieldName;

public class GeoField extends SchemaField {

private boolean indexMissing;
private boolean sortable;
private boolean noIndex;

public GeoField(String fieldName) {
super(fieldName);
}
Expand All @@ -29,9 +33,36 @@ public GeoField as(String attribute) {
return this;
}

public GeoField indexMissing() {
this.indexMissing = true;
return this;
}

public GeoField sortable() {
this.sortable = true;
return this;
}

public GeoField noIndex() {
this.noIndex = true;
return this;
}

@Override
public void addParams(CommandArguments args) {
args.addParams(fieldName);
args.add(GEO);

if (indexMissing) {
args.add(INDEXMISSING);
}

if (sortable) {
args.add(SORTABLE);
}

if (noIndex) {
args.add(NOINDEX);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package redis.clients.jedis.search.schemafields;

import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.GEOSHAPE;
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.*;

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

private final CoordinateSystem system;

private boolean indexMissing;
private boolean noIndex;

public GeoShapeField(String fieldName, CoordinateSystem system) {
super(fieldName);
this.system = system;
Expand All @@ -42,8 +45,26 @@ public GeoShapeField as(String attribute) {
return this;
}

public GeoShapeField indexMissing() {
this.indexMissing = true;
return this;
}

public GeoShapeField noIndex() {
this.noIndex = true;
return this;
}

@Override
public void addParams(CommandArguments args) {
args.addParams(fieldName).add(GEOSHAPE).add(system);

if (indexMissing) {
args.add(INDEXMISSING);
}

if (noIndex) {
args.add(NOINDEX);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package redis.clients.jedis.search.schemafields;

import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.NOINDEX;
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.NUMERIC;
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.SORTABLE;
import static redis.clients.jedis.search.SearchProtocol.SearchKeyword.*;

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.search.FieldName;

public class NumericField extends SchemaField {

private boolean indexMissing;
private boolean sortable;
private boolean noIndex;

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

public NumericField indexMissing() {
this.indexMissing = true;
return this;
}

/**
* Sorts the results by the value of this field.
*/
Expand All @@ -55,6 +59,10 @@ public void addParams(CommandArguments args) {
args.addParams(fieldName);
args.add(NUMERIC);

if (indexMissing) {
args.add(INDEXMISSING);
}

if (sortable) {
args.add(SORTABLE);
}
Expand Down
78 changes: 50 additions & 28 deletions src/main/java/redis/clients/jedis/search/schemafields/TagField.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

public class TagField extends SchemaField {

private boolean sortable;
private boolean sortableUNF;
private boolean noIndex;
private boolean indexMissing;
private boolean indexEmpty;
private byte[] separator;
private boolean caseSensitive;
private boolean withSuffixTrie;
private boolean sortable;
private boolean sortableUNF;
private boolean noIndex;

public TagField(String fieldName) {
super(fieldName);
Expand All @@ -37,39 +39,19 @@ public TagField as(String attribute) {
return this;
}

/**
* Sorts the results by the value of this field.
*/
public TagField sortable() {
this.sortable = true;
return this;
}

/**
* Sorts the results by the value of this field without normalization.
*/
public TagField sortableUNF() {
this.sortableUNF = true;
public TagField indexMissing() {
this.indexMissing = true;
return this;
}

/**
* @see TextField#sortableUNF()
*/
public TagField sortableUnNormalizedForm() {
return sortableUNF();
}

/**
* Avoid indexing.
*/
public TagField noIndex() {
this.noIndex = true;
public TagField indexEmpty() {
this.indexEmpty = true;
return this;
}

/**
* Indicates how the text contained in the attribute is to be split into individual tags.
* @param separator
*/
public TagField separator(char separator) {
if (separator < 128) {
Expand Down Expand Up @@ -97,11 +79,51 @@ public TagField withSuffixTrie() {
return this;
}

/**
* Sorts the results by the value of this field.
*/
public TagField sortable() {
this.sortable = true;
return this;
}

/**
* Sorts the results by the value of this field without normalization.
*/
public TagField sortableUNF() {
this.sortableUNF = true;
return this;
}

/**
* @deprecated Use {@code TagField#sortableUNF()}.
* @see TagField#sortableUNF()
*/
@Deprecated
public TagField sortableUnNormalizedForm() {
return sortableUNF();
}

/**
* Avoid indexing.
*/
public TagField noIndex() {
this.noIndex = true;
return this;
}

@Override
public void addParams(CommandArguments args) {
args.addParams(fieldName);
args.add(TAG);

if (indexMissing) {
args.add(INDEXMISSING);
}
if (indexEmpty) {
args.add(INDEXEMPTY);
}

if (separator != null) {
args.add(SEPARATOR).add(separator);
}
Expand Down
Loading
Loading