diff --git a/src/main/java/com/basho/riak/client/api/commands/search/Search.java b/src/main/java/com/basho/riak/client/api/commands/search/Search.java index 62512fc75..275269237 100644 --- a/src/main/java/com/basho/riak/client/api/commands/search/Search.java +++ b/src/main/java/com/basho/riak/client/api/commands/search/Search.java @@ -150,16 +150,48 @@ else if (option.getKey() == Option.DEFAULT_OPERATION) return builder.build(); } + @Override + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + + if (!(o instanceof Search)) + { + return false; + } + + Search search = (Search) o; + + return start == search.start && + rows == search.rows && + Objects.equals(index, search.index) && + Objects.equals(query, search.query) && + presort == search.presort && + Objects.equals(filterQuery, search.filterQuery) && + Objects.equals(sortField, search.sortField) && + Objects.equals(returnFields, search.returnFields) && + Objects.equals(options, search.options); + } + + @Override + public int hashCode() + { + return Objects.hash(index, query, start, rows, presort, filterQuery, sortField, returnFields, options); + } + /* - * Options For controlling how Riak performs the search operation. - *

- * These options can be supplied to the {@link Search.Builder} to change - * how Riak performs the operation. These override the defaults provided - * by Riak. - *

- * @author Dave Rusek - * @since 2.0 - */ + * Options For controlling how Riak performs the search operation. + *

+ * These options can be supplied to the {@link Search.Builder} to change + * how Riak performs the operation. These override the defaults provided + * by Riak. + *

+ * @author Dave Rusek + * @since 2.0 + */ public static final class Option extends RiakOption { /** diff --git a/src/test/java/com/basho/riak/client/api/commands/search/SearchTest.java b/src/test/java/com/basho/riak/client/api/commands/search/SearchTest.java new file mode 100644 index 000000000..b061c6948 --- /dev/null +++ b/src/test/java/com/basho/riak/client/api/commands/search/SearchTest.java @@ -0,0 +1,46 @@ +package com.basho.riak.client.api.commands.search; + +import org.junit.Test; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; + +public class SearchTest +{ + @Test + public void equalsReturnsTrueForEqualNamespaces() + { + Search search1 = new Search.Builder("index", "query").filter("filter") + .withPresort(Search.Presort.KEY).sort("sort") + .returnFields("field1", "field2") + .withStart(10).withRows(10) + .withOption(Search.Option.DEFAULT_OPERATION, Search.Option.Operation.AND).build(); + Search search2 = new Search.Builder("index", "query").filter("filter") + .withPresort(Search.Presort.KEY).sort("sort") + .returnFields("field1", "field2") + .withStart(10).withRows(10) + .withOption(Search.Option.DEFAULT_OPERATION, Search.Option.Operation.AND).build(); + + assertThat(search1, is(equalTo(search2))); + assertThat(search2, is(equalTo(search1))); + } + + @Test + public void equalsReturnsFalseForDifferentNamespaces() + { + Search search1 = new Search.Builder("index1", "query1").filter("filter1") + .withPresort(Search.Presort.KEY).sort("sort1") + .returnFields("field1") + .withStart(10).withRows(10) + .withOption(Search.Option.DEFAULT_OPERATION, Search.Option.Operation.AND).build(); + Search search2 = new Search.Builder("index2", "query2").filter("filter2") + .withPresort(Search.Presort.SCORE).sort("sort2") + .returnFields("field2") + .withStart(5).withRows(5) + .withOption(Search.Option.DEFAULT_FIELD, "field2").build(); + + assertThat(search1, is(not(equalTo(search2)))); + assertThat(search2, is(not(equalTo(search1)))); + } +} \ No newline at end of file