Change queries in advanced to support or not. Add different options for every equality operator.

This commit is contained in:
Konstantinos Triantafyllou 2022-06-01 13:27:46 +03:00
parent b0c9ee3736
commit c9c1aff2ff
4 changed files with 26 additions and 22 deletions

View File

@ -27,9 +27,8 @@
<div class="uk-grid uk-flex-middle uk-child-width-1-2@m uk-child-width-1-1"> <div class="uk-grid uk-flex-middle uk-child-width-1-2@m uk-child-width-1-1">
<div input [(value)]="selectedField.id" inputClass="border-bottom" [tooltip]="true" <div input [(value)]="selectedField.id" inputClass="border-bottom" [tooltip]="true"
[options]="fieldIdsOptions" (valueChange)="fieldIdsChanged(i,selectedField.id)" type="select"></div> [options]="fieldIdsOptions" (valueChange)="fieldIdsChanged(i,selectedField.id)" type="select"></div>
<div input *ngIf="selectedField.id != 'q' && !onlyIncludesSupported(i)" [(value)]="selectedField.includes" inputClass="border-bottom" [options]="notOperators" type="select"></div> <div input *ngIf="selectedField.id != 'q'" [(value)]="selectedField.includes" inputClass="border-bottom" [options]="getNotOperators(selectedField)" type="select"></div>
<div *ngIf="selectedField.id != 'q' && onlyIncludesSupported(i)">includes</div> <div *ngIf="selectedField.id == 'q'">includes</div>
<div *ngIf="selectedField.id == 'q'">include</div>
</div> </div>
<!-- <mat-select [(ngModel)]="selectedField.id" name="selectField_{{i}}" [disableOptionCentering]="true" class="matSelection" panelClass="matSelectionPanel" <!-- <mat-select [(ngModel)]="selectedField.id" name="selectField_{{i}}" [disableOptionCentering]="true" class="matSelection" panelClass="matSelectionPanel"
(ngModelChange)="fieldIdsChanged(i,selectedField.id)">&lt;!&ndash;(click)="fieldIdsChanged(i)" &ndash;&gt; (ngModelChange)="fieldIdsChanged(i,selectedField.id)">&lt;!&ndash;(click)="fieldIdsChanged(i)" &ndash;&gt;
@ -91,9 +90,9 @@
</span> </span>
</td> </td>
<td class="uk-width-small"> <td class="uk-width-small">
<div *ngIf="i+1 <selectedFields.length && !onlyAndSupported(i)" [(value)]="selectedFields[i+1].operatorId" (valueChange)="fieldOperatorChanged(i+1, $event, $event)" <div *ngIf="i+1 <selectedFields.length" [(value)]="selectedFields[i+1].operatorId" (valueChange)="fieldOperatorChanged(i+1, $event, $event)"
input [options]="operators" inputClass="border-bottom" type="select"></div> input [options]="operators" inputClass="border-bottom" type="select"></div>
<div *ngIf="i+1 <selectedFields.length && onlyAndSupported(i)">and</div> <!-- <div *ngIf="i+1 <selectedFields.length && onlyAndSupported(i)">and</div>-->
</td> </td>
<td [class.uk-invisible]="selectedFields.length === 1"> <td [class.uk-invisible]="selectedFields.length === 1">
<button class="uk-icon uk-close" <button class="uk-icon uk-close"
@ -104,7 +103,7 @@
</tr> </tr>
</table> </table>
<div class="uk-margin-small-top"> <div class="uk-margin-small-top">
<button (click)="addField()" class="uk-button uk-button-link uk-flex uk-flex-middle"> <button type="button" (click)="addField()" class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="add" [flex]="true"></icon> <icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left">Add rule</span> <span class="uk-margin-small-left">Add rule</span>
</button> </button>

View File

