Skip to content

Commit

Permalink
Merge 10e1bfd into 763a1a0
Browse files Browse the repository at this point in the history
  • Loading branch information
aseure authored Jun 14, 2018
2 parents 763a1a0 + 10e1bfd commit d1a15ec
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ public class SearchResult<T> implements Serializable {

private String queryID;

private List<Map<String, Object>> userData;

private List<Map<String, Object>> appliedRules;

public List<Map<String, Object>> getAppliedRules() { return appliedRules; }

public void setAppliedRules(List<Map<String, Object>> appliedRules) {
this.appliedRules = appliedRules;
}

public List<Map<String, Object>> getUserData() { return userData; }

public void setUserData(List<Map<String, Object>> userData) {
this.userData = userData;
}

public List<T> getHits() {
return hits;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
package com.algolia.search.integration.common.sync;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.algolia.search.Index;
import com.algolia.search.SyncAlgoliaIntegrationTest;
import com.algolia.search.exceptions.AlgoliaException;
import com.algolia.search.inputs.query_rules.Rule;
import com.algolia.search.objects.Query;
import com.algolia.search.objects.RuleQuery;
import com.algolia.search.objects.tasks.sync.Task;
import com.algolia.search.responses.SearchResult;
import com.algolia.search.responses.SearchRuleResult;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;

import java.util.Arrays;
import java.util.Optional;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class DummyRecord {
private String objectID;
private String company;

public DummyRecord() {}

public String getObjectID() {
return objectID;
}

public void setObjectID(String objectID) {
this.objectID = objectID;
}


public String getCompany() {
return company;
}

public void setCompany(String company) {
this.company = company;
}
}

@SuppressWarnings({"OptionalGetWithoutIsPresent", "ConstantConditions"})
public abstract class SyncRulesTest extends SyncAlgoliaIntegrationTest {
Expand Down Expand Up @@ -40,6 +67,21 @@ public void trySaveRuleWithEmptyObjectID() throws Exception {
).hasMessageContaining("Cannot save rule with empty queryRuleID");
}

@Test
public void getRuleUserDataFromQueryResponse() throws Exception {
Index<DummyRecord> index = createIndex(DummyRecord.class);
DummyRecord record = new DummyRecord();
record.setObjectID("one");
record.setCompany("algolia");
waitForCompletion(index.addObject(record));

waitForCompletion(index.saveRule("id", generateRule("id")));
SearchResult<DummyRecord> res = index.search(new Query("my pattern").setGetRankingInfo(true));

assertThat(res.getAppliedRules()).hasSize(1);
assertThat(res.getUserData()).isEqualTo(Arrays.asList(ImmutableMap.of("a", "b")));
}

@Test
public void deleteRule() throws AlgoliaException {
String queryRuleID = "queryRule2";
Expand Down

0 comments on commit d1a15ec

Please sign in to comment.