Skip to content

Commit

Permalink
Added support for ADDSCORES argument in FT.AGGREGATE (#3908)
Browse files Browse the repository at this point in the history
  • Loading branch information
uglide authored Jul 26, 2024
1 parent 0b04243 commit 7b121c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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, INDEXMISSING, INDEXEMPTY;
SEARCH, AGGREGATE, QUERY, LIMITED, COUNT, REDUCE, INDEXMISSING, INDEXEMPTY, ADDSCORES;

private final byte[] raw;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public AggregationBuilder timeout(long timeout) {
return this;
}

public AggregationBuilder addScores() {
aggrArgs.add(SearchKeyword.ADDSCORES);
return this;
}

public AggregationBuilder params(Map<String, Object> params) {
aggrArgs.add(SearchKeyword.PARAMS);
aggrArgs.add(params.size() << 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,23 @@ public void testAggregationBuilderVerbatim() {
assertEquals(0, res.getTotalResults());
}

@Test
public void testAggregationBuilderAddScores() {
Schema sc = new Schema();
sc.addSortableTextField("name", 1.0);
sc.addSortableNumericField("age");
client.ftCreate(index, IndexOptions.defaultOptions(), sc);
addDocument(new Document("data1").set("name", "Adam").set("age", 33));
addDocument(new Document("data2").set("name", "Sara").set("age", 44));

AggregationBuilder r = new AggregationBuilder("sara").addScores()
.apply("@__score * 100", "normalized_score").dialect(3);

AggregationResult res = client.ftAggregate(index, r);
assertEquals(2, res.getRow(0).getLong("__score"));
assertEquals(200, res.getRow(0).getLong("normalized_score"));
}

@Test
public void testAggregationBuilderTimeout() {
Schema sc = new Schema();
Expand Down

0 comments on commit 7b121c4

Please sign in to comment.