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 DROPINDEX command with DD option #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/main/java/io/redisearch/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ public interface Client extends Closeable{
*/
boolean dropIndex(boolean missingOk);

boolean dropIndexDD();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sazzad16 should you also add "boolean missingOk"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gkorland IMHO, if this is a necessity, it should be supported from RediSearch. If too much convenience is given to users, there is a way greater chance of it being misused.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why to introduce new method?
why not to add overloaded method
boolean dropIndex(boolean missingOk, boolean keepDocuments)

dropIndexDD name is confusing

and client still use deprecated FT.DROP -> which use different parameter


/**
* Add a word to the suggestion index for redis plugin
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/redisearch/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,15 @@ public boolean dropIndex(boolean missingOk) {
}
}

@Override
public boolean dropIndexDD() {
try (Jedis conn = connection()) {
String res = sendCommand(conn, commands.getDropCommand(), endocdedIndexName,
Keywords.DD.getRaw()).getStatusCodeReply();
return res.equals("OK");
}
}

@Override
public Long addSuggestion(Suggestion suggestion, boolean increment) {
List<String> args = new ArrayList<>();
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/io/redisearch/client/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,34 @@ public void testMGet() throws Exception {
assertTrue(Arrays.equals( SafeEncoder.encode("Hello World!2"), (byte[])docs.get(0).get("txt1")));
}

@Test
public void testDropDD() {
search.createIndex(new Schema().addTextField("txt1", 1.0), Client.IndexOptions.defaultOptions());
search.addDocument(new Document("doc1").set("txt1", "Hello World!1"), new AddOptions());
search.addDocument(new Document("doc2").set("txt1", "Hello World!2"), new AddOptions());
search.addDocument(new Document("doc3").set("txt1", "Hello World!3"), new AddOptions());

search.dropIndexDD();
try {
search.getDocument("doc1");
} catch(JedisDataException jde) {
assertUnknownIndex(jde);
}
try {
search.getDocuments("doc2", "doc3");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add another test that also verify docs were deleted with EXISTS or HGET

} catch(JedisDataException jde) {
assertUnknownIndex(jde);
}
try {
search.dropIndexDD();
} catch(JedisDataException jde) {
assertUnknownIndex(jde);
}
}

private static void assertUnknownIndex(JedisDataException jde) {
assertTrue(jde.getMessage().toLowerCase().contains("unknown index"));
}

@Test
public void testAddSuggestionGetSuggestionFuzzy() throws Exception {
Expand Down