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

SENSEI-324 Add template mapping to SenseiRequest #16

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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class SenseiRequest implements AbstractSenseiRequest, Cloneable {
private SenseiMapReduce<?, ?> mapReduceFunction;
private List<SenseiError> errors;
private Set<String> _storedFieldsToFetch;
private Map<String, String> _templateMapping;

public SenseiRequest() {
_facetInitParamMap = new HashMap<String, FacetHandlerInitializerParam>();
Expand All @@ -75,6 +76,7 @@ public SenseiRequest() {
_storedFieldsToFetch = null;
_selectList = null;
_selectSet = null;
_templateMapping = null;
}

public Set<String> getTermVectorsToFetch() {
Expand All @@ -93,6 +95,10 @@ public void setStoredFieldsToFetch(Set<String> _storedFieldsToFetch) {
this._storedFieldsToFetch = _storedFieldsToFetch;
}

public Map<String, String> getTemplateMapping() { return _templateMapping; }

public void setTemplateMapping(Map<String, String> templateMapping) { this._templateMapping = templateMapping; }

/**
* Get the transaction ID.
* @return the transaction ID.
Expand Down Expand Up @@ -468,6 +474,7 @@ public String toString() {
if (_groupBy != null) buf.append("group by: ").append(_groupBy).append('\n');
buf.append("max per group: ").append(_maxPerGroup).append('\n');
buf.append("fetch stored fields: ").append(_fetchStoredFields).append('\n');
buf.append("template mapping: ").append(_templateMapping).append('\n');
return buf.toString();
}

Expand Down Expand Up @@ -506,6 +513,9 @@ public SenseiRequest clone() {
clone.setSelectList(new ArrayList<String>(this.getSelectList()));
}
clone.setMapReduceFunction(this.getMapReduceFunction());
if (this._templateMapping != null) {
clone.setTemplateMapping(new HashMap<String, String>(this._templateMapping));
}

return clone;
}
Expand Down Expand Up @@ -537,6 +547,12 @@ public boolean equals(Object o) {
} else {
if (!setsAreEqual(getPartitions(), b.getPartitions())) return false;
}
if (getTemplateMapping() == null) {
if (b.getTemplateMapping() != null) return false;
} else {
if (b.getTemplateMapping() == null) return false;
if (!getTemplateMapping().equals(b.getTemplateMapping())) return false;
}

return true;
}
Expand Down
14 changes: 14 additions & 0 deletions sensei-core/src/main/java/com/senseidb/util/RequestConverter2.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public class RequestConverter2 {
private static final String MAP_REDUCE_FUNCTION = "function";
private static final String MAP_REDUCE_PARAMETERS = "parameters";

public static final String TEMPLATE_MAPPING = "templateMapping";

private static JsonTemplateProcessor jsonTemplateProcessor = new JsonTemplateProcessor();

public static String[] getStrings(JSONObject obj, String field) {
Expand Down Expand Up @@ -400,6 +402,18 @@ else if (type.equals(RequestConverter2.FACETINIT_TYPE_DOUBLE)) param.putDoublePa
String routeParam = json.optString(RequestConverter2.ROUTEPARAM, null);
req.setRouteParam(routeParam);

JSONObject templateMapping = json.optJSONObject(RequestConverter2.TEMPLATE_MAPPING);
Map<String, String> templateMappingMap = new HashMap<String, String>();
if (templateMapping != null) {
Iterator<String> iter = (Iterator<String>)templateMapping.keys();

while (iter.hasNext()) {
String key = iter.next();
templateMappingMap.put(key, templateMapping.get(key).toString());
}
}
req.setTemplateMapping(templateMappingMap);

return req;
}

Expand Down