Search fields for publications and projects, change query creation for projects in order to work with the new API format, changes in Advanced search : select fieldtype only when adding new field

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44372 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2016-10-31 14:48:26 +00:00
parent 3651ce0b3a
commit 8d530a01de
12 changed files with 187 additions and 280 deletions

View File

@ -16,7 +16,7 @@ import {SearchFields} from '../../utils/properties/searchFields';
<advanced-search-page pageTitle="Advanced Search Publications" entityType="publication"
[(results)] = "results" [(totalResults)] = "totalResults"
[(page)] = "page" [(size)] = "size" [baseUrl] = "baseUrl"
[(fieldIds)]="fieldIds" [(selectedFields)]="selectedFields"
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
[(status)] = "status"
(queryChange)="queryChanged($event)">
</advanced-search-page>
@ -34,7 +34,8 @@ export class AdvancedSearchPublicationsComponent {
private baseUrl: string;
private searchFields:SearchFields = new SearchFields();
private fieldIds: string[] = this.searchFields.ADVANCED_SEARCH_PUBLICATIONS_FIELDS;
private fieldIds: string[] = this.searchFields.ADVANCED_SEARCH_PUBLICATIONS_PARAM;
private fieldIdsMap: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.PUBLICATION_FIELDS_MAP;
private selectedFields:AdvancedField[] = [];
@ViewChild (AdvancedSearchPageComponent) searchPage : AdvancedSearchPageComponent ;
@ -58,6 +59,7 @@ export class AdvancedSearchPublicationsComponent {
this.page = ( page <= 0 ) ? 1 : page;
this.searchPage.fieldIds = this.fieldIds;
this.searchPage.selectedFields = this.selectedFields;
this.searchPage.fieldIdsMap = this.fieldIdsMap;
this.searchPage.getSelectedFiltersFromUrl(params);
this.getResults(this.searchPage.createQueryParameters(), this.page, this.size);

View File

@ -1,168 +0,0 @@
import {Component, Input, ViewChild} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import { Router, ActivatedRoute} from '@angular/router';
import {Filter, Value} from './searchUtils/searchHelperClasses.class';
import {SearchPublicationsService} from '../services/searchPublications.service';
import {SearchResult} from '../utils/entities/searchResult';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
@Component({
selector: 'advanced-search-publications',
template: `
<advanced-search-page pageTitle="Search Publications" type="publication" [(filters)] = "filters"
[(results)] = "results" [(totalResults)] = "totalResults"
[(page)] = "page" [(size)] = "size"
[(fields)] = "fields" [(selectedFields)]="selectedFields"
[(quantifiers)]="quantifiers" [(selectedQuantifiers)]="selectedQuantifiers"
[(keywords)] = "keywords" (queryChange)="queryChanged($event)">
</advanced-search-page>
`
})
export class AdvancedSearchPublicationsComponent {
private results =[];
private filters =[];
private totalResults:number = 0 ;
private page :number = 1;
private size :number = 1;
private fields: {"name": string, "value": string}[] = [
{"name": "all fields", "value": "all"},
{"name": "Title", "value": "title"},
{"name": "Author", "value": "author"},
{"name": "Publisher", "value": "publisher"},
{"name": "Subject", "value": "subject"}
];
private selectedFields: {"name": string, "value": string}[] = [this.fields[0]];
private quantifiers: {"name": string, "value": string}[] = [
{"name": "all words", "value": "and"},
{"name": "any words", "value": "or"},
{"name": "none words", "value": "not"}
];
private selectedQuantifiers: {"name": string, "value": string}[] = [this.quantifiers[0]];
private keywords: string[] = [''];
constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) {
this.results =[];
this.filters =[];
//SearchPublicationsComponent.filters = [];
/*this.totalResults = 123;
for(var i=0; i<15 ; i++){
//var result = {title: "title"+i, id: "id"+i}
var result: SearchResult = new SearchResult();
result['title'] = {"name": "title"+i, "url": OpenaireProperties.getsearchLinkToPublication()+i, "accessMode": ""};
result['authors'] = new Array<{"name": string, "url": string}>();
for(let j=0; j<=i+1; j++) {
result['authors'][j] = {"name": "author"+j+":"+i, "url": OpenaireProperties.getsearchLinkToPerson()+i};
}
result.year = "0000"
result.description = "This is a description for publication "+i;
result['projects'] = {"name": "EC | EPLANET (246806)", "url": "https://beta.openaire.eu/index.php?option=com_openaire&view=project&projectId=corda_______::9352bcbec0b5882278a21fdc0e83078c"};
this.results.push(result);
}*/
for(var i=0; i<5 ; i++){
var values = [];
for(var j=0; j<10 ; j++){
var value:Value = {name: "name"+j, id: "filter_"+i+ "_id_"+j, number:j, selected:false}
values.push(value);
}
values.sort((n2,n1) => {
if (n1.number > n2.number) {
return 1;
}
if (n1.number < n2.number) {
return -1;
}
return 0;
});
var filter:Filter = {title: "title"+i, filterId: "filter_"+i, originalFilterId: "filter_"+i, values : values, countSelectedValues:0, "filterOperator": 'and'}
if(i==0) {
var values = [];
for(var j=0; j<10 ; j++){
var value:Value = {name: "MYname"+j, id: "MYfilter_"+i+ "_id_"+j, number:j, selected:false}
values.push(value);
}
values.sort((n2,n1) => {
if (n1.number > n2.number) {
return 1;
}
if (n1.number < n2.number) {
return -1;
}
return 0;
});
var filter1:Filter = {title: "MYtitle"+i, filterId: "MYfilter_"+i, originalFilterId: "MYfilter_"+i, values : values, countSelectedValues:0, "filterOperator": 'or'}
this.filters.push(filter1);
}
this.sub = this.route.queryParams.subscribe(params => {
console.info(params);
if(params[filter.filterId] != undefined) {
let values = params[filter.filterId].split(",");
for(let value of values) {
for(let filterValue of filter.values) {
if(filterValue.id == value) {
filterValue.selected = true;
filter.countSelectedValues++;
}
}
}
}
});
this.filters.push(filter);
}
}
ngOnInit() {
this.sub = this.route.queryParams.subscribe(params => {
let page = (params['page']=== undefined)?1:+params['page'];
let size = (params['size']=== undefined)?10:+params['size'];
this.page = ( page <= 0 ) ? 1 : page;
this.size = ( size <= 0 ) ? 10 : size;
//this.keywords = (params['keyword']?params['keyword']:'');
});
//TODO get the rest parameters to create query
}
ngOnDestroy() {
this.sub.unsubscribe();
}
sub: any;
getResults(parameters:string){
//http://rudie.di.uoa.gr:8080/dnet-functionality-services-1.2.0-SNAPSHOT/search?action=searchNrefine&sTransformer=results_openaire&rTransformer=results_openaire_browse&query=%28oaftype+exact+result%29+and+%28resulttypeid+exact+publication%29&page=5&size=10&fields=instancetypenameid&fields=resultlanguageid&fields=relfunderid&fields=relprojectid&fields=resultacceptanceyear&fields=resultbestlicense&fields=resulthostingdatasourceid&fields=communityid&locale=en_GB
console.info("getResults: Execute search query "+parameters);
}
private setFilters(){
//TODO set filters from
}
private queryChanged($event) {
var parameters = $event.value;
this.getResults(parameters);
console.info("queryChanged: Execute search query "+parameters);
}
}

View File

@ -183,7 +183,7 @@ export class SearchComponent {
if(this.reloadPublications) {
this.reloadPublications = false;
this.searchPublicationsComponent.getResults(this.keyword, false, 1, 10);
this.linkToSearchPublications = OpenaireProperties.getLinkToSearchPublications() + this.keyword;
this.linkToSearchPublications = OpenaireProperties.getLinkToSearchPublications() + "?keyword=" + this.keyword;
}
}
private searchDatasets() {
@ -191,7 +191,7 @@ export class SearchComponent {
if(this.reloadDatasets) {
this.reloadDatasets = false;
this.searchDatasetsComponent.getResults(this.keyword, false, 1, 10);
this.linkToSearchDatasets = OpenaireProperties.getLinkToSearchDatasets() + this.keyword;
this.linkToSearchDatasets = OpenaireProperties.getLinkToSearchDatasets() + "?keyword=" + this.keyword;
}
}
private searchProjects() {
@ -199,7 +199,7 @@ export class SearchComponent {
if(this.reloadProjects) {
this.reloadProjects = false;
this.searchProjectsComponent.getResults(this.keyword, false, 1, 10);
this.linkToSearchProjects = OpenaireProperties.getLinkToSearchProjects() + this.keyword;
this.linkToSearchProjects = OpenaireProperties.getLinkToSearchProjects() + "?keyword=" + this.keyword;
}
}
private searchDataProviders() {
@ -207,7 +207,7 @@ export class SearchComponent {
if(this.reloadDataproviders) {
this.reloadDataproviders = false;
this.searchDataProvidersComponent.getResults(this.keyword, false, 1, 10);
this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders() + this.keyword;
this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders() + "?keyword=" + this.keyword;
}
}
private searchOrganizations() {
@ -215,7 +215,7 @@ export class SearchComponent {
if(this.reloadOrganizations) {
this.reloadOrganizations = false;
this.searchOrganizationsComponent.getResults(this.keyword, false, 1, 10);
this.linkToSearchOrganizations = OpenaireProperties.getLinkToSearchOrganizations() + this.keyword;
this.linkToSearchOrganizations = OpenaireProperties.getLinkToSearchOrganizations() + "?keyword=" + this.keyword;
}
}
private searchPeople() {
@ -223,13 +223,13 @@ export class SearchComponent {
if(this.reloadPeople) {
this.reloadPeople = false;
this.searchPeopleComponent.getResults(this.keyword, false, 1, 10);
this.linkToSearchPeople = OpenaireProperties.getLinkToSearchPeople() + this.keyword;
this.linkToSearchPeople = OpenaireProperties.getLinkToSearchPeople() + "?keyword=" + this.keyword;
}
}
private keywordChanged($event){
this.keyword = $event.value;
console.info("Search Find: search with keyword \"" + this.keyword + "\"" );
console.info("Search Find: search with keyword \"" + this.keyword + "\"" );
//unsubscribeSearch();

View File

@ -2,8 +2,6 @@ import {Component, Input, ViewChild} from '@angular/core';
import { ActivatedRoute} from '@angular/router';
import {Location} from '@angular/common';
import { Filter, Value} from './searchUtils/searchHelperClasses.class';
// import {RefineResultsService} from '../services/servicesUtils/refineResuts.service';
import {SearchProjectsService} from '../services/searchProjects.service';
import {SearchResult} from '../utils/entities/searchResult';
import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties';
@ -30,26 +28,30 @@ export class SearchProjectsComponent {
private page :number = 1;
private size :number = 10;
private sub: any;
private refineFields = [];
private searchFields:SearchFields = new SearchFields();
private urlParams : Map<string, string> ;
private refineFields: string[] = this.searchFields.PROJECT_INDEX;
private indexIdsMap: { [key:string]:string } = this.searchFields.PROJECT_INDEX_PARAM_MAP;
private fieldIdsMap: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.PROJECT_FIELDS_MAP;
private urlParams : Map<string, string>;
private _location:Location;
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
constructor (private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService) {
console.info(" constructor SearchProjectsComponent "+this.refineFields.length);
var errorCodes:ErrorCodes = new ErrorCodes();
this.status =errorCodes.LOADING;
this.baseUrl = OpenaireProperties.getLinkToSearchProjects();
this.refineFields = this.searchFields.getPROJECT_FIELDS();
if(!this.searchPage){
this.searchPage = new SearchPageComponent(this._location);
}
this.refineFields = this.searchFields.PROJECT_INDEX;
}
private ngOnInit() {
this.searchPage.refineFields = this.refineFields;
console.info("Here:: init pr"+this.refineFields.length);
this.searchPage.indexIdsMap = this.indexIdsMap;
this.searchPage.fieldIdsMap = this.fieldIdsMap;
console.info(" ngOnInit SearchProjectsComponent "+this.refineFields.length);
//get refine field filters from url parameters
this.sub = this.route.queryParams.subscribe(params => {
@ -60,9 +62,8 @@ export class SearchProjectsComponent {
//get page from url parameters
this.page = (params['page']=== undefined)?1:+params['page'];
this.searchPage.getSelectedFiltersFromUrl(params);
this.getResults(this.keyword, true, this.page, this.size);
var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
this._getResults(queryParameters, true, this.page, this.size);
});
}
@ -78,13 +79,17 @@ export class SearchProjectsComponent {
this._getResults(parameters,refine,page,size);
}
private _getResults(parameters:string,refine:boolean, page: number, size: number){
if(!refine && !this.searchPage){
this.searchPage = new SearchPageComponent(this._location);
}
this._searchProjectsService.searchProjects(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
data => {
this.totalResults = data[0];
console.info("search Projects: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]");
this.results = data[1];
this.filters = this.searchPage.checkSelectedFilters(data[2]);
this.filters = data[2];
this.searchPage.checkSelectedFilters(this.filters);
// this.filters = this.searchPage.checkSelectedFilters(data[2]);
this.searchPage.updateBaseUrlWithParameters(this.filters);
var errorCodes:ErrorCodes = new ErrorCodes();
this.status = errorCodes.DONE;

View File

@ -43,7 +43,7 @@ export class SearchPublicationsComponent {
var errorCodes:ErrorCodes = new ErrorCodes();
this.status =errorCodes.LOADING;
this.baseUrl = OpenaireProperties.getLinkToSearchPublications();
this.refineFields = this.searchFields.getPROJECT_FIELDS();
this.refineFields = this.searchFields.PUBLICATION_INDEX;
//get refine field filters from url parameters
if(!this.searchPage){
this.searchPage = new SearchPageComponent(this._location);

View File

@ -30,18 +30,18 @@ import {SearchFields} from '../../utils/properties/searchFields';
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li *ngFor="let id of fieldIds">
<a (click)="fieldIdsChanged(i, id)">{{searchFields.ADVANCED_FIELDS_NAMES_IDS[id].name}}</a>
<a (click)="fieldIdsChanged(i, id)">{{searchFields.PUBLICATION_FIELDS_MAP[id].name}}</a>
</li>
</ul-->
</div>
<input *ngIf = "searchFields.ADVANCED_FIELDS_NAMES_IDS[selectedField.id].type == 'keyword'" type="text" class="form-control" placeholder="Type keywords..." [(ngModel)]="selectedField.value" name="value[{{i}}]">
<input *ngIf = "searchFields.PUBLICATION_FIELDS_MAP[selectedField.id].type == 'keyword'" type="text" class="form-control" placeholder="Type keywords..." [(ngModel)]="selectedField.value" name="value[{{i}}]">
<div *ngIf = "searchFields.ADVANCED_FIELDS_NAMES_IDS[selectedField.id].type == 'vocabulary'" class="input-group">
<div *ngIf = "searchFields.PUBLICATION_FIELDS_MAP[selectedField.id].type == 'vocabulary'" class="input-group">
<static-autocomplete2 [(vocabularyId)] = selectedField.id [(list)] = this.fieldList[selectedField.id] [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" title = "Languages:" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
</div>
<div *ngIf = "searchFields.ADVANCED_FIELDS_NAMES_IDS[selectedField.id].type == 'refine'" class="input-group">
<static-autocomplete2 [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [fieldName] = searchFields.ADVANCED_FIELDS_NAMES_IDS[selectedField.id].indexField [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" title = "Languages:" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
<div *ngIf = "searchFields.PUBLICATION_FIELDS_MAP[selectedField.id].type == 'refine'" class="input-group">
<static-autocomplete2 [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [fieldName] = searchFields.PUBLICATION_FIELDS_MAP[selectedField.id].indexField [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" title = "Languages:" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
</div>
</div>
@ -54,11 +54,11 @@ import {SearchFields} from '../../utils/properties/searchFields';
<div class=" input-group">
<div class="input-group-btn">
<button aria-expanded="false" aria-haspopup="true" class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="dropdownMenu1" type="button">
{{searchFields.ADVANCED_FIELDS_NAMES_IDS[newFieldId].name}}
{{searchFields.PUBLICATION_FIELDS_MAP[newFieldId].name}}
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li *ngFor="let id of fieldIds">
<a (click)="fieldIdsChanged(i, id)">{{searchFields.ADVANCED_FIELDS_NAMES_IDS[id].name}}</a>
<a (click)="fieldIdsChanged(i, id)">{{searchFields.PUBLICATION_FIELDS_MAP[id].name}}</a>
</li>
</ul>
</div>
@ -79,6 +79,7 @@ import {SearchFields} from '../../utils/properties/searchFields';
export class AdvancedSearchFormComponent {
@Input() entityType;
@Input() fieldIds: string[];
@Input() fieldIdsMap:{ [key:string]:{ name:string, operator:string, type:string, indexField:string }} ;
@Input() selectedFields:AdvancedField[];
@Output() queryChange = new EventEmitter();
newFieldId:string;
@ -107,8 +108,8 @@ export class AdvancedSearchFormComponent {
}
addField() {
console.info("add filter"+this.fieldIds[0]+this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.fieldIds[0]].name+this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.fieldIds[0]].type);
this.selectedFields.push(new AdvancedField(this.newFieldId, this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.newFieldId].name,this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.newFieldId].type,"","and"));
console.info("add filter"+this.fieldIds[0]+this.fieldIdsMap[this.fieldIds[0]].name+this.fieldIdsMap[this.fieldIds[0]].type);
this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].name,this.fieldIdsMap[this.newFieldId].type,"","and"));
}
@ -126,9 +127,9 @@ export class AdvancedSearchFormComponent {
fieldIdsChanged(index: number,id) {
this.newFieldId = id;
// this.selectedFields[index].id = id;
// this.selectedFields[index].name = this.searchFields.ADVANCED_FIELDS_NAMES_IDS[id].name;
// this.selectedFields[index].name = this.searchFields.PUBLICATION_FIELDS_MAP[id].name;
// // this.selectedFields[index].type = "keyword";
// this.selectedFields[index].type = this.searchFields.ADVANCED_FIELDS_NAMES_IDS[id].type;
// this.selectedFields[index].type = this.searchFields.PUBLICATION_FIELDS_MAP[id].type;
// this.selectedFields[index].value = "";
}
valueChanged($event,index:number){

View File

@ -29,7 +29,9 @@ import {SearchFields} from '../../utils/properties/searchFields';
<div class="col-xs-6 col-sm-9 sidebar-offcanvas" id="sidebar"-->
<advanced-search-form
[entityType] = "entityType"
[(fieldIds)]="fieldIds" [(selectedFields)]="selectedFields"
[(fieldIds)]="fieldIds"
[(fieldIdsMap)]="fieldIdsMap"
[(selectedFields)]="selectedFields"
(queryChange)="queryChanged($event)">
</advanced-search-form>
@ -55,13 +57,14 @@ export class AdvancedSearchPageComponent {
@Input() size: number = 10;
@Input() totalResults: number = 0;
@Input() fieldIds: string[];
@Input() fieldIdsMap:{ [key:string]:{ name:string, operator:string, type:string, indexField:string }} ;
@Input() selectedFields:AdvancedField[];
@Input() baseUrl:string = '';
@Input() status: number;
private baseURLWithParameters:string = '';
private searchFields:SearchFields = new SearchFields();
// private searchFields:SearchFields = new SearchFields();
@Output() queryChange = new EventEmitter();
@ -77,7 +80,7 @@ export class AdvancedSearchPageComponent {
public getSelectedFiltersFromUrl(params){
for(var i=0; i< this.fieldIds.length ; i++){
var fieldId = this.fieldIds[i];
var operatorId = this.searchFields.ADVANCED_FIELDS_NAMES_IDS[fieldId].operator;
var operatorId = this.fieldIdsMap[fieldId].operator;
if(params[fieldId] != undefined && params[operatorId] != undefined) {
console.log(fieldId + " " + params[fieldId]+" Op: "+ operatorId + " "+ params[operatorId] );
var values:string [] = decodeURIComponent(params[fieldId]).split(",");
@ -85,13 +88,13 @@ export class AdvancedSearchPageComponent {
console.log(values + " " + " Op: "+ operators );
if(values.length == operators.length){
for(var j=0; j< values.length ; j++){
this.selectedFields.push(new AdvancedField(fieldId,this.searchFields.ADVANCED_FIELDS_NAMES_IDS[fieldId].name,this.searchFields.ADVANCED_FIELDS_NAMES_IDS[fieldId].type,values[j],operators[j]) )
this.selectedFields.push(new AdvancedField(fieldId,this.fieldIdsMap[fieldId].name,this.fieldIdsMap[fieldId].type,values[j],operators[j]) )
}
}
}
}
if(this.selectedFields.length == 0){
this.selectedFields.push(new AdvancedField(this.fieldIds[0],this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.fieldIds[0]].name,this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.fieldIds[0]].type,"","and"));
this.selectedFields.push(new AdvancedField(this.fieldIds[0],this.fieldIdsMap[this.fieldIds[0]].name,this.fieldIdsMap[this.fieldIds[0]].type,"","and"));
}
}
private createUrlParameters(includePage:boolean){
@ -99,7 +102,7 @@ export class AdvancedSearchPageComponent {
var fields: { [key:string]:{ values:string[], operators:string[] }}={};
for(var i = 0; i< this.selectedFields.length; i++){
if(this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.selectedFields[i].id] != undefined && this.selectedFields[i].value.length > 0){
if(this.fieldIdsMap[this.selectedFields[i].id] != undefined && this.selectedFields[i].value.length > 0){
if(!fields[this.selectedFields[i].id]){
fields[this.selectedFields[i].id] = {values:[], operators:[]};
fields[this.selectedFields[i].id].values =[];
@ -113,7 +116,7 @@ export class AdvancedSearchPageComponent {
for(var i = 0; i< this.fieldIds.length; i++){
if(fields[this.fieldIds[i]]){
params+="&"+this.fieldIds[i]+"="+fields[this.fieldIds[i]].values.join()+
"&"+this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.fieldIds[i]].operator+"="+fields[this.fieldIds[i]].operators.join()
"&"+this.fieldIdsMap[this.fieldIds[i]].operator+"="+fields[this.fieldIds[i]].operators.join()
}
}
if(includePage && this.page != 1){
@ -125,9 +128,9 @@ export class AdvancedSearchPageComponent {
var params="";
for(var i = 0; i< this.selectedFields.length; i++){
console.info("Creating Parameter:" + this.selectedFields[i].id+" :"+this.selectedFields[i].value);
if(this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.selectedFields[i].id] != undefined && this.selectedFields[i].value != ""){
if(this.fieldIdsMap[this.selectedFields[i].id] != undefined && this.selectedFields[i].value != ""){
params +="&"+ this.selectedFields[i].id
+ "="+ encodeURIComponent(this.selectedFields[i].value)+"&"+this.searchFields.ADVANCED_FIELDS_NAMES_IDS[this.selectedFields[i].id].operator
+ "="+ encodeURIComponent(this.selectedFields[i].value)+"&"+this.fieldIdsMap[this.selectedFields[i].id].operator
+ "=" + this.selectedFields[i].operatorId;
}
}

View File

@ -55,7 +55,8 @@ export class SearchPageComponent {
@Input() showResultCount:boolean = true;
@Input() showRefine:boolean = true;
@Input() refineFields = [];
public indexIdsMap: { [key:string]:string } ;
public fieldIdsMap: { [key:string]:{ name:string, operator:string, type:string, indexField:string }};
private searchFieldsHelper:SearchFields = new SearchFields();
private queryParameters: Map<string, string> = new Map<string,string>();
private baseURLWithParameters:string = '';
@ -71,7 +72,9 @@ export class SearchPageComponent {
ngAfterViewChecked(){
}
public getSelectedFiltersFromUrl(params){
public getQueryParametersFromUrl(params){
var parameters = "";
for(var i=0; i< this.refineFields.length ; i++){
var filterId = this.refineFields[i];
@ -80,10 +83,18 @@ export class SearchPageComponent {
this.queryParameters = new Map<string,string>();
}
this.queryParameters[filterId]=decodeURIComponent(params[filterId]);
console.log("My PAram "+filterId+" : "+this.queryParameters[filterId]);
let values = decodeURIComponent(this.queryParameters[filterId]).split(",");
var countvalues = 0
for(let value of values) {
countvalues++;
var paramId = this.indexIdsMap[filterId];
parameters+='&' + paramId+ '='+ value+"&" + this.fieldIdsMap[paramId].operator + "="+((countvalues == 1)?"and":"or");
}
}
}
var keyword = params['keyword'];
return (keyword && keyword.length > 0?'q='+keyword+"&op=and":'')+parameters;
}
/*
* Mark as check the new filters that are selected, when you get them from search
@ -145,6 +156,8 @@ export class SearchPageComponent {
for (let filter of filters){
if(filter.countSelectedValues > 0){
var filterLimits="";
var count_selected=0;
var fieldId = this.indexIdsMap[filter.filterId];
for (let value of filter.values){
if(value.selected == true){
// if(filter.filterOperator == 'not') {
@ -152,11 +165,13 @@ export class SearchPageComponent {
// } else {
// filterLimits+=((filterLimits.length == 0)?'':' '+filter.filterOperator+' ') + filter.filterId + '='+ value.id;
// }
if(filter.filterOperator == 'not') {
filterLimits+='&' + filter.filterId + '='+ value.id+"&operator=not";
} else {
filterLimits+='&' + filter.filterId + '='+ value.id+"&operator="+filter.filterOperator;
}
count_selected++;
// if(filter.filterOperator == 'not') {
// filterLimits+='&' + fieldId + '='+ value.id+"&" + this.fieldIdsMap[fieldId].operator + "=not";
// } else {
filterLimits+='&' + fieldId+ '='+ value.id+"&" + this.fieldIdsMap[fieldId].operator + "="+((count_selected == 1)?"and":filter.filterOperator);
// }
}
}
allLimits += filterLimits;

View File

@ -21,7 +21,7 @@ export class SearchProjectsService {
if(params!= null && params != '' ) {
url += params;
}
if(refineParams!= null && params != '' ) {
if(refineParams!= null && refineParams != '' ) {
url += refineParams;
}
url += "&page="+page+"&size="+size;

View File

@ -19,15 +19,17 @@ export class RefineResultsUtils {
filter.filterId = fields[j];
filter.originalFilterId = fields[j];
let field = data[fields[j]];
for(let i=0; i<field.length; i++) {
var value:Value = new Value();
value.name = field[i].name;
value.number = field[i].count;
value.id = field[i].id;
filter.values.push(value);
if(field){
for(let i=0; i<field.length; i++) {
var value:Value = new Value();
value.name = field[i].name;
value.number = field[i].count;
value.id = field[i].id;
filter.values.push(value);
}
filters.push(filter);
}
filters.push(filter);
}
}
return filters;

View File

@ -1,8 +1,54 @@
export class SearchFields {
//main Entities
public PUBLICATION_FIELDS:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid",
public PUBLICATION_INDEX:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid",
"relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id",
"resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"];
public ADVANCED_SEARCH_PUBLICATIONS_PARAM:string[] = ["q","title","author","publisher","type", "lang", "funder", "funderlv0",
"funderlv1","funderlv2","community","access","hostedBy","collectedFrom"];
public PUBLICATION_INDEX_PARAM_MAP:{ [key:string]:string } = {["instancetypenameid"]:"type", ["resultlanguageid"]:"lang",["communityid"]:"community",
[ "relfunderid"]:"funder",
["relfundinglevel0_id"]:"funderlv0",["relfundinglevel1_id"]:"funderlv1",["relfundinglevel2_id"]:"funderlv2",
["resultacceptanceyear"]:"year",["resultbestlicense"]:"access",["resulthostingdatasourceid"]:"hostedBy",["collectedfromdatasourceid"]:"collectedFrom"};
public PUBLICATION_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null},
["title"]:{name:"Title",operator:"tt", type:"keyword" , indexField:"resulttitle"},
["author"]:{name:"Author",operator:"at", type:"keyword", indexField:"relperson"},
["publisher"]:{name:"Publisher",operator:"pb", type:"keyword", indexField:"resultpublisher"},
["funder"]:{name:"Funder",operator:"fn", type:"refine", indexField:"relfunderid"},
["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"relfundinglevel0_id"},
["funderlv1"]:{name:"Funding Substream Level 1",operator:"fn1", type:"refine", indexField:"relfundinglevel1_id"},
["funderlv2"]:{name:"Funding Substream Level 2",operator:"fn2", type:"refine", indexField:"relfundinglevel2_id"},
["type"]:{name:"Type",operator:"tp", type:"vocabulary", indexField:"instancetypenameid"},
["lang"]: {name:"Language",operator:"ln", type:"vocabulary", indexField:"resultlanguageid"},
["community"]: {name:"Community",operator:"cm", type:"refine", indexField:"communityid"},
["access"]: {name:"Access Mode",operator:"ac", type:"vocabulary", indexField:'resultbestlicense'},
["hostedBy"]: {name:"Hosted by data provider",operator:"hs", type:"refine", indexField:"resulthostingdatasourceid"},
["collectedFrom"]: {name:"Collected from data provider",operator:"cl", type:"refine", indexField:"collectedfromdatasourceid"}
};
//PROJECT
public PROJECT_INDEX:string[] = ["funderid","fundinglevel0_id","fundinglevel1_id","fundinglevel2_id","projectstartyear","projectendyear","projectecsc39"];
public ADVANCED_PROJECTS_PARAM:string[] = ["acronym","title","keywords", "funder", "funderlv0",
"funderlv1","funderlv2","startyear","endyear","sc39","code"];
public PROJECT_INDEX_PARAM_MAP:{ [key:string]:string } = {
[ "funderid"]:"funder", ["fundinglevel0_id"]:"funderlv0",["fundinglevel1_id"]:"funderlv1",["fundinglevel2_id"]:"funderlv2",
["projectstartyear"]:"startyear",["projectendyear"]:"endyear",["projectecsc39"]:"sc39"};
public PROJECT_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
["keywords"]:{name:"Keywords",operator:"ky", type:"keyword" , indexField:"projectkeywords"},
["funder"]:{name:"Funder",operator:"fn", type:"refine", indexField:"funderid"},
["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"fundinglevel0_id"},
["funderlv1"]:{name:"Funding Substream Level 1",operator:"fn1", type:"refine", indexField:"fundinglevel1_id"},
["funderlv2"]:{name:"Funding Substream Level 2",operator:"fn2", type:"refine", indexField:"fundinglevel2_id"},
["startyear"]:{name:"Start Year",operator:"sa", type:"keyword", indexField:"projectstartyear"},
["endyear"]: {name:"End Year",operator:"ed", type:"keyword", indexField:"projectendyear"},
["sc39"]: {name:"Community",operator:"sc", type:"keyword", indexField:"projectecsc39"},
["acronym"]: {name:"Access Mode",operator:"ar", type:"keyword", indexField:'projectacronym'},
["title"]: {name:"Title",operator:"tt", type:"keyword", indexField:"projecttitle"},
["code"]: {name:"Project Code",operator:"cd", type:"keyword", indexField:"projectcode"}
};
public DATASET_FIELDS:string[] = ["instancetypenameid", "resultlanguageid", "relfunderid",
"relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id",
"resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"];
@ -22,7 +68,7 @@ export class SearchFields {
["fundinglevel1_id"]:"fundinglevel0_id", ["fundinglevel2_id"]:"fundinglevel1_id", ["relfundinglevel0_id"]:"relfunderid",
["relfundinglevel1_id"]:"relfundinglevel0_id", ["relfundinglevel2_id"]:"relfundinglevel1_id"};
public PROJECT_PARAM_FIELDS:string[] = ["funder","fl0","fl1", "fl2", "start","end","sc39"];
// public PROJECT_PARAM_FIELDS:string[] = ["funder","fl0","fl1", "fl2", "start","end","sc39"];
public FIELDS_NAMES: { [key:string]:string } = {["funderid"]:"Funder",["fundinglevel0_id"]:"Funding Stream",
["fundinglevel1_id"]:"Funding Substream Level 1", ["fundinglevel2_id"]:"Funding Substream Level 2", ["relfunderid"]:"Funder",
@ -33,12 +79,12 @@ export class SearchFields {
["datasourceodcontenttypes"]: "Type", ["datasourcecompatibilityid"]:"Compatibility Type", ["organizationcountryid"]:"Country",
["organizationeclegalbody"]:"Type",["projectstartyear"]:"Start Year",["projectendyear"]:"End Year",["projectecsc39"]:"Special Clause 39"};
public ADVANCED_FIELDS:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid",
"relfundinglevel0_id","relfundinglevel1_id,relfundinglevel2_id",
"resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"];
public ADVANCED_SEARCH_PUBLICATIONS_FIELDS:string[] = ["q","title","author","publisher","type", "lang", "funder", "funderlv0",
"funderlv1","funderlv2","community","access","hostedBy","collectedFrom"];
public ADVANCED_FIELDS_NAMES_IDS: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
// public ADVANCED_FIELDS:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid",
// "relfundinglevel0_id","relfundinglevel1_id,relfundinglevel2_id",
// "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"];
public ADVANCED_FIELDS_PROJECTS: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null},
["title"]:{name:"Title",operator:"tt", type:"keyword" , indexField:"resulttitle"},
["author"]:{name:"Author",operator:"at", type:"keyword", indexField:"relperson"},
@ -71,9 +117,9 @@ export class SearchFields {
// ["organizationeclegalbody"]:"Type",["projectstartyear"]:"Start Year",["projectendyear"]:"End Year",["projectecsc39"]:"Special Clause 39"};
public getPROJECT_FIELDS(){
return this.PROJECT_FIELDS;
}
// public getPROJECT_FIELDS(){
// return this.PROJECT_FIELDS;
// }
constructor (){

View File

@ -62,8 +62,8 @@ export class StaticAutocomplete2Component {
private tries = 0;
private showInput = true;
private sub;
private done = false;
constructor ( private _vocabulariesService: ISVocabulariesService,private _refineService: RefineFieldResultsService, private myElement: ElementRef) {
console.info("Type"+this.type);
}
ngOnDestroy(){
if(this.sub){
@ -73,27 +73,14 @@ export class StaticAutocomplete2Component {
ngOnInit () {
if(this.list == undefined || this.list.length == 0){
if(this.vocabularyId){
this.sub = this.list = this._vocabulariesService.getVocabularyByType(this.vocabularyId);
this.listUpdated.emit({
value: this.list
});
this.getSelectedNameFromGivenId();
if(this.list.length == 0){
this.warningMessage = "There are no results"
}
this.list = this._vocabulariesService.getVocabularyByType(this.vocabularyId);
this.afterListFetchedActions();
}else if(this.fieldName && this.entityName){
console.info("Get From refine");
this.list = this._refineService.getRefineFieldResultsByFieldName(this.fieldName,this.entityName);
this._refineService.getRefineFieldResultsByFieldName(this.fieldName,this.entityName).subscribe(
this.sub = this._refineService.getRefineFieldResultsByFieldName(this.fieldName,this.entityName).subscribe(
data => {
this.list = data;
this.getSelectedNameFromGivenId();
this.listUpdated.emit({
value: this.list
});
if(this.list.length == 0 ){
this.warningMessage = "There are no results"
}
this.afterListFetchedActions();
},
err => {
@ -104,31 +91,46 @@ export class StaticAutocomplete2Component {
}
}
}
private afterListFetchedActions(){
this.getSelectedNameFromGivenId();
this.listUpdated.emit({
value: this.list
});
this.done = true;
if(this.keyword != ""){
this.filter();
}
if(this.list.length == 0 ){
this.warningMessage = "There are no results"
}
}
filter() {
this.infoMessage = "";
this.filtered = [];
if(this.keyword == ""){
var cut = 5;
if(this.list.length < 5){
cut = this.list.length;
}
this.filtered =this.list.slice(0, cut);
this.tries = 0;
this.warningMessage = "";
// } else if(this.keyword && this.keyword.length < this.keywordlimit){
// this.tries++;
// if(this.tries == this.keywordlimit -1 ){
// this.warningMessage = "Type at least " + this.keywordlimit + " characters";
// this.tries = 0;
// }
}else{
this.tries = 0;
this.warningMessage = "";
this.filtered = this.list.filter(function(el){
return el.label.toLowerCase().indexOf(this.keyword.toLowerCase()) > -1;
}.bind(this));
if(this.done){
this.infoMessage = "";
this.filtered = [];
if(this.keyword == ""){
var cut = 5;
if(this.list.length < 5){
cut = this.list.length;
}
this.filtered =this.list.slice(0, cut);
this.tries = 0;
this.warningMessage = "";
// } else if(this.keyword && this.keyword.length < this.keywordlimit){
// this.tries++;
// if(this.tries == this.keywordlimit -1 ){
// this.warningMessage = "Type at least " + this.keywordlimit + " characters";
// this.tries = 0;
// }
}else{
this.tries = 0;
this.warningMessage = "";
this.filtered = this.list.filter(function(el){
return el.label.toLowerCase().indexOf(this.keyword.toLowerCase()) > -1;
}.bind(this));
}
}
}
remove(item:any){
@ -173,7 +175,6 @@ export class StaticAutocomplete2Component {
private checkIfExists(item:any,list):number{
if(item.concept && item.concept.id ){
console.log("context");
for (var _i = 0; _i < list.length; _i++) {
let itemInList = list[_i];