Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #178 from o19s/renaming-object-id
Browse files Browse the repository at this point in the history
Renaming object_id to object_id_field
  • Loading branch information
epugh authored May 28, 2024
2 parents 4a3d7e9 + f5027e7 commit 928180e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/opensearch/ubi/UbiActionFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ public void onResponse(Response response) {
final String queryId = ubiParameters.getQueryId();
final String userQuery = ubiParameters.getUserQuery();
final String userId = ubiParameters.getClientId();
final String objectId = ubiParameters.getObjectId();
final String objectIdField = ubiParameters.getObjectIdField();
final Map<String, String> queryAttributes = ubiParameters.getQueryAttributes();
final String query = searchRequest.source().toString();

final List<String> queryResponseHitIds = new LinkedList<>();

for (final SearchHit hit : ((SearchResponse) response).getHits()) {

if (objectId == null || objectId.isEmpty()) {
if (objectIdField == null || objectIdField.isEmpty()) {
// Use the result's docId since no object_id was given for the search.
queryResponseHitIds.add(String.valueOf(hit.docId()));
} else {
final Map<String, Object> source = hit.getSourceAsMap();
queryResponseHitIds.add((String) source.get(objectId));
queryResponseHitIds.add((String) source.get(objectIdField));
}

}
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/org/opensearch/ubi/ext/UbiParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class UbiParameters implements Writeable, ToXContentObject {
private static final ParseField QUERY_ID = new ParseField("query_id");
private static final ParseField USER_QUERY = new ParseField("user_query");
private static final ParseField CLIENT_ID = new ParseField("client_id");
private static final ParseField OBJECT_ID = new ParseField("object_id");
private static final ParseField OBJECT_ID_FIELD = new ParseField("object_id_field");
private static final ParseField QUERY_ATTRIBUTES = new ParseField("query_attributes");

static {
PARSER = new ObjectParser<>(UbiParametersExtBuilder.UBI_PARAMETER_NAME, UbiParameters::new);
PARSER.declareString(UbiParameters::setQueryId, QUERY_ID);
PARSER.declareString(UbiParameters::setUserQuery, USER_QUERY);
PARSER.declareString(UbiParameters::setClientId, CLIENT_ID);
PARSER.declareString(UbiParameters::setObjectId, OBJECT_ID);
PARSER.declareString(UbiParameters::setObjectIdField, OBJECT_ID_FIELD);
PARSER.declareObject(UbiParameters::setQueryAttributes, (p, c) -> p.mapStrings(), QUERY_ATTRIBUTES);
}

Expand Down Expand Up @@ -78,7 +78,7 @@ public static UbiParameters getUbiParameters(final SearchRequest request) {
private String queryId;
private String userQuery;
private String clientId;
private String objectId;
private String objectIdField;
private Map<String, String> queryAttributes;

/**
Expand All @@ -96,7 +96,7 @@ public UbiParameters(StreamInput input) throws IOException {
this.queryId = input.readString();
this.userQuery = input.readOptionalString();
this.clientId = input.readOptionalString();
this.objectId = input.readOptionalString();
this.objectIdField = input.readOptionalString();
this.queryAttributes = (Map<String, String>) input.readGenericValue();
}

Expand All @@ -105,14 +105,14 @@ public UbiParameters(StreamInput input) throws IOException {
* @param queryId The query ID.
* @param userQuery The user-entered search query.
* @param clientId The client ID.
* @param objectId The object ID.
* @param objectIdField The object ID field.
* @param queryAttributes Optional attributes for UBI.
*/
public UbiParameters(String queryId, String userQuery, String clientId, String objectId, Map<String, String> queryAttributes) {
public UbiParameters(String queryId, String userQuery, String clientId, String objectIdField, Map<String, String> queryAttributes) {
this.queryId = queryId;
this.userQuery = userQuery;
this.clientId = clientId;
this.objectId = objectId;
this.objectIdField = objectIdField;
this.queryAttributes = queryAttributes;
}

Expand All @@ -122,7 +122,7 @@ public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params
.field(QUERY_ID.getPreferredName(), this.queryId)
.field(USER_QUERY.getPreferredName(), this.userQuery)
.field(CLIENT_ID.getPreferredName(), this.clientId)
.field(OBJECT_ID.getPreferredName(), this.objectId)
.field(OBJECT_ID_FIELD.getPreferredName(), this.objectIdField)
.field(QUERY_ATTRIBUTES.getPreferredName(), this.queryAttributes);
}

Expand All @@ -131,7 +131,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(getQueryId());
out.writeOptionalString(userQuery);
out.writeOptionalString(clientId);
out.writeOptionalString(objectId);
out.writeOptionalString(objectIdField);
out.writeGenericValue(queryAttributes);
}

Expand All @@ -158,7 +158,7 @@ public boolean equals(Object o) {
return Objects.equals(this.queryId, other.getQueryId())
&& Objects.equals(this.userQuery, other.getUserQuery())
&& Objects.equals(this.clientId, other.getClientId())
&& Objects.equals(this.objectId, other.getObjectId())
&& Objects.equals(this.objectIdField, other.getObjectIdField())
&& Objects.equals(this.queryAttributes, other.getQueryAttributes());
}

Expand Down Expand Up @@ -203,19 +203,19 @@ public void setClientId(String clientId) {
}

/**
* Get the object ID.
* @return The object ID.
* Get the object ID field.
* @return The object ID field.
*/
public String getObjectId() {
return objectId;
public String getObjectIdField() {
return objectIdField;
}

/**
* Set the object ID.
* @param objectId The object ID.
* Set the object ID field.
* @param objectIdField The object ID field.
*/
public void setObjectId(String objectId) {
this.objectId = objectId;
public void setObjectIdField(String objectIdField) {
this.objectIdField = objectIdField;
}

/**
Expand Down

0 comments on commit 928180e

Please sign in to comment.