Skip to content

Commit

Permalink
Merge pull request fli-iam#2336 from pierrehenri-dauvergne/shanoir-is…
Browse files Browse the repository at this point in the history
…sue#2284

Shanoir issue#2284: solr filter importDate
  • Loading branch information
LaurentPV authored Jul 30, 2024
2 parents 41eb6db + cce3db5 commit 58e62b3
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ public class ShanoirSolrQuery {
private Collection<String> tags;

private LocalDate datasetStartDate;

private LocalDate datasetEndDate;

private LocalDate importStartDate;

private LocalDate importEndDate;

private Collection<String> datasetType;

Expand Down Expand Up @@ -207,6 +211,22 @@ public void setDatasetEndDate(LocalDate datasetEndDate) {
this.datasetEndDate = datasetEndDate;
}

public LocalDate getImportStartDate() {
return importStartDate;
}

public void setImportStartDate(LocalDate importStartDate) {
this.importStartDate = importStartDate;
}

public LocalDate getImportEndDate() {
return importEndDate;
}

public void setImportEndDate(LocalDate importEndDate) {
this.importEndDate = importEndDate;
}

/**
* @return the datasetType
*/
Expand Down Expand Up @@ -300,10 +320,13 @@ public Map<String, FacetPageable> getFacetPaging() {
public void setFacetPaging(Map<String, FacetPageable> facetPaging) {
this.facetPaging = facetPaging;
}

public Range<LocalDate> getDatasetDateRange() {
return new Range<LocalDate>(getDatasetStartDate(), getDatasetEndDate());
}
public Range<LocalDate> getImportDateRange() {
return new Range<LocalDate>(getImportStartDate(), getImportEndDate());
}

public Collection<Long> getSubjectId() {
return subjectId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ private void addUserFiltering(SolrQuery query, ShanoirSolrQuery shanoirQuery) {
addFilterQueryFromRange(query, PIXEL_BANDWIDTH_FACET, shanoirQuery.getPixelBandwidth());
addFilterQueryFromRange(query, MAGNETIC_FIELD_STRENGHT_FACET, shanoirQuery.getMagneticFieldStrength());
addFilterQueryFromDateRange(query, DATASET_CREATION_DATE_FACET, shanoirQuery.getDatasetDateRange());
addFilterQueryFromDateRange(query, IMPORT_DATE_FACET, shanoirQuery.getImportDateRange());

if (shanoirQuery.getSearchText() != null && !shanoirQuery.getSearchText().trim().isEmpty()) {
if (shanoirQuery.isExpertMode()) {
Expand Down
3 changes: 2 additions & 1 deletion shanoir-ng-front/src/app/solr/solr.document.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class SolrDocument {
studyId: string;
id: number; // only for the table component..
username: string;

importDate: Date;
}

Expand All @@ -54,6 +53,8 @@ export class SolrRequest {
datasetName: string[];
datasetStartDate: Date | 'invalid';
datasetEndDate: Date | 'invalid';
importStartDate: Date | 'invalid';
importEndDate: Date | 'invalid';
datasetType: string[];
processed: boolean[];
datasetNature: string[];
Expand Down
23 changes: 22 additions & 1 deletion shanoir-ng-front/src/app/solr/solr.search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h2>Solr Search</h2>
<div class="title" (click)="dateOpen = !dateOpen">
<span class="left-icon">
<i class="fa-regular fa-calendar-days"></i>
Creation Date
Exam Date
</span>
<span *ngIf="!dateOpen" class="date-colapse"><i class="fas fa-chevron-down"></i></span>
<span *ngIf="dateOpen" class="date-colapse"><i class="fas fa-chevron-up"></i></span>
Expand All @@ -94,6 +94,27 @@ <h2>Solr Search</h2>
</div>
</div>
</div>
<div class="dates">
<div class="title" (click)="importDateOpen = !importDateOpen">
<span class="left-icon">
<i class="fa-regular fa-calendar-days"></i>
Import Date
</span>
<span *ngIf="!importDateOpen" class="date-colapse"><i class="fas fa-chevron-down"></i></span>
<span *ngIf="importDateOpen" class="date-colapse"><i class="fas fa-chevron-up"></i></span>
</div>
<div class="date-content" *ngIf="importDateOpen" @slideDown>
<div class="date-from">
<span class="left-title">from :</span> <datepicker *ngIf="viewChecked" [(ngModel)]="solrRequest.importStartDate" (ngModelChange)="onDateChange($event)" formControlName="importStartDate"></datepicker>
<label *ngIf="hasError('importStartDate', ['format'])" class="form-validation-alert">Date should be valid! Date format: dd/mm/yyyy</label>
</div>
<div class="date-to">
<span class="left-title">to :</span> <datepicker *ngIf="viewChecked" [(ngModel)]="solrRequest.importEndDate" (ngModelChange)="onDateChange($event)" formControlName="importEndDate"></datepicker>
<label *ngIf="hasError('importEndDate', ['format'])" class="form-validation-alert">Date should be valid! Date format: dd/mm/yyyy</label>
<label *ngIf="hasError('importEndDate', ['order'])" class="form-validation-alert">End date must be subsequent to start date</label>
</div>
</div>
</div>

<solr-paging-criterion
label="Examination"
Expand Down
39 changes: 32 additions & 7 deletions shanoir-ng-front/src/app/solr/solr.search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { TaskState } from '../async-tasks/task.model';
import {DatasetCopyDialogComponent} from "../shared/components/dataset-copy-dialog/dataset-copy-dialog.component";

const TextualFacetNames: string[] = ['studyName', 'subjectName', 'subjectType', 'acquisitionEquipmentName', 'examinationComment', 'datasetName', 'datasetType', 'datasetNature', 'tags', 'processed'];
const RangeFacetNames: string[] = ['sliceThickness', 'pixelBandwidth', 'magneticFieldStrength'];
const RangeFacetNames: string[] = ['sliceThickness', 'pixelBandwidth', 'magneticFieldStrength', 'examinationDate', 'importDate'];
export type TextualFacet = typeof TextualFacetNames[number];
@Component({
selector: 'solr-search',
Expand All @@ -71,9 +71,9 @@ export class SolrSearchComponent implements AfterViewChecked, AfterContentInit {
selectedDatasetIds: Set<number> = new Set();
syntaxError: boolean = false;
dateOpen: boolean = false;
importDateOpen: boolean = false;
public downloadState: TaskState = new TaskState();
datasetStudymap: Map<number, number> = new Map();

tab: 'results' | 'selected' = 'results';
role: 'admin' | 'expert' | 'user';
rights: Map<number, StudyUserRight[]>;
Expand All @@ -84,7 +84,6 @@ export class SolrSearchComponent implements AfterViewChecked, AfterContentInit {
solrRequest: SolrRequest = new SolrRequest();
private facetPageable: Map<string, FacetPageable>;
contentPage: SolrResultPage[] = [];

studies: Study[];
selectedStudies: string[]=[];
hasCopyRight: boolean = false;
Expand Down Expand Up @@ -162,7 +161,14 @@ export class SolrSearchComponent implements AfterViewChecked, AfterContentInit {
let formGroup = this.formBuilder.group({
'startDate': [this.solrRequest.datasetStartDate, [DatepickerComponent.validator]],
'endDate': [this.solrRequest.datasetEndDate, [DatepickerComponent.validator, this.dateOrderValidator]],
'importStartDate': [this.solrRequest.importStartDate, [DatepickerComponent.validator]],
'importEndDate': [this.solrRequest.importEndDate, [DatepickerComponent.validator, this.dateOrderValidator]],
});

formGroup.valueChanges.subscribe(() => {
formGroup.get('importEndDate').updateValueAndValidity({ emitEvent: false });
});

return formGroup;
}

Expand All @@ -185,10 +191,16 @@ export class SolrSearchComponent implements AfterViewChecked, AfterContentInit {
}

dateOrderValidator = (control: AbstractControl): ValidationErrors | null => {
this.solrRequest.importStartDate = this.form?.get('importStartDate')?.value;
this.solrRequest.importEndDate = this.form?.get('importEndDate')?.value;
if (this.solrRequest.datasetStartDate && this.solrRequest.datasetEndDate
&& this.solrRequest.datasetStartDate > this.solrRequest.datasetEndDate) {
return { order: true }
}
if (this.solrRequest.importStartDate && this.solrRequest.importEndDate
&& this.solrRequest.importStartDate > this.solrRequest.importEndDate) {
return { order: true }
}
return null;
}

Expand All @@ -205,14 +217,26 @@ export class SolrSearchComponent implements AfterViewChecked, AfterContentInit {
this.selections = [];
if (this.solrRequest.datasetStartDate && this.solrRequest.datasetStartDate != 'invalid') {
this.selections.push(new DateSelectionBlock(
'from: ' + formatDate(this.solrRequest.datasetStartDate, 'dd/MM/yyy', 'en-US', 'UTC'),
() => this.solrRequest.datasetStartDate = null
'from: ' + formatDate(this.solrRequest.datasetStartDate, 'dd/MM/yyy', 'en-US', 'UTC'),
() => this.solrRequest.datasetStartDate = null
));
}
if (this.solrRequest.datasetEndDate && this.solrRequest.datasetEndDate != 'invalid') {
this.selections.push(new DateSelectionBlock(
'to: ' + formatDate(this.solrRequest.datasetEndDate, 'dd/MM/yyy', 'en-US', 'UTC'),
() => this.solrRequest.datasetEndDate = null
'to: ' + formatDate(this.solrRequest.datasetEndDate, 'dd/MM/yyy', 'en-US', 'UTC'),
() => this.solrRequest.datasetEndDate = null
));
}
if (this.solrRequest.importStartDate && this.solrRequest.importStartDate != 'invalid') {
this.selections.push(new DateSelectionBlock(
'from: ' + formatDate(this.solrRequest.importStartDate, 'dd/MM/yyy', 'en-US', 'UTC'),
() => this.solrRequest.importStartDate = null
));
}
if (this.solrRequest.importEndDate && this.solrRequest.importEndDate != 'invalid') {
this.selections.push(new DateSelectionBlock(
'to: ' + formatDate(this.solrRequest.importEndDate, 'dd/MM/yyy', 'en-US', 'UTC'),
() => this.solrRequest.importEndDate = null
));
}
TextualFacetNames.forEach(facetName => {
Expand Down Expand Up @@ -257,6 +281,7 @@ export class SolrSearchComponent implements AfterViewChecked, AfterContentInit {
}

onDateChange(date: Date | 'invalid') {
console.log("onDateChange : ", date);
if (this.loaded && (date === null || (date && ('invalid' != date)))) {
this.updateSelections();
this.refreshTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<code>(*:* -datasetName:*localizer* AND -datasetName:*scout*)</code>
<br/><span class="italic">(all existing datasets except those which names contains "localizer" or "scout")</span>
<p>The present field names are :
<code>centerName, datasetCreationDate, studyName, subjectName, subjectType, acquisitionEquipmentName, datasetId, datasetName, datasetNature, datasetType, processed, examinationComment, examinationDate, tags, magneticFieldStrength, pixelBandwidth, sliceThickness, studyId, </code>
<code>centerName, datasetCreationDate, studyName, subjectName, subjectType, acquisitionEquipmentName, datasetId, datasetName, datasetNature, datasetType, processed, examinationComment, examinationDate, importDate, tags, magneticFieldStrength, pixelBandwidth, sliceThickness, studyId, </code>
</p>
<p>For further information, see the <a href="https://solr.apache.org/guide/8_1/the-standard-query-parser.html#specifying-terms-for-the-standard-query-parser" target="_blank">Solr official documentation</a>.</p>
</div>
Expand Down

0 comments on commit 58e62b3

Please sign in to comment.