Skip to content

Commit

Permalink
Text fields and related entities #267
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Apr 8, 2022
1 parent ba32387 commit 3c0d3bc
Show file tree
Hide file tree
Showing 27 changed files with 690 additions and 641 deletions.
35 changes: 16 additions & 19 deletions src/main/java/org/icatproject/core/entity/Datafile.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,31 +201,26 @@ public void setSourceDatafiles(List<RelatedDatafile> sourceDatafiles) {
}

@Override
public void getDoc(JsonGenerator gen, SearchApi searchApi) {
StringBuilder sb = new StringBuilder(name);
public void getDoc(JsonGenerator gen) {
SearchApi.encodeString(gen, "name", name);
if (description != null) {
sb.append(" " + description);
SearchApi.encodeString(gen, "description", description);
}
if (doi != null) {
sb.append(" " + doi);
SearchApi.encodeString(gen, "doi", doi);
}
if (datafileFormat != null) {
sb.append(" " + datafileFormat.getName());
datafileFormat.getDoc(gen);
}
searchApi.encodeTextField(gen, "text", sb.toString());
searchApi.encodeSortedDocValuesField(gen, "name", name);
if (datafileModTime != null) {
searchApi.encodeSortedDocValuesField(gen, "date", datafileModTime);
SearchApi.encodeLong(gen, "date", datafileModTime);
} else if (datafileCreateTime != null) {
searchApi.encodeSortedDocValuesField(gen, "date", datafileCreateTime);
SearchApi.encodeLong(gen, "date", datafileCreateTime);
} else {
searchApi.encodeSortedDocValuesField(gen, "date", modTime);
SearchApi.encodeLong(gen, "date", modTime);
}
searchApi.encodeStringField(gen, "id", id, true);
searchApi.encodeStringField(gen, "dataset", dataset.id);
searchApi.encodeStringField(gen, "investigation", dataset.getInvestigation().id);

// TODO User and Parameter support for Elasticsearch
SearchApi.encodeString(gen, "id", id);
SearchApi.encodeString(gen, "investigation.id", dataset.getInvestigation().id);
}

/**
Expand All @@ -242,16 +237,18 @@ public void getDoc(JsonGenerator gen, SearchApi searchApi) {
public static Map<String, Relationship[]> getDocumentFields() throws IcatException {
if (documentFields.size() == 0) {
EntityInfoHandler eiHandler = EntityInfoHandler.getInstance();
Relationship[] textRelationships = {
Relationship[] datafileFormatRelationships = {
eiHandler.getRelationshipsByName(Datafile.class).get("datafileFormat") };
Relationship[] investigationRelationships = {
eiHandler.getRelationshipsByName(Datafile.class).get("dataset") };
documentFields.put("text", textRelationships);
documentFields.put("name", null);
documentFields.put("description", null);
documentFields.put("doi", null);
documentFields.put("date", null);
documentFields.put("id", null);
documentFields.put("dataset", null);
documentFields.put("investigation", investigationRelationships);
documentFields.put("investigation.id", investigationRelationships);
documentFields.put("datafileFormat.id", null);
documentFields.put("datafileFormat.name", datafileFormatRelationships);
}
return documentFields;
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/icatproject/core/entity/DatafileFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.json.stream.JsonGenerator;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -14,6 +15,8 @@
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.icatproject.core.manager.SearchApi;

@Comment("A data file format")
@SuppressWarnings("serial")
@Entity
Expand Down Expand Up @@ -95,4 +98,10 @@ public void setVersion(String version) {
this.version = version;
}

@Override
public void getDoc(JsonGenerator gen) {
SearchApi.encodeString(gen, "datafileFormat.name", name);
SearchApi.encodeString(gen, "datafileFormat.id", id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public void setDatafile(Datafile datafile) {
}

@Override
public void getDoc(JsonGenerator gen, SearchApi searchApi) {
super.getDoc(gen, searchApi);
searchApi.encodeSortedDocValuesField(gen, "datafile", datafile.id);
public void getDoc(JsonGenerator gen) {
super.getDoc(gen);
SearchApi.encodeString(gen, "datafile.id", datafile.id);
}

}
59 changes: 28 additions & 31 deletions src/main/java/org/icatproject/core/entity/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,45 +189,31 @@ public void setType(DatasetType type) {
}

@Override
public void getDoc(JsonGenerator gen, SearchApi searchApi) {

StringBuilder sb = new StringBuilder(name + " " + type.getName() + " " + type.getName()); // TODO duplicate type.getName()
public void getDoc(JsonGenerator gen) {
SearchApi.encodeString(gen, "name", name);
if (description != null) {
sb.append(" " + description);
SearchApi.encodeString(gen, "description", description);
}

if (doi != null) {
sb.append(" " + doi);
}

if (sample != null) {
sb.append(" " + sample.getName());
if (sample.getType() != null) {
sb.append(" " + sample.getType().getName());
}
SearchApi.encodeString(gen, "doi", doi);
}

searchApi.encodeTextField(gen, "text", sb.toString());
searchApi.encodeSortedDocValuesField(gen, "name", name);

if (startDate != null) {
searchApi.encodeSortedDocValuesField(gen, "startDate", startDate);
SearchApi.encodeLong(gen, "startDate", startDate);
} else {
searchApi.encodeSortedDocValuesField(gen, "startDate", createTime);
SearchApi.encodeLong(gen, "startDate", createTime);
}

if (endDate != null) {
searchApi.encodeSortedDocValuesField(gen, "endDate", endDate);
SearchApi.encodeLong(gen, "endDate", endDate);
} else {
searchApi.encodeSortedDocValuesField(gen, "endDate", modTime);
SearchApi.encodeLong(gen, "endDate", modTime);
}
searchApi.encodeStringField(gen, "id", id, true);

searchApi.encodeSortedDocValuesField(gen, "id", id);
SearchApi.encodeString(gen, "id", id);
SearchApi.encodeString(gen, "investigation.id", investigation.id);

searchApi.encodeStringField(gen, "investigation", investigation.id);

// TODO User, Parameter and Sample support for Elasticsearch
if (sample != null) {
sample.getDoc(gen, "sample.");
}
type.getDoc(gen);
}

/**
Expand All @@ -244,13 +230,24 @@ public void getDoc(JsonGenerator gen, SearchApi searchApi) {
public static Map<String, Relationship[]> getDocumentFields() throws IcatException {
if (documentFields.size() == 0) {
EntityInfoHandler eiHandler = EntityInfoHandler.getInstance();
Relationship[] textRelationships = { eiHandler.getRelationshipsByName(Dataset.class).get("type"), eiHandler.getRelationshipsByName(Dataset.class).get("sample") };
documentFields.put("text", textRelationships);
Relationship[] sampleRelationships = { eiHandler.getRelationshipsByName(Dataset.class).get("sample") };
Relationship[] sampleTypeRelationships = { eiHandler.getRelationshipsByName(Dataset.class).get("sample"),
eiHandler.getRelationshipsByName(Sample.class).get("type") };
Relationship[] typeRelationships = { eiHandler.getRelationshipsByName(Dataset.class).get("type") };
documentFields.put("name", null);
documentFields.put("description", null);
documentFields.put("doi", null);
documentFields.put("startDate", null);
documentFields.put("endDate", null);
documentFields.put("id", null);
documentFields.put("investigation", null);
documentFields.put("investigation.id", null);
documentFields.put("sample.id", null);
documentFields.put("sample.name", sampleRelationships);
documentFields.put("sample.investigation.id", sampleRelationships);
documentFields.put("sample.type.id", sampleRelationships);
documentFields.put("sample.type.name", sampleTypeRelationships);
documentFields.put("type.id", null);
documentFields.put("type.name", typeRelationships);
}
return documentFields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public void setDataset(Dataset dataset) {
}

@Override
public void getDoc(JsonGenerator gen, SearchApi searchApi) {
super.getDoc(gen, searchApi);
searchApi.encodeSortedDocValuesField(gen, "dataset", dataset.id);
public void getDoc(JsonGenerator gen) {
super.getDoc(gen);
SearchApi.encodeString(gen, "dataset.id", dataset.id);
}
}
9 changes: 9 additions & 0 deletions src/main/java/org/icatproject/core/entity/DatasetType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.json.stream.JsonGenerator;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -14,6 +15,8 @@
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.icatproject.core.manager.SearchApi;

@Comment("A type of data set")
@SuppressWarnings("serial")
@Entity
Expand Down Expand Up @@ -71,4 +74,10 @@ public void setName(String name) {
this.name = name;
}

@Override
public void getDoc(JsonGenerator gen) {
SearchApi.encodeString(gen, "type.name", name);
SearchApi.encodeString(gen, "type.id", id);
}

}
7 changes: 5 additions & 2 deletions src/main/java/org/icatproject/core/entity/EntityBaseBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,11 @@ public String toString() {
return this.getClass().getSimpleName() + ":" + id;
}

/* This should be overridden by classes wishing to index things in a search engine */
public void getDoc(JsonGenerator gen, SearchApi searchApi) {
/*
* This should be overridden by classes wishing to index things in a search
* engine
*/
public void getDoc(JsonGenerator gen) {
}

}
9 changes: 9 additions & 0 deletions src/main/java/org/icatproject/core/entity/Facility.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import java.util.ArrayList;
import java.util.List;

import javax.json.stream.JsonGenerator;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.icatproject.core.manager.SearchApi;

@Comment("An experimental facility")
@SuppressWarnings("serial")
@Entity
Expand Down Expand Up @@ -177,4 +180,10 @@ public void setUrl(String url) {
this.url = url;
}

@Override
public void getDoc(JsonGenerator gen) {
SearchApi.encodeString(gen, "facility.name", name);
SearchApi.encodeString(gen, "facility.id", id);
}

}
72 changes: 23 additions & 49 deletions src/main/java/org/icatproject/core/entity/Investigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,66 +265,32 @@ public void setVisitId(String visitId) {
}