@ -18,7 +18,6 @@ import {EnvProperties} from '../../utils/properties/env-properties';
import {SearchCustomFilter} from "./searchUtils.class"; import {SearchCustomFilter} from "./searchUtils.class";
import {Subscriber} from "rxjs"; import {Subscriber} from "rxjs";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
import {Open} from "../../utils/modal/open.component";
import {Option} from "../../sharedComponents/input/input.component"; import {Option} from "../../sharedComponents/input/input.component";
@Component({ @Component({
@ -52,8 +51,9 @@ export class AdvancedSearchFormComponent implements OnInit, OnDestroy, OnChanges
properties: EnvProperties; properties: EnvProperties;
public openaireEntities = OpenaireEntities; public openaireEntities = OpenaireEntities;
public operators: string[] = this.searchFields.ADVANCED_SEARCH_OPERATORS; public operators: string[] = this.searchFields.ADVANCED_SEARCH_OPERATORS;
public notOperators: Option[] = []; public isOperators: Option[] = [{label: 'is', value: true}, {label: 'is not', value: false}];
public logicalOperators: Option[] = []; public isWithinOperators: Option[] = [{label: 'is within', value: true}, {label: 'is not within', value: false}];
public includesOperators: Option[] = [{label: 'includes', value: true}, {label: 'not includes', value: false}];
selectedEntity; selectedEntity;
selectedEntitySimpleUrl; selectedEntitySimpleUrl;
selectedEntityAdvancedUrl; selectedEntityAdvancedUrl;
@ -73,7 +73,6 @@ export class AdvancedSearchFormComponent implements OnInit, OnDestroy, OnChanges
} }
this.newFieldId = this.fieldIds[0]; this.newFieldId = this.fieldIds[0];
this.newFieldName = this.fieldIdsMap[this.newFieldId].name; this.newFieldName = this.fieldIdsMap[this.newFieldId].name;
this.buildOperatorsOptions();
this.buildFieldIdsOptions(); this.buildFieldIdsOptions();
} }
@ -89,9 +88,14 @@ export class AdvancedSearchFormComponent implements OnInit, OnDestroy, OnChanges
} }
} }
buildOperatorsOptions() { getNotOperators(field: AdvancedField) {
this.notOperators = [{label: 'includes', value: true}, {label: 'not includes', value: false}]; if(this.fieldIdsMap[field.id].equalityOperator.includes('exact')) {
this.logicalOperators = []; return this.isOperators;
} else if(this.fieldIdsMap[field.id].equalityOperator.includes('within')) {
return this.isWithinOperators;
} else {
return this.includesOperators;
}
} }
buildFieldIdsOptions() { buildFieldIdsOptions() {
@ -136,7 +140,6 @@ export class AdvancedSearchFormComponent implements OnInit, OnDestroy, OnChanges
}); });
if (this.validDateFrom && this.validDateTo) { if (this.validDateFrom && this.validDateTo) {
this.queryChange.emit({}); this.queryChange.emit({});
} }
} }

View File

