-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29406 from cescoffier/redis-labs-auto-suggest
- Loading branch information
Showing
24 changed files
with
1,059 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...nt/runtime/src/main/java/io/quarkus/redis/datasource/autosuggest/AutoSuggestCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package io.quarkus.redis.datasource.autosuggest; | ||
|
||
import java.util.List; | ||
|
||
import io.quarkus.redis.datasource.RedisCommands; | ||
|
||
/** | ||
* Allows executing commands from the {@code auto-suggest} group (requires the Redis Search module from Redis stack). | ||
* See <a href="https://redis.io/commands/?group=suggestion">the auto-suggest command list</a> for further information about | ||
* these | ||
* commands. | ||
* | ||
* @param <K> the type of the key | ||
*/ | ||
public interface AutoSuggestCommands<K> extends RedisCommands { | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugadd/">FT.SUGADD</a>. | ||
* Summary: Add a suggestion string to an auto-complete suggestion dictionary | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param string the suggestion string to index | ||
* @param score the floating point number of the suggestion string's weight | ||
* @return A uni emitting the current size of the suggestion dictionary. | ||
*/ | ||
default long ftSugAdd(K key, String string, double score) { | ||
return ftSugAdd(key, string, score, false); | ||
} | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugadd/">FT.SUGADD</a>. | ||
* Summary: Add a suggestion string to an auto-complete suggestion dictionary | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param string the suggestion string to index | ||
* @param score the floating point number of the suggestion string's weight | ||
* @param increment increments the existing entry of the suggestion by the given score, instead of replacing the score. | ||
* This is useful for updating the dictionary based on user queries in real time. | ||
* @return A uni emitting the current size of the suggestion dictionary. | ||
*/ | ||
long ftSugAdd(K key, String string, double score, boolean increment); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugdel/">FT.SUGDEL</a>. | ||
* Summary: Delete a string from a suggestion index | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param string the suggestion string to index | ||
* @return A uni emitting {@code true} if the value was found, {@code false} otherwise | ||
*/ | ||
boolean ftSugDel(K key, String string); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugget/">FT.SUGGET</a>. | ||
* Summary: Get completion suggestions for a prefix | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param prefix is prefix to complete on. | ||
* @return A uni emitting a list of the top suggestions matching the prefix, optionally with score after each entry. | ||
*/ | ||
List<Suggestion> ftSugGet(K key, String prefix); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugget/">FT.SUGGET</a>. | ||
* Summary: Get completion suggestions for a prefix | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param prefix is prefix to complete on. | ||
* @param args the extra argument, must not be {@code null} | ||
* @return A uni emitting {@code true} if the value was found, {@code false} otherwise | ||
*/ | ||
List<Suggestion> ftSugGet(K key, String prefix, GetArgs args); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.suglen/">FT.SUGLEN</a>. | ||
* Summary: Get the size of an auto-complete suggestion dictionary | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @return A uni emitting the current size of the suggestion dictionary. | ||
*/ | ||
long ftSugLen(K key); | ||
} |
68 changes: 68 additions & 0 deletions
68
...s/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/autosuggest/GetArgs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.quarkus.redis.datasource.autosuggest; | ||
|
||
import static io.quarkus.redis.runtime.datasource.Validation.positive; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import io.quarkus.redis.datasource.RedisCommandExtraArguments; | ||
|
||
public class GetArgs implements RedisCommandExtraArguments { | ||
|
||
private boolean fuzzy; | ||
private int max; | ||
private boolean withScores; | ||
|
||
/** | ||
* Performs a fuzzy prefix search, including prefixes at Levenshtein distance of 1 from the prefix sent. | ||
* | ||
* @return the current {@code GetArgs}. | ||
*/ | ||
public GetArgs fuzzy() { | ||
this.fuzzy = true; | ||
return this; | ||
} | ||
|
||
/** | ||
* Limits the results to a maximum of num (default: 5). | ||
* | ||
* @param max the max number of results, must be strictly positive | ||
* @return the current {@code GetArgs}. | ||
*/ | ||
public GetArgs max(int max) { | ||
positive(max, "max"); | ||
this.max = max; | ||
return this; | ||
} | ||
|
||
/** | ||
* Also to attach the score of each suggestion. | ||
* This can be used to merge results from multiple instances. | ||
* | ||
* @return the current {@code GetArgs}. | ||
*/ | ||
public GetArgs withScores() { | ||
this.withScores = true; | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<String> toArgs() { | ||
List<String> list = new ArrayList<>(); | ||
if (fuzzy) { | ||
list.add("FUZZY"); | ||
} | ||
if (max > 0) { | ||
list.add("MAX"); | ||
list.add(Integer.toString(max)); | ||
} | ||
if (withScores) { | ||
list.add("WITHSCORES"); | ||
} | ||
return list; | ||
} | ||
|
||
public boolean hasScores() { | ||
return withScores; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...me/src/main/java/io/quarkus/redis/datasource/autosuggest/ReactiveAutoSuggestCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package io.quarkus.redis.datasource.autosuggest; | ||
|
||
import java.util.List; | ||
|
||
import io.quarkus.redis.datasource.ReactiveRedisCommands; | ||
import io.smallrye.common.annotation.Experimental; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
/** | ||
* Allows executing commands from the {@code auto-suggest} group (requires the Redis Search module from Redis stack). | ||
* See <a href="https://redis.io/commands/?group=suggestion">the auto-suggest command list</a> for further information about | ||
* these commands. | ||
* | ||
* @param <K> the type of the key | ||
*/ | ||
@Experimental("The auto-suggest group is experimental") | ||
public interface ReactiveAutoSuggestCommands<K> extends ReactiveRedisCommands { | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugadd/">FT.SUGADD</a>. | ||
* Summary: Add a suggestion string to an auto-complete suggestion dictionary | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param string the suggestion string to index | ||
* @param score the floating point number of the suggestion string's weight | ||
* @return A uni emitting the current size of the suggestion dictionary. | ||
**/ | ||
default Uni<Long> ftSugAdd(K key, String string, double score) { | ||
return ftSugAdd(key, string, score, false); | ||
} | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugadd/">FT.SUGADD</a>. | ||
* Summary: Add a suggestion string to an auto-complete suggestion dictionary | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param string the suggestion string to index | ||
* @param score the floating point number of the suggestion string's weight | ||
* @param increment increments the existing entry of the suggestion by the given score, instead of replacing the score. | ||
* This is useful for updating the dictionary based on user queries in real time. | ||
* @return A uni emitting the current size of the suggestion dictionary. | ||
**/ | ||
Uni<Long> ftSugAdd(K key, String string, double score, boolean increment); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugdel/">FT.SUGDEL</a>. | ||
* Summary: Delete a string from a suggestion index | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param string the suggestion string to index | ||
* @return A uni emitting {@code true} if the value was found, {@code false} otherwise | ||
**/ | ||
Uni<Boolean> ftSugDel(K key, String string); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugget/">FT.SUGGET</a>. | ||
* Summary: Get completion suggestions for a prefix | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param prefix is prefix to complete on. | ||
* @return A uni emitting a list of the top suggestions matching the prefix, optionally with score after each entry. | ||
**/ | ||
Uni<List<Suggestion>> ftSugGet(K key, String prefix); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.sugget/">FT.SUGGET</a>. | ||
* Summary: Get completion suggestions for a prefix | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @param prefix is prefix to complete on. | ||
* @param args the extra argument, must not be {@code null} | ||
* @return A uni emitting {@code true} if the value was found, {@code false} otherwise | ||
**/ | ||
Uni<List<Suggestion>> ftSugGet(K key, String prefix, GetArgs args); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/ft.suglen/">FT.SUGLEN</a>. | ||
* Summary: Get the size of an auto-complete suggestion dictionary | ||
* Group: auto-suggest | ||
* | ||
* @param key the suggestion dictionary key | ||
* @return A uni emitting the current size of the suggestion dictionary. | ||
**/ | ||
Uni<Long> ftSugLen(K key); | ||
|
||
} |
Oops, something went wrong.