This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit d86a681e authored by Eduard Frankford's avatar Eduard Frankford
Browse files

modified mock search so that full text search is applied to mock data description

parent 0b4b56ca
2 merge requests!17Initial Merge to Prepare Release 1.0.0,!1Resolve "Metadaten konsolideren"
......@@ -34,54 +34,57 @@ public class SearchService {
}
/**
* currently just a dummy implementation.
* TODO: first, and length is redundant to searchInput.getPage()
* currently just a dummy implementation. TODO: first, and length is redundant
* to searchInput.getPage()
*
* @param searchInput the query definition
* @param first the index of the first record to be returned
* @param length the number of records
* @param first the index of the first record to be returned
* @param length the number of records
*/
public SearchResultsDTO searchResultPage(SearchInputDTO searchInput, long first, int length) {
log.debug("Searchrequest for {} ", searchInput);
return readTestResults("Query = " + searchInput.toString(), first, length);
return readTestResults(searchInput.getFulltextQuery(), first, length);
}
/**
* temporary static test data.
*
* @param infoString just a string to add to testdata description.
* @return
*/
private SearchResultsDTO readTestResults(String infoString, long first, int length) {
private SearchResultsDTO readTestResults(String searchString, long first, int length) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
mapper.findAndRegisterModules();
List<SearchResultDTO> loadedMetaData = new ArrayList<SearchResultsDTO.SearchResultDTO>();
for (String testFile : new String[] { "metaData1.yaml", "metaData2.yaml" }) {
log.debug( "reading test data from {} ", testFile);
log.debug("reading test data from {} ", testFile);
final File metaDataFile =
new File("src/main/java/at/ac/uibk/gitsearch/service/testData/" + testFile);
final File metaDataFile = new File("src/main/java/at/ac/uibk/gitsearch/service/testData/" + testFile);
try {
byte[] fileContent = FileCopyUtils.copyToByteArray(metaDataFile);
SearchResultDTO searchResultDTO = mapper.readValue(fileContent, SearchResultDTO.class);
loadedMetaData.add(searchResultDTO);
} catch (IOException e) {
log.error( "Cannot read test search input from " + testFile, e);
log.error("Cannot read test search input from " + testFile, e);
}
}
List<SearchResultDTO> result = new ArrayList<>();
if(length>0) {
if (length > 0) {
int metadataPos = 0;
long recordNr = first;
while(recordNr - first < length && recordNr < NUM_TESTRESULTS) {
while (metadataPos < length && metadataPos < loadedMetaData.size()) {
final SearchResultDTO loadedMetaDataRecord = new SearchResultDTO(loadedMetaData.get(metadataPos++));
loadedMetaDataRecord.setTitle("#" + (recordNr+1) + " " + loadedMetaDataRecord.getTitle());
result.add(loadedMetaDataRecord);
if(metadataPos >= loadedMetaData.size()) metadataPos = 0;
recordNr++;
if (loadedMetaDataRecord.toString().contains(searchString)) {
loadedMetaDataRecord.setTitle("#" + (recordNr + 1) + " " + loadedMetaDataRecord.getTitle());
result.add(loadedMetaDataRecord);
recordNr++;
log.debug("Added MetadData Record {}", loadedMetaData);
}
log.debug("{} does not contain {}", loadedMetaData,searchString);
}
}
......
package at.ac.uibk.gitsearch.service.dto;
import java.util.Arrays;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -10,83 +11,85 @@ public class SearchResultsDTO {
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ExerciseType {
PROGRAMMING_EXERCISE ("programming exercise"),
EXERCISE("exercise"),
COLLECTION("collection"),
OTHER("other");
PROGRAMMING_EXERCISE("programming exercise"), EXERCISE("exercise"), COLLECTION("collection"), OTHER("other");
ExerciseType(String externalName) {
this.externalName = externalName;
}
private String externalName;
@JsonValue
private String externalName;
@JsonValue
public String getExternalName() {
return externalName;
}
}
public static class Person {
private String name;
private String affiliation;
private String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAffiliation() {
return affiliation;
}
public void setAffiliation(String affiliation) {
this.affiliation = affiliation;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
public static class SearchResultDTO {
public static class SearchResultDTO {
public SearchResultDTO() {
// default constructor
}
private String metadataVersion; // just for YAML testdata reader
private String metadataVersion; // just for YAML testdata reader
private String title;
private String identifier;
private String version;
private String structure;
private String description;
private ExerciseType type;
private String license;
private String[] keyword;
private String format;
private String[] programmingLanguage;
private String[] language;
private String status;
private String educationLevel;
private String gitURL;
@JsonIgnore
private String audience;
private String timeRequired;
@JsonIgnore
private String collectionContent;
public String getTimeRequired() {
return timeRequired;
}
......@@ -98,17 +101,15 @@ public class SearchResultsDTO {
private Person[] creator;
private Person[] publisher;
private Person[] contributor;
private boolean deprecated;
private String difficulty;
private String[] source;
private String requires;
private String image;
public String getIdentifier() {
return identifier;
}
......@@ -310,9 +311,10 @@ public class SearchResultsDTO {
public void setGitURL(String gitURL) {
this.gitURL = gitURL;
}
/**
* clone constructor
*
* @param toClone
*/
public SearchResultDTO(SearchResultDTO toClone) {
......@@ -345,6 +347,21 @@ public class SearchResultsDTO {
this.image = toClone.image;
this.repositoryURL = toClone.repositoryURL;
}
@Override
public String toString() {
return "SearchResultDTO [audience=" + audience + ", collectionContent=" + collectionContent
+ ", contributor=" + Arrays.toString(contributor) + ", creator=" + Arrays.toString(creator)
+ ", deprecated=" + deprecated + ", description=" + description + ", difficulty=" + difficulty
+ ", educationLevel=" + educationLevel + ", format=" + format + ", gitURL=" + gitURL
+ ", identifier=" + identifier + ", image=" + image + ", keyword=" + Arrays.toString(keyword)
+ ", language=" + Arrays.toString(language) + ", license=" + license + ", metadataVersion="
+ metadataVersion + ", programmingLanguage=" + Arrays.toString(programmingLanguage) + ", publisher="
+ Arrays.toString(publisher) + ", repositoryURL=" + repositoryURL + ", requires=" + requires
+ ", source=" + Arrays.toString(source) + ", status=" + status + ", structure=" + structure
+ ", timeRequired=" + timeRequired + ", title=" + title + ", type=" + type + ", version=" + version
+ "]";
}
}
private List<SearchResultDTO> searchResult;
......
......@@ -29,4 +29,4 @@ source:
contributor:
- {name: "Manuel Seywald", affiliation: "University of Klagenfurt", email: "maseywald@edu.aau.at"}
requires: # empty, t.b.d. later
image: teaserImage.png
image: 'https://sharing-codeability.uibk.ac.at/static/CodeAbility%20Austria-Dateien/Partner_UIBK.png'
......@@ -27,4 +27,4 @@ format: latex
deprecated: false
difficulty: EASY
requires: Java14
image: ./courseIcon.png
image: 'https://sharing-codeability.uibk.ac.at/static/CodeAbility%20Austria-Dateien/Partner_UIBK.png'
......@@ -41,7 +41,7 @@ public class SearchResource {
@PostMapping("/search/page-details")
public SearchResultsDTO
searchPageDetails(@RequestBody SearchInputDTO query) throws IOException {
log.debug("REST request to search {}, pageSize {}", query);
log.debug("REST request to search {}", query);
return searchService.searchResultPage(query,SearchInputDTO.PAGE_SIZE*query.getPage(), SearchInputDTO.PAGE_SIZE);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment