Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Commit

Permalink
added no-option methods to API
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Jun 8, 2020
1 parent f3f6fd3 commit 02f72ad
Show file tree
Hide file tree
Showing 31 changed files with 724 additions and 521 deletions.
20 changes: 7 additions & 13 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,16 @@ Usage example:
RediSearchClient client = RediSearchClient.create("redis://localhost"); //<1>
StatefulRediSearchConnection<String, String> connection = client.connect(); //<2>
RediSearchCommands<String, String> commands = connection.sync(); //<3>
Schema schema = Schema.builder().field(TextField.builder().name("field1").build())….build(); //<4>
CreateOptions options = CreateOptions.builder()….build();
commands.create("beerIdx", schema, options); //<5>
Document<String, String> doc = Document.<String, String>builder().id("123").score(1D).build(); //<6>
doc.put("name", "La Chouffe");
commands.add("beerIdx", doc, AddOptions.builder().build()); //<7>
SearchResults<String, String> results = commands.search("beerIdx", "chou*"); //<8>
commands.create(INDEX, Schema.builder().field(TextField.builder().name(NAME).build()).build()); //<4>
commands.add(INDEX, Document.builder().id(ID).score(1D).field(NAME, "La Chouffe").build()); //<5>
SearchResults<String, String> results = commands.search(INDEX, "chou*"); //<6>
----
<1> Create a RediSearch client
<2> Establish a connection to RediSearch
<2> Connect to RediSearch
<3> Use _sync_, _async_, or _reactive_ API
<4> Create a schema
<5> Create an index with the schema
<6> Create a document
<7> Add document to the index
<8> Search the index
<4> Create an index
<5> Add a document to the index
<6> Search the index

== Architecture
LettuSearch implements RediSearch commands using the https://lettuce.io/core/5.0.1.RELEASE/reference/#_custom_commands[Command abstraction] provided by Lettuce.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.1.2
version=2.2.0
102 changes: 53 additions & 49 deletions src/main/java/com/redislabs/lettusearch/RediSearchCommandBuilder.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,5 @@
package com.redislabs.lettusearch;

import static com.redislabs.lettusearch.protocol.CommandKeyword.COUNT;
import static com.redislabs.lettusearch.protocol.CommandKeyword.DD;
import static com.redislabs.lettusearch.protocol.CommandKeyword.INCR;
import static com.redislabs.lettusearch.protocol.CommandKeyword.NOCONTENT;
import static com.redislabs.lettusearch.protocol.CommandKeyword.PAYLOAD;
import static com.redislabs.lettusearch.protocol.CommandKeyword.READ;
import static com.redislabs.lettusearch.protocol.CommandKeyword.SCHEMA;
import static com.redislabs.lettusearch.protocol.CommandKeyword.WITHCURSOR;
import static com.redislabs.lettusearch.protocol.CommandKeyword.WITHPAYLOADS;
import static com.redislabs.lettusearch.protocol.CommandKeyword.WITHSCORES;
import static com.redislabs.lettusearch.protocol.CommandType.ADD;
import static com.redislabs.lettusearch.protocol.CommandType.AGGREGATE;
import static com.redislabs.lettusearch.protocol.CommandType.ALIASADD;
import static com.redislabs.lettusearch.protocol.CommandType.ALIASDEL;
import static com.redislabs.lettusearch.protocol.CommandType.ALIASUPDATE;
import static com.redislabs.lettusearch.protocol.CommandType.ALTER;
import static com.redislabs.lettusearch.protocol.CommandType.CREATE;
import static com.redislabs.lettusearch.protocol.CommandType.CURSOR;
import static com.redislabs.lettusearch.protocol.CommandType.DEL;
import static com.redislabs.lettusearch.protocol.CommandType.DROP;
import static com.redislabs.lettusearch.protocol.CommandType.GET;
import static com.redislabs.lettusearch.protocol.CommandType.INFO;
import static com.redislabs.lettusearch.protocol.CommandType.MGET;
import static com.redislabs.lettusearch.protocol.CommandType.SEARCH;
import static com.redislabs.lettusearch.protocol.CommandType.SUGADD;
import static com.redislabs.lettusearch.protocol.CommandType.SUGDEL;
import static com.redislabs.lettusearch.protocol.CommandType.SUGGET;
import static com.redislabs.lettusearch.protocol.CommandType.SUGLEN;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.redislabs.lettusearch.aggregate.AggregateOptions;
import com.redislabs.lettusearch.aggregate.AggregateResults;
import com.redislabs.lettusearch.aggregate.AggregateWithCursorResults;
Expand All @@ -41,12 +8,7 @@
import com.redislabs.lettusearch.index.DropOptions;
import com.redislabs.lettusearch.index.Schema;
import com.redislabs.lettusearch.index.field.FieldOptions;
import com.redislabs.lettusearch.output.AggregateOutput;
import com.redislabs.lettusearch.output.AggregateWithCursorOutput;
import com.redislabs.lettusearch.output.MapListOutput;
import com.redislabs.lettusearch.output.SearchNoContentOutput;
import com.redislabs.lettusearch.output.SearchOutput;
import com.redislabs.lettusearch.output.SuggestOutput;
import com.redislabs.lettusearch.output.*;
import com.redislabs.lettusearch.protocol.CommandKeyword;
import com.redislabs.lettusearch.protocol.CommandType;
import com.redislabs.lettusearch.protocol.RediSearchCommandArgs;
Expand All @@ -56,19 +18,22 @@
import com.redislabs.lettusearch.search.SearchResults;
import com.redislabs.lettusearch.suggest.Suggestion;
import com.redislabs.lettusearch.suggest.SuggetOptions;