@ -341,8 +341,8 @@ export class NewSearchPageComponent {
} }
queryChanged($event) { queryChanged($event) {
this.cdr.detectChanges();
if ($event == "filters_update") { if ($event == "filters_update") {
this.cdr.detectChanges();
return; return;
} }
this.goTo(1, false); this.goTo(1, false);
@ -917,8 +917,10 @@ export class NewSearchPageComponent {
} else if (this.selectedFields[i].type == "identifier") { } else if (this.selectedFields[i].type == "identifier") {
params += NewSearchPageComponent.createKeywordQuery(this.entityType, this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams); params += NewSearchPageComponent.createKeywordQuery(this.entityType, this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams);
} else if ((!this.selectedFields[i].includes || (countParams == 0 && this.selectedFields[i].operatorId == "not" && this.fieldIdsMap[this.selectedFields[i].id].equalityOperator != "="))) { } else if (countParams == 0 && this.selectedFields[i].operatorId == "not" && this.fieldIdsMap[this.selectedFields[i].id].equalityOperator != "=") {
params += (this.selectedFields[i].operatorId && countParams>0?this.selectedFields[i].operatorId:"") + " (" + this.selectedFields[i].id + " <> " + '"' + StringUtils.URIEncode(this.selectedFields[i].value) + '"' + ") "; params += " " + this.selectedFields[i].id + " <> " + '"' + StringUtils.URIEncode(this.selectedFields[i].value) + '"' + " ";
} else if (!this.selectedFields[i].includes) {
params += (i > 0?this.selectedFields[i].operatorId:'') + " (*=* NOT " + this.selectedFields[i].id + this.fieldIdsMap[this.selectedFields[i].id].equalityOperator + '"' + StringUtils.URIEncode(this.selectedFields[i].value) + '"' + ") ";
} else if (this.fieldIdsMap[this.selectedFields[i].id].equalityOperator == "=") { } else if (this.fieldIdsMap[this.selectedFields[i].id].equalityOperator == "=") {
params += NewSearchPageComponent.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams, false); params += NewSearchPageComponent.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams, false);
} else { } else {

View File

@ -23,7 +23,7 @@ export class SearchFields {
"relfundinglevel0_id", "relfundinglevel1_id", "relfundinglevel2_id", "relfundinglevel0_id", "relfundinglevel1_id", "relfundinglevel2_id",
"resultlanguagename", "relorganizationid", "pid", "relprojectid", "instancetypename", "fos", "sdg"]; "resultlanguagename", "relorganizationid", "pid", "relprojectid", "instancetypename", "fos", "sdg"];
public RESULT_FIELDS: { [key: string]: FieldDetails } = { public RESULT_FIELDS: { [key: string]: FieldDetails } = {
["q"]: {name: "All fields", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, ["q"]: {name: "Any field", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null},
["resulttitle"]: { ["resulttitle"]: {
name: "Title", name: "Title",
type: "keyword", type: "keyword",
@ -262,7 +262,7 @@ export class SearchFields {
"projectstartdate", "projectenddate", "projectstartdate", "projectenddate",
"projectcode_nt", "relorganizationid", "collectedfromdatasourceid"]; "projectcode_nt", "relorganizationid", "collectedfromdatasourceid"];
public PROJECT_FIELDS: { [key: string]: FieldDetails } = { public PROJECT_FIELDS: { [key: string]: FieldDetails } = {
["q"]: {name: "All fields", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, ["q"]: {name: "Any field", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null},
["projectacronym"]: { ["projectacronym"]: {
name: "Acronym", name: "Acronym",
type: "keyword", type: "keyword",
@ -405,7 +405,7 @@ export class SearchFields {
"datasourceodcontenttypes", "datasourcecompatibilityname", "relorganizationid", "collectedfromdatasourceid"]; "datasourceodcontenttypes", "datasourcecompatibilityname", "relorganizationid", "collectedfromdatasourceid"];
public DATASOURCE_FIELDS: { [key: string]: FieldDetails } = { public DATASOURCE_FIELDS: { [key: string]: FieldDetails } = {
["q"]: {name: "All fields", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, ["q"]: {name: "Any field", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null},
["datasourceofficialname"]: { ["datasourceofficialname"]: {
name: "English name", name: "English name",
type: "keyword", type: "keyword",
@ -600,7 +600,7 @@ export class SearchFields {
public ORGANIZATION_ADVANCED_FIELDS: string[] = ["q", "organizationlegalname", "organizationlegalshortname", "country"]; public ORGANIZATION_ADVANCED_FIELDS: string[] = ["q", "organizationlegalname", "organizationlegalshortname", "country"];
public ORGANIZATION_FIELDS: { [key: string]: FieldDetails } = { public ORGANIZATION_FIELDS: { [key: string]: FieldDetails } = {
["q"]: {name: "All fields", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, ["q"]: {name: "Any field", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null},
["organizationlegalname"]: { ["organizationlegalname"]: {
name: "Legal Name", name: "Legal Name",
type: "keyword", type: "keyword",
@ -631,7 +631,7 @@ export class SearchFields {
// public ORGANIZATION_INDEX_PARAM_MAP:{ [key:string]:string } = {["organizationlegalname"]:"contenttype", ["organizationlegalshortname"]:"type", // public ORGANIZATION_INDEX_PARAM_MAP:{ [key:string]:string } = {["organizationlegalname"]:"contenttype", ["organizationlegalshortname"]:"type",
// ["organizationcountryname"]:"country"};//,["organizationeclegalbody"]:"type"}; // ["organizationcountryname"]:"country"};//,["organizationeclegalbody"]:"type"};
// public ORGANIZATION_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string , operator: "op", equalityOperator:string}} ={ // public ORGANIZATION_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string , operator: "op", equalityOperator:string}} ={
// ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null, operator: "op", equalityOperator: "="}, // ["q"]:{name:"Any field",operator:"op", type:"keyword", indexField:null, operator: "op", equalityOperator: "="},
// ["contenttype"]:{name:"Legal Name",operator:"cn", type:"keyword" , indexField:"organizationlegalname", operator: "op", equalityOperator: "="}, // ["contenttype"]:{name:"Legal Name",operator:"cn", type:"keyword" , indexField:"organizationlegalname", operator: "op", equalityOperator: "="},
// ["compatibility"]:{name:"Legal Short Name",operator:"cm", type:"keyword", indexField:"organizationlegalshortname", operator: "op", equalityOperator: "="}, // ["compatibility"]:{name:"Legal Short Name",operator:"cm", type:"keyword", indexField:"organizationlegalshortname", operator: "op", equalityOperator: "="},
// ["country"]:{name:"Country",operator:"cu", type:"vocabulary", indexField:"organizationcountryname", operator: "op", equalityOperator: " exact "}, // ["country"]:{name:"Country",operator:"cu", type:"vocabulary", indexField:"organizationcountryname", operator: "op", equalityOperator: " exact "},