Skip to content

Commit

Permalink
Merge pull request IQSS#4109 from IQSS/4090-file-search
Browse files Browse the repository at this point in the history
4090 file search fix
  • Loading branch information
kcondon authored Aug 25, 2017
2 parents 8bf4a9d + 8e6b17f commit 10ab526
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,21 @@ public List<FileMetadata> findFileMetadataByDatasetVersionIdLabelSearchTerm(Long

public List<Integer> findFileMetadataIdsByDatasetVersionIdLabelSearchTerm(Long datasetVersionId, String searchTerm, String userSuppliedSortField, String userSuppliedSortOrder){
FileSortFieldAndOrder sortFieldAndOrder = new FileSortFieldAndOrder(userSuppliedSortField, userSuppliedSortOrder);


searchTerm=searchTerm.trim();
String sortField = sortFieldAndOrder.getSortField();
String sortOrder = sortFieldAndOrder.getSortOrder();
String searchClause = "";
if(searchTerm != null && !searchTerm.isEmpty()){
searchClause = " and (lower(o.label) like '%" + searchTerm.toLowerCase() + "%' or lower(o.description) like '%" + searchTerm.toLowerCase() + "%')";
}

//the createNativeQuary takes persistant entities, which Integer.class is not,
//which is causing the exception. Hence, this query does not need an Integer.class
//as the second parameter.
return em.createNativeQuery("select o.id from FileMetadata o where o.datasetVersion_id = " + datasetVersionId
+ searchClause
+ " order by o." + sortField + " " + sortOrder, Integer.class)
+ " order by o." + sortField + " " + sortOrder)
.getResultList();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public String getFileLabelSearchTerm() {
}

public void setFileLabelSearchTerm(String fileLabelSearchTerm) {
this.fileLabelSearchTerm = fileLabelSearchTerm;
this.fileLabelSearchTerm = fileLabelSearchTerm.trim();
}

private List<FileMetadata> fileMetadatasSearch;
Expand Down

0 comments on commit 10ab526

Please sign in to comment.