import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.output.BooleanOutput;
import io.lettuce.core.output.CommandOutput;
import io.lettuce.core.output.IntegerOutput;
import io.lettuce.core.output.MapOutput;
import io.lettuce.core.output.NestedMultiOutput;
import io.lettuce.core.output.StatusOutput;
import io.lettuce.core.output.*;
import io.lettuce.core.protocol.BaseRedisCommandBuilder;
import io.lettuce.core.protocol.Command;
import io.lettuce.core.protocol.CommandArgs;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import static com.redislabs.lettusearch.protocol.CommandKeyword.*;
import static com.redislabs.lettusearch.protocol.CommandType.ADD;
import static com.redislabs.lettusearch.protocol.CommandType.DEL;
import static com.redislabs.lettusearch.protocol.CommandType.*;

/**
* Dedicated pub/sub command builder to build pub/sub commands.
*/
Expand All @@ -83,7 +48,11 @@ public RediSearchCommandBuilder(RedisCodec<K, V> codec) {

protected <A, B, T> Command<A, B, T> createCommand(CommandType type, CommandOutput<A, B, T> output,
CommandArgs<A, B> args) {
return new Command<A, B, T>(type, output, args);
return new Command<>(type, output, args);
}

public Command<K, V, String> add(K index, Document<K, V> document) {
return add(index, document, null);
}

public Command<K, V, String> add(K index, Document<K, V> document, AddOptions options) {
Expand All @@ -110,6 +79,10 @@ public Command<K, V, String> add(K index, Document<K, V> document, AddOptions op
return createCommand(ADD, new StatusOutput<>(codec), args);
}

public Command<K, V, String> create(K index, Schema schema) {
return create(index, schema, null);
}

public Command<K, V, String> create(K index, Schema schema, CreateOptions options) {
assertNotNull(index, "index");
assertNotNull(schema, "schema");
Expand All @@ -121,6 +94,10 @@ public Command<K, V, String> create(K index, Schema schema, CreateOptions option
return createCommand(CREATE, new StatusOutput<>(codec), args);
}

public Command<K, V, String> drop(K index) {
return drop(index, null);
}

public Command<K, V, String> drop(K index, DropOptions options) {
assertNotNull(index, "index");
RediSearchCommandArgs<K, V> args = createArgs(index);
Expand Down Expand Up @@ -152,6 +129,10 @@ private RediSearchCommandArgs<K, V> createArgs(K index) {
return new RediSearchCommandArgs<>(codec).addKey(index);
}

public Command<K, V, SearchResults<K, V>> search(K index, V query) {
return search(index, query, (SearchOptions) null);
}

public Command<K, V, SearchResults<K, V>> search(K index, V query, SearchOptions options) {
assertNotNull(index, "index");
assertNotNull(query, "query");
Expand Down Expand Up @@ -195,14 +176,17 @@ public Command<K, V, SearchResults<K, V>> search(K index, V query, Object... opt
return createCommand(SEARCH, getSearchOutput(codec, noContent, withScores, withPayloads), commandArgs);
}

private CommandOutput<K, V, SearchResults<K, V>> getSearchOutput(RedisCodec<K, V> codec, boolean noContent,
boolean withScores, boolean withPayloads) {
private CommandOutput<K, V, SearchResults<K, V>> getSearchOutput(RedisCodec<K, V> codec, boolean noContent, boolean withScores, boolean withPayloads) {
if (noContent) {
return new SearchNoContentOutput<>(codec, withScores);
}
return new SearchOutput<>(codec, withScores, withPayloads);
}

public Command<K, V, AggregateResults<K, V>> aggregate(K index, V query) {
return aggregate(index, query, (AggregateOptions) null);
}

public Command<K, V, AggregateResults<K, V>> aggregate(K index, V query, AggregateOptions options) {
assertNotNull(index, "index");
assertNotNull(query, "query");
Expand Down Expand Up @@ -257,6 +241,14 @@ public Command<K, V, AggregateWithCursorResults<K, V>> aggregate(K index, V quer
return createCommand(AGGREGATE, new AggregateWithCursorOutput<>(codec), args);
}

public Command<K, V, AggregateWithCursorResults<K, V>> cursorRead(K index, long cursor) {
return cursorRead(index, cursor, null);
}

public Command<K, V, AggregateWithCursorResults<K, V>> cursorRead(K index, long cursor, long count) {
return cursorRead(index, cursor, (Long) count);
}

public Command<K, V, AggregateWithCursorResults<K, V>> cursorRead(K index, long cursor, Long count) {
assertNotNull(index, "index");
RediSearchCommandArgs<K, V> args = new RediSearchCommandArgs<>(codec);
Expand All @@ -279,6 +271,10 @@ public Command<K, V, String> cursorDelete(K index, long cursor) {
return createCommand(CURSOR, new StatusOutput<>(codec), args);
}

public Command<K, V, Long> sugadd(K key, Suggestion<V> suggestion) {
return sugadd(key, suggestion, false);
}

public Command<K, V, Long> sugadd(K key, Suggestion<V> suggestion, boolean increment) {
assertNotNull(key, "key");
assertNotNull(suggestion.getString(), "suggestion string");
Expand All @@ -297,6 +293,10 @@ public Command<K, V, Long> sugadd(K key, Suggestion<V> suggestion, boolean incre
return createCommand(SUGADD, new IntegerOutput<>(codec), args);
}

public Command<K, V, List<Suggestion<V>>> sugget(K key, V prefix) {
return sugget(key, prefix, null);
}

public Command<K, V, List<Suggestion<V>>> sugget(K key, V prefix, SuggetOptions options) {
assertNotNull(key, "key");
assertNotNull(prefix, "prefix");
Expand Down Expand Up @@ -342,6 +342,10 @@ private void assertNotNull(Object arg, String name) {
LettuceAssert.notNull(arg, name + " " + MUST_NOT_BE_NULL);
}

public Command<K, V, Boolean> del(K index, K docId) {
return del(index, docId, false);
}

public Command<K, V, Boolean> del(K index, K docId, boolean deleteDoc) {
assertNotNull(index, "index");
assertNotNull(docId, "docId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public <K, V> void build(RediSearchCommandArgs<K, V> args) {
args.add(GROUPBY);
args.add(properties.size());
properties.forEach(property -> args.addProperty(property));
properties.forEach(args::addProperty);
reducers.forEach(reducer -> reducer.build(args));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@
*/
public interface AggregateAsyncCommands<K, V> {

RedisFuture<AggregateResults<K, V>> aggregate(K index, V query);

RedisFuture<AggregateResults<K, V>> aggregate(K index, V query, AggregateOptions options);

RedisFuture<AggregateResults<K, V>> aggregate(K index, V query, Object... options);

RedisFuture<AggregateWithCursorResults<K, V>> aggregate(K index, V query, Cursor cursor,
AggregateOptions options);
RedisFuture<AggregateWithCursorResults<K, V>> aggregate(K index, V query, Cursor cursor);

RedisFuture<AggregateWithCursorResults<K, V>> aggregate(K index, V query, Cursor cursor, AggregateOptions options);

RedisFuture<AggregateWithCursorResults<K, V>> aggregate(K index, V query, Cursor cursor, Object... options);

RedisFuture<AggregateWithCursorResults<K, V>> cursorRead(K index, long cursor);

RedisFuture<AggregateWithCursorResults<K, V>> aggregate(K index, V query, Cursor cursor,
Object... options);
RedisFuture<AggregateWithCursorResults<K, V>> cursorRead(K index, long cursor, long count);

@Deprecated
RedisFuture<AggregateWithCursorResults<K, V>> cursorRead(K index, long cursor, Long count);

RedisFuture<String> cursorDelete(K index, long cursor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@
*/
public interface AggregateCommands<K, V> {

AggregateResults<K, V> aggregate(K index, V query);

AggregateResults<K, V> aggregate(K index, V query, AggregateOptions options);

AggregateResults<K, V> aggregate(K index, V query, Object... options);

AggregateWithCursorResults<K, V> aggregate(K index, V query, Cursor cursor);

AggregateWithCursorResults<K, V> aggregate(K index, V query, Cursor cursor, AggregateOptions options);

AggregateWithCursorResults<K, V> aggregate(K index, V query, Cursor cursor, Object... options);

AggregateWithCursorResults<K, V> cursorRead(K index, long cursor);

AggregateWithCursorResults<K, V> cursorRead(K index, long cursor, long count);

@Deprecated
AggregateWithCursorResults<K, V> cursorRead(K index, long cursor, Long count);

String cursorDelete(K index, long cursor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@
*/
public interface AggregateReactiveCommands<K, V> {

Mono<AggregateResults<K, V>> aggregate(K index, V query);

Mono<AggregateResults<K, V>> aggregate(K index, V query, AggregateOptions options);

Mono<AggregateResults<K, V>> aggregate(K index, V query, Object... options);

Mono<AggregateWithCursorResults<K, V>> aggregate(K index, V query, Cursor cursor,
AggregateOptions options);
Mono<AggregateWithCursorResults<K, V>> aggregate(K index, V query, Cursor cursor);

Mono<AggregateWithCursorResults<K, V>> aggregate(K index, V query, Cursor cursor, AggregateOptions options);

Mono<AggregateWithCursorResults<K, V>> aggregate(K index, V query, Cursor cursor, Object... options);

Mono<AggregateWithCursorResults<K, V>> cursorRead(K index, long cursor);

Mono<AggregateWithCursorResults<K, V>> cursorRead(K index, long cursor, long count);

@Deprecated
Mono<AggregateWithCursorResults<K, V>> cursorRead(K index, long cursor, Long count);

Mono<String> cursorDelete(K index, long cursor);
Expand Down

0 comments on commit 02f72ad

Please sign in to comment.