@Override
public void getDoc(JsonGenerator gen, SearchApi searchApi) {
StringBuilder sb = new StringBuilder(visitId + " " + name + " " + facility.getName() + " " + type.getName());
public void getDoc(JsonGenerator gen) {
SearchApi.encodeString(gen, "name", name);
SearchApi.encodeString(gen, "visitId", visitId);
SearchApi.encodeString(gen, "title", title);
if (summary != null) {
sb.append(" " + summary);
SearchApi.encodeString(gen, "summary", summary);
}
if (doi != null) {
sb.append(" " + doi);
SearchApi.encodeString(gen, "doi", doi);
}
if (title != null) {
sb.append(" " + title);
}
searchApi.encodeTextField(gen, "text", sb.toString());
searchApi.encodeSortedDocValuesField(gen, "name", name);

if (startDate != null) {
searchApi.encodeSortedDocValuesField(gen, "startDate", startDate);
SearchApi.encodeLong(gen, "startDate", startDate);
} else {
searchApi.encodeSortedDocValuesField(gen, "startDate", createTime);
SearchApi.encodeLong(gen, "startDate", createTime);
}

if (endDate != null) {
searchApi.encodeSortedDocValuesField(gen, "endDate", endDate);
SearchApi.encodeLong(gen, "endDate", endDate);
} else {
searchApi.encodeSortedDocValuesField(gen, "endDate", modTime);
}

investigationUsers.forEach((investigationUser) -> {
searchApi.encodeStringField(gen, "userName", investigationUser.getUser().getName());
searchApi.encodeTextField(gen, "userFullName", investigationUser.getUser().getFullName());
});

samples.forEach((sample) -> {
// searchApi.encodeSortedSetDocValuesFacetField(gen, "sampleName",
// sample.getName());
searchApi.encodeTextField(gen, "sampleText", sample.getDocText());
});

for (InvestigationParameter parameter : parameters) {
ParameterType type = parameter.type;
String parameterName = type.getName();
String parameterUnits = type.getUnits();
// searchApi.encodeSortedSetDocValuesFacetField(gen, "parameterName",
// parameterName);
searchApi.encodeStringField(gen, "parameterName", parameterName);
searchApi.encodeStringField(gen, "parameterUnits", parameterUnits);
// TODO make all value types facetable...
if (type.getValueType() == ParameterValueType.STRING) {
// searchApi.encodeSortedSetDocValuesFacetField(gen, "parameterStringValue",
// parameter.getStringValue());
searchApi.encodeStringField(gen, "parameterStringValue", parameter.getStringValue());
} else if (type.getValueType() == ParameterValueType.DATE_AND_TIME) {
searchApi.encodeStringField(gen, "parameterDateValue", parameter.getDateTimeValue());
} else if (type.getValueType() == ParameterValueType.NUMERIC) {
searchApi.encodeDoublePoint(gen, "parameterNumericValue", parameter.getNumericValue());
}
SearchApi.encodeLong(gen, "endDate", modTime);
}

searchApi.encodeSortedDocValuesField(gen, "id", id);

searchApi.encodeStringField(gen, "id", id, true);
SearchApi.encodeString(gen, "id", id);
facility.getDoc(gen);
type.getDoc(gen);
}

/**
Expand All @@ -341,13 +307,21 @@ public void getDoc(JsonGenerator gen, SearchApi searchApi) {
public static Map<String, Relationship[]> getDocumentFields() throws IcatException {
if (documentFields.size() == 0) {
EntityInfoHandler eiHandler = EntityInfoHandler.getInstance();
Relationship[] textRelationships = { eiHandler.getRelationshipsByName(Investigation.class).get("type"),
Relationship[] typeRelationships = { eiHandler.getRelationshipsByName(Investigation.class).get("type") };
Relationship[] facilityRelationships = {
eiHandler.getRelationshipsByName(Investigation.class).get("facility") };
documentFields.put("text", textRelationships);
documentFields.put("name", null);
documentFields.put("visitId", null);
documentFields.put("title", null);
documentFields.put("summary", null);
documentFields.put("doi", null);
documentFields.put("startDate", null);
documentFields.put("endDate", null);
documentFields.put("id", null);
documentFields.put("facility.name", facilityRelationships);
documentFields.put("facility.id", null);
documentFields.put("type.name", typeRelationships);
documentFields.put("type.id", null);
}
return documentFields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void setInvestigation(Investigation investigation) {
}

@Override
public void getDoc(JsonGenerator gen, SearchApi searchApi) {
super.getDoc(gen, searchApi);
searchApi.encodeSortedDocValuesField(gen, "investigation", investigation.id);
public void getDoc(JsonGenerator gen) {
super.getDoc(gen);
SearchApi.encodeString(gen, "investigation.id", investigation.id);
}
}
Loading

0 comments on commit 3c0d3bc

Please sign in to comment.