Skip to content

Commit

Permalink
Review changes, Opensearch refactors and fixes #267
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Oct 12, 2022
1 parent 60f30a6 commit de47467
Show file tree
Hide file tree
Showing 13 changed files with 1,384 additions and 1,197 deletions.
2 changes: 2 additions & 0 deletions src/main/config/run.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ search.populateBlockSize = 10000
search.directory = ${HOME}/data/icat/search
search.backlogHandlerIntervalSeconds = 60
search.enqueuedRequestIntervalSeconds = 5
search.aggregateFilesIntervalSeconds = 3600
search.maxSearchTimeSeconds = 5
# The entities to index with the search engine. For example, remove 'Datafile' and 'DatafileParameter' if the number of datafiles exceeds lucene's limit of 2^32 entries in an index
!search.entitiesToIndex = Datafile Dataset Investigation InvestigationUser DatafileParameter DatasetParameter InvestigationParameter Sample

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
public class FacetLabel {

private String label;
private Long value;
private long value;
private JsonNumber from;
private JsonNumber to;

public FacetLabel(String label, Long value) {
public FacetLabel(String label, long value) {
this.label = label;
this.value = value;
}
Expand All @@ -39,7 +39,7 @@ public String getLabel() {
return label;
}

public Long getValue() {
public long getValue() {
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class LuceneApi extends SearchApi {
private static String getTargetPath(JsonObject query) throws IcatException {
if (!query.containsKey("target")) {
throw new IcatException(IcatExceptionType.BAD_PARAMETER,
"'target' must be present in query for LuceneApi, but it was " + query.toString());
"'target' must be present in query for LuceneApi, but it was " + query);
}
String path = query.getString("target").toLowerCase();
if (!indices.contains(path)) {
Expand Down Expand Up @@ -179,8 +179,8 @@ public SearchResult getResults(JsonObject query, JsonValue searchAfter, Integer
for (JsonObject resultObject : resultsArray) {
int luceneDocId = resultObject.getInt("_id");
int shardIndex = resultObject.getInt("_shardIndex");
Float score = Float.NaN;
if (resultObject.keySet().contains("_score")) {
float score = Float.NaN;
if (resultObject.containsKey("_score")) {
score = resultObject.getJsonNumber("_score").bigDecimalValue().floatValue();
}
JsonObject source = resultObject.getJsonObject("_source");
Expand Down
1,326 changes: 433 additions & 893 deletions src/main/java/org/icatproject/core/manager/search/OpensearchApi.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.icatproject.core.manager.search;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* Holds information for the various types of request that need to be made as
* part of a bulk modification.
*/
public class OpensearchBulk {

public Map<String, Set<String>> updatesMap = new HashMap<>();
public Set<String> investigationIds = new HashSet<>();
public Map<String, long[]> investigationAggregations = new HashMap<>();
public Map<String, long[]> datasetAggregations = new HashMap<>();
public StringBuilder bulkBuilder = new StringBuilder();
public StringBuilder deletionBuilder = new StringBuilder();
public StringBuilder fileAggregationBuilder = new StringBuilder();

/**
* Adds a path and body for a single update to updatesMap, if not already
* present.
*
* @param path Path of request
* @param body Body of request
*/
public void addUpdate(String path, String body) {
Set<String> bodies = updatesMap.getOrDefault(path, new HashSet<>());
bodies.add(body);
updatesMap.put(path, bodies);
}

/**
* @return String of updates that should be performed as a bulk request
*/
public String bulkBody() {
return bulkBuilder.toString();
}

/**
* @return String of deletes that should be performed as a bulk request
*/
public String deletedBody() {
return deletionBuilder.toString();
}

/**
* @return String of file aggregations that should be performed as a bulk
* request
*/
public String fileAggregationBody() {
return fileAggregationBuilder.toString();
}

}
Loading

0 comments on commit de47467

Please sign in to comment.