Skip to content

Commit

Permalink
Merge pull request #2434 from pierrehenri-dauvergne/shanoir-issue#2307
Browse files Browse the repository at this point in the history
shanoir-issue#2307: solr search detects keywords and switch to expertMode
  • Loading branch information
julien-louis authored Nov 12, 2024
2 parents 21a53d4 + 2313e50 commit c528f38
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ private QueryResponse querySolrServer(final SolrQuery query) throws RestServiceE
} catch (IOException e) {
throw new RestServiceException(e, new ErrorModel(500, "Error querying Solr"));
} catch (SolrException | SolrServerException e) {
ErrorModel error = new ErrorModel(HttpStatus.UNPROCESSABLE_ENTITY.value(), "solr query failed");
String errorMessage = e.getMessage().substring(e.getMessage().indexOf("shanoir") + 9);
ErrorModel error = new ErrorModel(HttpStatus.UNPROCESSABLE_ENTITY.value(), errorMessage);
throw new RestServiceException(e, error);
}
return response;
Expand Down
3 changes: 2 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 @@ -205,7 +205,8 @@ <h2>Solr Search</h2>
(onType)="syntaxError = false"
(onChange)="refreshTable()"
[syntaxError]="syntaxError"
[expertMode]="solrRequest.expertMode">
[syntaxErrorMsg]="syntaxErrorMsg"
(expertModeChange)="setExpertMode($event)">
</solr-text-search>

<solr-text-search-mode
Expand Down
11 changes: 9 additions & 2 deletions shanoir-ng-front/src/app/solr/solr.search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class SolrSearchComponent implements AfterViewChecked, AfterContentInit {
@ViewChild('selectionTable', { static: false }) selectionTable: TableComponent;
selectedDatasetIds: Set<number> = new Set();
syntaxError: boolean = false;
syntaxErrorMsg : string = "";
dateOpen: boolean = false;
importDateOpen: boolean = false;
public downloadState: TaskState = new TaskState();
Expand Down Expand Up @@ -274,6 +275,10 @@ export class SolrSearchComponent implements AfterViewChecked, AfterContentInit {
this.table.refresh(1);
}

setExpertMode(value: boolean): void {
this.solrRequest.expertMode = value;
}

openResultTab() {
this.tab = 'results';
}
Expand Down Expand Up @@ -321,11 +326,13 @@ export class SolrSearchComponent implements AfterViewChecked, AfterContentInit {
}
this.firstPageLoaded = true;
this.contentPage.push(solrResultPage);
this.syntaxErrorMsg = "";

return solrResultPage;
}).catch(reason => {
if (reason?.error?.code == 422 && reason.error.message == 'solr query failed') {
this.syntaxError = true;
if (reason?.error?.code == 422) {
this.syntaxError = true;
this.syntaxErrorMsg = reason?.error?.message;
return new SolrResultPage();
} else throw reason;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* Shanoir NG - Import, manage and share neuroimaging data
* Copyright (C) 2009-2019 Inria - https://www.inria.fr/
* Contact us on https://project.inria.fr/shanoir/
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html
*/
Expand All @@ -26,7 +26,7 @@ import { slideDown } from '../../shared/animations/animations';
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SolrTextSearchModeComponent),
multi: true,
}]
}]
})

export class SolrTextSearchModeComponent implements ControlValueAccessor {
Expand All @@ -37,8 +37,16 @@ export class SolrTextSearchModeComponent implements ControlValueAccessor {
protected propagateChange = (_: any) => {};
protected propagateTouched = () => {};

ngOnChanges(changes: SimpleChanges): void {
if (changes['expertMode']) {
setTimeout(() => {
this.onExpertModeChange();
}, 0);
}
}

onExpertModeChange() {
this.propagateChange(this.expertMode);
this.propagateChange(this.expertMode);
}

onExpertModeUserChange() {
Expand All @@ -57,4 +65,4 @@ export class SolrTextSearchModeComponent implements ControlValueAccessor {
registerOnTouched(fn: any): void {
this.propagateTouched = fn;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-->

<div class="input-frame">
<input type="text" placeholder="search in Shanoir ..." [(ngModel)]="searchText" (change)="onChangeSearch()" (keyup)="onType.emit()" [class.error]="syntaxError" [class.expert]="expertMode"/>
<input type="text" placeholder="search in Shanoir ..." [(ngModel)]="searchText" (ngModelChange)="inputTextChange()" (change)="onChangeSearch()" (keyup)="onType.emit()" [class.error]="syntaxError" [class.expert]="expertMode"/>
<span class="left-icon clickable clear" (click)="clear(); this.onChangeSearch();"><i class="fas fa-times"></i>clear</span>
</div>
<div class="syntax-error" *ngIf="syntaxError">syntax error</div>
<div class="syntax-error" *ngIf="syntaxError || syntaxErrorMsg">{{syntaxErrorMsg}}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
* Shanoir NG - Import, manage and share neuroimaging data
* Copyright (C) 2009-2019 Inria - https://www.inria.fr/
* Contact us on https://project.inria.fr/shanoir/
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html
*/
import { Component, EventEmitter, forwardRef, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import {Component, EventEmitter, forwardRef, Input, OnChanges, Output, SimpleChanges, ViewChild} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { slideDown } from '../../shared/animations/animations';
import {TableComponent} from "../../shared/components/table/table.component";
import {ToggleSwitchComponent} from "../../shared/switch/switch.component";


@Component({
Expand All @@ -26,23 +28,32 @@ import { slideDown } from '../../shared/animations/animations';
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SolrTextSearchComponent),
multi: true,
}]
}]
})

export class SolrTextSearchComponent implements ControlValueAccessor {

showInfo: boolean = false;
searchText: string = "";
searchKeyWords: string[] = ["centerName", "datasetCreationDate", "studyName", "subjectName", "subjectType", "acquisitionEquipmentName", "datasetId", "datasetName", "datasetNature", "datasetType", "processed", "examinationComment", "examinationDate", "importDate", "tags", "magneticFieldStrength", "pixelBandwidth", "sliceThickness", "studyId"];
@Output() onChange: EventEmitter<string> = new EventEmitter();
@Output() onType: EventEmitter<void> = new EventEmitter();
@Output() expertModeChange: EventEmitter<boolean> = new EventEmitter();
@Input() syntaxError: boolean = false;
@Input() expertMode: boolean = false;
@Input() syntaxErrorMsg: string;
expertMode: boolean = false;
protected propagateChange = (_: any) => {};
protected propagateTouched = () => {};

inputTextChange() {
if (this.searchKeyWords.some(word => this.searchText.includes(word))) {
this.expertModeChange.emit(true);
}
}

onChangeSearch() {
if (!this.syntaxError) {
this.propagateChange(this.searchText);
this.propagateChange(this.searchText);
this.onChange.emit(this.searchText);
}
}
Expand All @@ -68,4 +79,4 @@ export class SolrTextSearchComponent implements ControlValueAccessor {
registerOnTouched(fn: any): void {
this.propagateTouched = fn;
}
}
}

0 comments on commit c528f38

Please sign in to comment.