Project

General

Profile

1
import {Component, ElementRef, Input, Output, ViewChild} from '@angular/core';
2
import {Location} from '@angular/common';
3
import {ActivatedRoute, Router} from '@angular/router';
4
import {Meta, Title} from '@angular/platform-browser';
5

    
6
import {AdvancedField, Filter, Value} from './searchHelperClasses.class';
7
import {SearchCustomFilter, SearchUtilsClass} from './searchUtils.class';
8
import {ModalLoading} from '../../utils/modal/loading.component';
9
import {Dates, Identifier, StringUtils} from '../../utils/string-utils.class';
10
import {ErrorCodes} from '../../utils/properties/errorCodes';
11
import {RouterHelper} from '../../utils/routerHelper.class';
12

    
13
import {PiwikService} from '../../utils/piwik/piwik.service';
14
import {EnvProperties} from '../../utils/properties/env-properties';
15
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
16
import {HelperService} from "../../utils/helper/helper.service";
17
import {SearchFields} from "../../utils/properties/searchFields";
18
import {RefineResultsUtils} from "../../services/servicesUtils/refineResults.class";
19
import {RangeFilter} from "../../utils/rangeFilter/rangeFilterHelperClasses.class";
20
import {ZenodoInformationClass} from "../../deposit/utils/zenodoInformation.class";
21
import {Breadcrumb} from "../../utils/breadcrumbs/breadcrumbs.component";
22
import {HelperFunctions} from "../../utils/HelperFunctions.class";
23
import {properties} from "../../../../environments/environment";
24
import {AlertModal} from "../../utils/modal/alert";
25

    
26
declare var UIkit: any;
27

    
28
@Component({
29
  selector: 'new-search-page',
30
  templateUrl: 'newSearchPage.component.html'
31
})
32
export class NewSearchPageComponent {
33
  @ViewChild('offcanvas_element') offcanvasElement: ElementRef;
34
  @Input() piwikSiteId = null;
35
  @Input() hasPrefix: boolean = true;
36
  @Input() pageTitle = "";
37
  @Input() results = [];
38
  @Input() type;
39
  @Input() entityType;
40
  @Input() searchUtils: SearchUtilsClass = new SearchUtilsClass();
41
  @Input() fieldIds: string[];
42
  @Input() fieldIdsMap;//:{ [key:string]:{ name:string, operator:string, type:string, indexField:string, equalityOperator:string  }} ;
43
  @Input() selectedFields: AdvancedField[];
44
  @ViewChild(ModalLoading) loading: ModalLoading;
45
  @Input() csvParams: string;
46
  @Input() csvPath: string;
47
  @Input() simpleSearchLink: string = "";
48
  @Input() advancedSearchLink: string = "";
49
  @Input() disableForms: boolean = false;
50
  @Input() disableRefineForms: boolean = false;
51
  @Input() loadPaging: boolean = true;
52
  @Input() oldTotalResults: number = 0;
53
  @Input() openaireLink: string;
54
  @Input() customFilter: SearchCustomFilter;
55
  @Input() sort: boolean = true;
56
  @Input() sortedByChanged: string = "";
57
  @Input() resultsPerPageChanged: number;
58
  @Input() searchFormClass: string = "searchForm";
59
  //From simple:
60
  @Input() rangeFilters: RangeFilter[] = [];
61
  @Input() rangeFields: string[][] = [];
62
  @Input() refineFields = [];
63
  @Input() filters:Filter[] = [];
64
  selectedFilters: number = 0;
65
  selectedRangeFilters: number = 0;
66
  private searchFieldsHelper: SearchFields = new SearchFields();
67
  @Input() newQueryButton: boolean = true;
68
  public showUnknownFilters: boolean = false; // when a filter exists in query but has no results, so no filters returned from the query
69
  URLCreatedFilters: Filter[] = [];
70
  URLCreatedRangeFilters: RangeFilter[] = [];
71
  @Input() showRefine: boolean = true;
72
  @Input() tableViewLink: string;
73
  @Input() usedBy: string = "search";
74
  @Input() public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
75
  @Input() showLastIndex: boolean = true;
76
  @Input() showResultCount: boolean = true;
77
  @Input() showMoreFilterValuesInline: boolean = true;
78
  @Input() filterValuesNum: number = 6;
79
  @Input() keywordFields = [];
80
  @Input() simpleView: boolean = true;
81
  @Input() formPlaceholderText = "Type Keywords...";
82
  @Input() resultTypes = null;
83
  resultTypeOptions = [{"id":"publication", "name":"Publications"},{"id":"dataset", "name":"Research data"},
84
    {"id":"software", "name":"Software"},{"id":"other", "name":" Other research products"}];
85
  selectedTypesNum = 0;
86
  @Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
87
  @Input() includeOnlyResultsAndFilter:boolean = false;
88
  @Input() showBreadcrumb:boolean = false;
89
  @Input() lastIndex: boolean = true;
90
  public dashboard: boolean = properties.isDashboard;
91

    
92
  piwiksub: any;
93
  public parameterNames: string[] = [];
94
  public parameterValues: string[] = [];
95

    
96
  public csvLimit: number = 0;
97
  public pagingLimit: number = 0;
98
  public resultsPerPage: number = 0;
99
  isPiwikEnabled = false;
100
  properties: EnvProperties;
101
  public pageContents = null;
102
  public divContents = null;
103
  public routerHelper: RouterHelper = new RouterHelper();
104
  public errorCodes: ErrorCodes = new ErrorCodes();
105
  breadcrumbs:Breadcrumb[] = [];
106
  url = null;
107
  metaDescription = "";
108
  @Input() basicMetaDescription = [];
109

    
110
  @Input() entitiesSelection:boolean = true;
111
  @Input() showSwitchSearchLink:boolean = true;
112

    
113
  // on 1st load, do not show filters until results query returns.
114
  public hideFilters: boolean = true;
115

    
116
  //Dashboard
117
  filterToggle = false;
118
  customFilterEnabled:boolean =  false;
119
  //stickyform
120
  @Input() stickyForm:boolean = false;
121

    
122
  @ViewChild('removeCustomFilter') removeCustomFilter: AlertModal;
123
  currentValueToRemove;
124
  currentFilterToRemove;
125
  isCustomFilterSelected:boolean = true;
126
  constructor(private route: ActivatedRoute,
127
              private location: Location,
128
              private _meta: Meta,
129
              private _title: Title,
130
              private _piwikService: PiwikService,
131
              private router: Router,
132
              private seoService: SEOService,
133
              private helper: HelperService) {
134
  }
135

    
136
  ngOnInit() {
137
    this.route.data
138
      .subscribe((data: { envSpecific: EnvProperties }) => {
139
        this.properties = data.envSpecific;
140
        //this.getDivContents();
141
        this.getPageContents();
142
        this.pagingLimit = data.envSpecific.pagingLimit;
143
        this.resultsPerPage = data.envSpecific.resultsPerPage;
144
        this.csvLimit = data.envSpecific.csvLimit;
145
        this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
146
        this.updateUrl(data.envSpecific.baseLink + this.router.url);
147
        this.url = data.envSpecific.baseLink + this.router.url;
148
        if (typeof document !== 'undefined' && this.isPiwikEnabled && !this.includeOnlyResultsAndFilter) {
149
          this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
150
        }
151
      });
152
    this.route.queryParams.subscribe(params => {
153
      if (params['page'] && params['page'] != 1) {
154
        HelperFunctions.scrollToId("searchForm");
155
      }
156
      this.customFilterEnabled = params['cf'] && params['cf'] == "true";
157
    });
158
    if (!this.includeOnlyResultsAndFilter) {
159
      if(this.basicMetaDescription.length == 0 ){
160
        if (this.entityType == "result") {
161
          this.basicMetaDescription =  ["Discover" + (this.properties.adminToolsCommunity == 'openaire'?"over 100 million of":"")+" research outcomes ", "categorized by research type, year range, funder, languages, community and content providers."];
162
        } else if (this.entityType == "project") {
163
          this.basicMetaDescription =  ["Discover research projects and correlated research categorized by Funder and active year. ", "Statistics data about produced research outcomes per year available."];
164
        } else if (this.entityType == "organization") {
165
          this.basicMetaDescription =  ["Discover worldwide research organizations from over 100 countries and correlated research. ", "Funding, content providers, research pubblications and research data available."];
166
        }else{
167
          this.basicMetaDescription.push(this.pageTitle)
168
        }
169
      }
170
      this.metaDescription = this.basicMetaDescription.join(" ");
171
      this.updateTitle(this.pageTitle);
172
      this.updateDescription();
173
    }
174

    
175
    this.searchUtils.baseUrl = "/" + this.searchUtils.baseUrl;
176
    this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.router.url, false);
177
    this.breadcrumbs.push({name: 'home', route: '/'});
178
    if(this.simpleView) {
179
      this.breadcrumbs.push( {name: "Search", route: null});
180
    }else if(!this.simpleView && this.advancedSearchLink) {
181
      this.breadcrumbs.push({name: "Advanced Search", route: null});
182
    }
183
    //console.log(this.filters)
184
  }
185

    
186
  private getPageContents() {
187
    if((this.customFilter && this.customFilter.queryFieldName == "communityId") && this.properties.adminToolsCommunity !== "monitor") {
188
      this.helper.getPageHelpContents(this.properties, (this.customFilter) ? this.customFilter.valueId : this.properties.adminToolsCommunity, this.router.url).subscribe(contents => {
189
        this.pageContents = contents;
190
      });
191
    }
192
  }
193

    
194
  private getDivContents() {
195
    if((this.customFilter && this.customFilter.queryFieldName == "communityId") && this.properties.adminToolsCommunity !== "monitor") {
196
      this.helper.getDivHelpContents(this.properties, (this.customFilter) ? this.customFilter.valueId : this.properties.adminToolsCommunity, this.router.url).subscribe(contents => {
197
        this.divContents = contents;
198
      });
199
    }
200
  }
201

    
202
  ngOnDestroy() {
203
    if (this.piwiksub) {
204
      this.piwiksub.unsubscribe();
205
    }
206
  }
207

    
208
  updateDescription() {
209
    // this.metaDescription2 = "";
210
    /*if(this.resultTypes){
211
      let array = [];
212
      for(let type of this.resultTypeOptions){
213
        if(this.resultTypes[type.id]== true){
214
          array.push(type.name);
215
        }
216
      }
217
      if(array.length == 0){
218
        this.metaDescription += "research outcomes ";
219
      }else{
220
        this.metaDescription += array.join(", ") + " ";
221
      }
222
    }else{
223
      this.metaDescription = this.pageTitle + " ";
224
    }*/
225
    let filterArray = [];
226
    for(let filter of this.filters){
227
      if(filter.countSelectedValues> 0){
228
       for(let value of filter.values){
229
         if(value.selected) {
230
           filterArray.push(value.name);
231
         }
232
        }
233
      }
234
    }
235
    for(let field of this.selectedFields){
236
      if((field.type == "entity" || field.type == "refine") && field.valueLabel.length > 0 && filterArray.indexOf(field.valueLabel)==-1){
237
        filterArray.push(field.valueLabel)
238
      }else if(!(field.type == "entity" || field.type == "refine")  && field.value.length > 0 && filterArray.indexOf(field.value)==-1) {
239
        filterArray.push(field.value);
240
      }
241
    }
242
    this.metaDescription= (filterArray.length > 0?( this.basicMetaDescription[0] + " Filtered by: " + filterArray.join(", ") + " ")
243
      :this.basicMetaDescription.join(" "));
244
    this._meta.updateTag({content: this.metaDescription}, "name='description'");
245
    this._meta.updateTag({content: this.metaDescription}, "property='og:description'");
246
  }
247

    
248
  updateTitle(title: string) {
249
    var _prefix = "";
250
    if (this.hasPrefix) {
251
      _prefix = "OpenAIRE | ";
252
    }
253
    var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
254
    this._title.setTitle(_title);
255
    this._meta.updateTag({content: _title}, "property='og:title'");
256
  }
257

    
258
  updateUrl(url: string) {
259
    this._meta.updateTag({content: url}, "property='og:url'");
260
  }
261

    
262

    
263
  clearFilters() {
264
    for (var i = 0; i < this.filters.length; i++) {
265
      for (var j = 0; j < this.filters[i].countSelectedValues; j++) {
266
        if (this.filters[i].values[j].selected) {
267
          this.filters[i].values[j].selected = false;
268
        }
269
        this.filters[i].countSelectedValues = 0;
270
        this.filters[i].radioValue = "";
271
      }
272
    }
273
    this.selectedFilters = 0;
274
    for(let i = 0; i < this.rangeFilters.length; i++) {
275
      this.rangeFilters[i].selectedFromValue = null;
276
      this.rangeFilters[i].selectedToValue = null;
277
    }
278
    this.selectedRangeFilters = 0;
279
    if (this.quickFilter) {
280
      this.removeValueFromQuickFilter();
281
    }
282
    this.resultTypes = {};
283
    for(let type of this.resultTypeOptions){
284
      this.resultTypes[type.id]=false;
285
    }
286
    this.goTo(1);
287
    // this.clearKeywords();
288
  }
289

    
290
  goTo(page: number = 1, scroll:boolean = true) {
291
    if(this.offcanvasElement) {
292
      UIkit.offcanvas(this.offcanvasElement.nativeElement).hide();
293
    }
294

    
295
    this.searchUtils.page = page;
296
    this.buildPageURLParameters(this.filters, this.rangeFilters, true);
297
    this.router.navigate([this.searchUtils.baseUrl], {queryParams: this.routerHelper.createQueryParams(this.parameterNames, this.parameterValues)});
298
    if(scroll) {
299
      HelperFunctions.scrollToId("searchForm");
300
    }
301
    /* Code For Piwik*/
302
    if (typeof localStorage !== 'undefined') {
303
      //console.log("In PreviousRouteRecorder : "+this.router.url );
304
      localStorage.setItem('previousRoute', this.router.url);
305
    }
306
    if (this.isPiwikEnabled && (typeof document !== 'undefined')) {
307
      this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
308
    }
309
    /* End Piwik Code */
310
  }
311

    
312
  queryChanged() {
313

    
314
    this.goTo(1, false);
315
  }
316

    
317

    
318
  sizeChanged($event) {
319
    //this.searchUtils.size = $event.value;
320
    this.resultsPerPageChanged = $event;
321

    
322
    this.goTo(1);
323
  }
324

    
325
  sortByChanged($event) {
326
    //this.searchUtils.sortBy = $event.value;
327
    this.sortedByChanged = $event;
328
    this.goTo(1);
329
  }
330

    
331

    
332
  getOperatorParameter(parameter: string): string {
333
    for (let id of this.fieldIds) {
334
      if (this.fieldIdsMap[id]["param"] == parameter) {
335
        return this.fieldIdsMap[id]["operator"];
336
      }
337
    }
338
  }
339

    
340
  /*
341
* Get A sub-array of this.refineFields array, which contains the ids of the selected filters
342
*/
343
  public getSelectedFilters(): string[] {
344
    var selected: string[] = [];
345
    var filters= (this.filters.length > 0)?this.filters:this.URLCreatedFilters;
346
    for (var i = 0; i < filters.length; i++) {
347
      var filter: Filter = filters[i];
348
      if (filter.countSelectedValues > 0) {
349
        selected.push(filter.filterId);
350
      }
351
    }
352
    return selected;
353
  }
354

    
355
  /*
356
    * Get A sub-array of this.refineFields array, which contains the ids of the selected parameters
357
    */
358
  private getSelectedParameters(): string[] {
359
    var selected: string[] = [];
360
    for (var i = 0; i < this.refineFields.length; i++) {
361
      if (this.parameterNames.indexOf(this.refineFields[i]) != -1) {
362
        selected.push(this.refineFields[i]);
363
      }
364
    }
365
    return selected;
366
  }
367

    
368
  /*
369
  * Get A sub-array of this.refineFields array, which hides hidden fields (e.g Funding level 0,1,2,..), and contains those that depend on another fields (e.g  Funding level 0 if Funder is selected )
370
  */
371
  public getFields(): string[] {
372
    var selected_filters: string[] = this.getSelectedFilters();
373
    if (selected_filters.length == 0) {
374
      selected_filters = this.getSelectedParameters();
375
    }
376
    var fields: string[] = [];
377
    for (var i = 0; i < this.refineFields.length; i++) {
378
      var dependentTo = this.searchFieldsHelper.DEPENDENT_FIELDS[this.refineFields[i]];
379

    
380
      //if filter is not marked as hidden OR it is hidden but it is dependent to a field that it IS selected
381
      if (this.searchFieldsHelper.HIDDEN_FIELDS.indexOf(this.refineFields[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) || (selected_filters.indexOf(this.refineFields[i]) != -1)) {
382
        fields.push(this.refineFields[i]);
383
      }
384
    }
385
    return fields;
386
  }
387

    
388
  /*
389
  * Get a query  string of all fields, that want to get from search (e.g. &fields=funderid&fields=projectstartyear&...))
390
  */
391
  public getRefineFieldsQuery(): string {
392

    
393
    var fields: string[] = this.getFields();
394
    var fieldsStr = ""
395
    for (var i = 0; i < fields.length; i++) {
396
      fieldsStr += "&fields=" + fields[i];
397
    }
398
    return "&refine=true" + fieldsStr;
399
  }
400

    
401

    
402
  /*
403
  * Mark as check the new filters that are selected, when you get them from search
404
  */
405
  public checkSelectedFilters(filters: Filter[]) {
406
    this.filters = filters;
407
    if(this.customFilter && !this.customFilter.isHiddenFilter) {
408
      this.customFilter.selected = null;
409
    }
410
    for (var i = 0; i < filters.length; i++) {
411
      var filter: Filter = filters[i];
412
      filter.countSelectedValues = 0;
413
      if (this.parameterNames.indexOf(filter.filterId) != -1) {
414
        let values = (decodeURIComponent(this.parameterValues[this.parameterNames.indexOf(filter.filterId)])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
415
        for (let filterValue of filter.values) {
416
          if (values.indexOf(StringUtils.quote(filterValue.id)) > -1) {
417
            filterValue.selected = true;
418
            filter.countSelectedValues++;
419
          } else {
420
            filterValue.selected = false;
421

    
422
          }
423
        }
424
        if(this.customFilter){
425
          this.customFilter.selected = this.customFilter.queryFieldName == filter.filterId && values.indexOf(StringUtils.quote(this.customFilter.valueId)) != -1;
426
        }
427
      } else if (this.quickFilter && this.quickFilter.filterId == filter.filterId && this.quickFilter.selected) {
428
        for (let filterValue of filter.values) {
429
          if (filterValue.id == this.quickFilter.value) {
430
            filterValue.selected = true;
431
            filter.countSelectedValues++;
432
          } else {
433
            filterValue.selected = false;
434
          }
435
        }
436
      } else {
437
        for (let filterValue of filter.values) {
438
          filterValue.selected = false;
439
        }
440
      }
441
      if (this.quickFilter && filter.filterId == this.quickFilter.filterId) {
442
        this.quickFilter.filter = filter;
443
      }
444
    }
445
    if (this.parameterNames.indexOf("cf") != -1 && this.parameterValues[this.parameterNames.indexOf("cf")] == "true") {
446
      this.customFilter.selected = true;
447
    }else if(this.customFilter && this.customFilter.selected == null){
448
      this.customFilter.selected = false;
449
    }
450
    this.filterFilterValues(this.filters);
451
    if(!this.includeOnlyResultsAndFilter) {
452
      this.updateDescription();
453
    }
454
    return filters;
455
  }
456

    
457
  /*
458
* Mark as check the new range filters that are selected
459
*/
460
  public checkSelectedRangeFilters(filters: RangeFilter[]) {
461
    //console.log("checkSelectedRangeFilters: parameterNames.length: "+this.parameterNames.length);
462

    
463
    this.rangeFilters = filters;
464
    for (let i = 0; i < filters.length; i++) {
465
      let filter: RangeFilter = filters[i];
466

    
467
      if (this.parameterNames.indexOf(filter.filterId) != -1) {
468
        //console.log(filter.filterId + " "+this.parameterNames.indexOf(filter.filterId) );
469
        let values = (decodeURIComponent(this.parameterValues[this.parameterNames.indexOf(filter.filterId)])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
470
        let operators: string [] = (StringUtils.URIDecode(this.parameterValues[this.parameterNames.indexOf(filter.filterId)])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
471
        if (values.length == operators.length) {
472
          for (let j = 0; j < values.length; j++) {
473
            if (this.fieldIdsMap[filter.originalFilterIdFrom+"-range-"+filter.originalFilterIdTo].filterType == "range") {
474
              let value: string = StringUtils.unquote(values[j]);
475
              let validDates: boolean = true;
476

    
477
              let years: string[] = (value.substring(5)).split(":");
478
              let yearFrom: string = (Dates.isValidYear(years[0]) ? years[0] : null);
479
              let yearTo: string = (Dates.isValidYear(years[1]) ? years[1] : null);
480
              //console.log("checkSelectedRangeFilters: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
481
              if(yearFrom) {
482
                filter.selectedFromValue = yearFrom;
483
              }
484
              if(yearTo) {
485
                filter.selectedToValue = yearTo;
486
              }
487
              if(yearFrom && yearTo) {
488
                filter.selectedFromAndToValues = yearFrom + "-" + yearTo;
489
              } else if(yearFrom) {
490
                filter.selectedFromAndToValues = "From " + yearFrom;
491
              } else if(yearTo) {
492
                filter.selectedFromAndToValues = "Until " + yearTo;
493
              }
494

    
495
              if(!yearFrom && !yearTo) {
496
                validDates = false;
497
              }
498

    
499
              // if (value.length < 14) {
500
              //   validDates = false;
501
              //   console.log("not valid (length<14)");
502
              // } else {
503
              //   if (!Dates.isValidYear(value.substring(5, 9)) || !Dates.isValidYear(value.substring(10, 14))) {
504
              //     validDates = false;
505
              //     console.log("not valid years");
506
              //   } else {
507
              //     filter.selectedFromValue = value.substring(5, 9);
508
              //     filter.selectedToValue = value.substring(10, 14);
509
              //     console.log(filter);
510
              //   }
511
              // }
512
            }
513
          }
514
        }
515
      } else {
516
        filter.selectedFromValue = null;
517
        filter.selectedToValue = null;
518
      }
519
    }
520
    return this.rangeFilters;
521
  }
522

    
523
  get existingFiltersWithValues() {
524
    if(this.filters.length == 0) {
525
      return 0;
526
    }
527
    return this.filters.some(filter => (filter.values && filter.values.length > 0));
528
  }
529

    
530
  /*
531
  * For Funder filters - if funder selected
532
  */
533
  public filterFilterValues(filters: Filter[]) {
534
    var funders = [];
535
    var funder_prefix = [];
536
    for (var i = 0; i < filters.length; i++) {
537

    
538
      var filter: Filter = filters[i];
539
      //  console.log(filter.filterId);
540
      if (filter.filterId.indexOf("funder") != -1 && this.parameterNames.indexOf(filter.filterId) != -1) {
541
        let funders = (decodeURIComponent(this.parameterValues[this.parameterNames.indexOf(filter.filterId)])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
542
        for (let funder of funders) {
543
          funder_prefix.push(StringUtils.unquote(funder).split("____")[0]);
544
        }
545
        //  console.log(funder_prefix );
546
      } else if (filter.filterId.indexOf("funding") != -1) {
547
        //  console.log(" funding: "+filter.filterId );
548
        var filteredValues = []
549
        for (let filterValue of filter.values) {
550
          var value_prefix = filterValue.id.split("____")[0];
551
          //  console.log("Value prefix: "+value_prefix );
552
          if (funder_prefix.indexOf(value_prefix) != -1) {
553
            //  console.log("here" + value_prefix);
554
            filteredValues.push(filterValue);
555
          }
556

    
557
        }
558
        if (filteredValues.length > 0) {
559
          filter.values = filteredValues;
560
        }
561
      }
562

    
563
    }
564

    
565
    return filters;
566
  }
567

    
568
  public countSelectedFilters(filters: Filter[]): number {
569
    this.selectedFilters = 0;
570
    for (let filter of filters) {
571
      if (filter.countSelectedValues > 0) {
572
        this.selectedFilters += filter.countSelectedValues;
573
      }
574
    }
575
    return this.selectedFilters;
576
  }
577

    
578
  public countSelectedRangeFilters(rangeFilters: RangeFilter[]) : number {
579
    this.selectedRangeFilters = 0;
580
    for(let filter of rangeFilters) {
581
      if(filter.selectedFromValue || filter.selectedToValue) {
582
        this.selectedRangeFilters++;
583
      }
584
    }
585
    return this.selectedRangeFilters;
586
  }
587

    
588
  private clearKeywords() {
589
    if (this.searchUtils.keyword.length > 0) {
590
      this.searchUtils.keyword = '';
591
    }
592
    this.goTo(1);
593
  }
594

    
595
  public removeFilter(value: Value, filter: Filter, forceRemove:boolean = false) {
596
    this.currentValueToRemove = value;
597
    this.currentFilterToRemove = filter;
598
    if(!forceRemove && this.customFilter && this.customFilter.queryFieldName ==filter.filterId && this.customFilter.valueId == value.id && this.customFilter.promptToAddFilter ){
599
      this.openRemoveCustomFilterModal();
600
      return;
601
    }
602
    filter.countSelectedValues--;
603
    this.selectedFilters--;
604
    if (value.selected == true) {
605
      value.selected = false;
606
    }
607
    if(filter.filterType == "radio"){
608
      filter.radioValue = "";
609
    }
610
    if (this.quickFilter && this.quickFilter.filterId == filter.filterId) {
611
      this.removeValueFromQuickFilter();
612
    }
613
    this.goTo(1);
614
  }
615
  public openRemoveCustomFilterModal() {
616
    this.removeCustomFilter.alertTitle = 'Remove filter';
617
    this.removeCustomFilter.message = 'You are about to see results that are not related to '+ this.customFilter.valueName + '. Do you want to proceed?';
618
    this.removeCustomFilter.okButtonText = 'Yes';
619
    this.removeCustomFilter.cancelButtonText = 'No';
620
    this.removeCustomFilter.open();
621
  }
622

    
623
  closeCustomFilterModal() {
624
    this.removeFilter(this.currentValueToRemove, this.currentFilterToRemove, true);
625
    this.isCustomFilterSelected = false;
626
  }
627

    
628
  public removeRangeFilter(filter: RangeFilter) {
629
    filter.selectedFromValue = null;
630
    filter.selectedToValue = null;
631
    this.goTo(1);
632
  }
633

    
634
  getSelectedValues(filter): any {
635
    var selected = [];
636
    if (filter.countSelectedValues > 0) {
637
      for (var i = 0; i < filter.values.length; i++) {
638
        if (filter.values[i].selected) {
639
          selected.push(filter.values[i]);
640
        }
641
      }
642
    }
643
    return selected;
644

    
645
  }
646

    
647
  filterChanged($event) {
648
    if (this.quickFilter && this.quickFilter.filter) {
649
      this.removeValueFromQuickFilter();
650
    }
651
    this.goTo(1);
652

    
653
  }
654

    
655
  /**
656
   * if there is a change in the values of the quick filter, this function has to be run, to also update the quickFilter
657
   */
658
  removeValueFromQuickFilter() {
659
    if (this.quickFilter.filter.countSelectedValues == 0) {
660
      this.quickFilter.selected = false;
661
    } else {
662
      let isQuickEnabled = false;
663
      for (let filterValue of this.quickFilter.filter.values) {
664
        isQuickEnabled = (filterValue.name == this.quickFilter.value)
665
      }
666
      this.quickFilter.selected = (isQuickEnabled && this.quickFilter.filter.countSelectedValues == 1);
667
    }
668
  }
669

    
670
  /**
671
   * Set selected the value of the custom filter.
672
   */
673
  addCustomFilter() {
674
    this.customFilter.selected = true;
675
    if(this.refineFields.indexOf(this.customFilter.queryFieldName) == -1  ){
676
      this.customFilterEnabled = true;
677
    }else {
678
      for (let filter of this.filters) {
679
        if (this.customFilter.queryFieldName == filter.filterId) {
680
          for (let value of filter.values) {
681
            if (value.id == this.customFilter.valueId) {
682
              value.selected = true;
683
              filter.countSelectedValues++;
684
            }
685
          }
686
        }
687
      }
688
    }
689
    this.filterChanged(null);
690

    
691
  }
692
  // for loading
693
  public openLoading() {
694
    this.loading.open();
695
  }
696

    
697
  public closeLoading() {
698
    this.loading.close();
699
  }
700

    
701
  /**
702
   * Build advanced search Filters based on the URL parameters
703
   * @param params
704
   */
705
  createAdvancedSearchSelectedFiltersFromNewURLParameters(params) {
706
    for (let i = 0; i < Object.keys(params).length; i++) {
707
      if(params["f"+i] && params["fv"+i]   ) {
708
        let fieldId = params["f" + i].split(",")[0];
709
        let operator = (params["f" + i].split(",").length  >1 )?params["f" + i].split(",")[1]:"and";
710
        let fieldparam = (this.fieldIdsMap[fieldId]) ? this.fieldIdsMap[fieldId].param : "";
711

    
712
        if (!this.fieldIdsMap[fieldId]) {
713
          console.error("Field: " + fieldId + " not found in fieldIds map");
714
          continue;
715
        }
716
        let value: string = StringUtils.URIDecode(params["fv"+i]);
717
        if (this.fieldIdsMap[fieldId].type == "date") {
718
            let validDates: boolean = true;
719
            let dateField: AdvancedField = new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type, value, operator);
720
            if (value.indexOf("range") != -1) {
721
              dateField.dateValue.type = "range";
722
              if (value.length < 26) {
723
                validDates = false;
724
              } else {
725
                if (!Dates.isValidDate(value.substring(5, 15)) || !Dates.isValidDate(value.substring(16, 26))) {
726
                  validDates = false;
727
                } else {
728
                  dateField.dateValue.from = Dates.getDateFromString(value.substring(5, 15));
729
                  dateField.dateValue.to = Dates.getDateFromString(value.substring(16, 26));
730
                }
731
              }
732
              //  "rangeYYYY-MM-DD:YYYY-MM-DD"
733
            } else {
734
              dateField.dateValue.setDatesByType(value);
735
            }
736
            if (validDates) {
737
              this.selectedFields.push(dateField);
738
            }
739

    
740
          } else {
741
            this.selectedFields.push(new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type,value, operator));
742
          }
743

    
744
        }
745
      }
746
  }
747
  /**
748
   * Build advanced search Filters based on the URL parameters
749
   * @param params
750
   */
751
  createAdvancedSearchSelectedFiltersFromURLParameters(params) {
752
    this.createAdvancedSearchSelectedFiltersFromNewURLParameters(params);
753
    for (var i = 0; i < this.fieldIds.length; i++) {
754
      var fieldId = this.fieldIds[i];
755
      var fieldparam = (this.fieldIdsMap[fieldId]) ? this.fieldIdsMap[fieldId].param : "";
756
      if (!this.fieldIdsMap[fieldId]) {
757
        console.error("Field: " + fieldId + " not found in fieldIds map");
758
        continue;
759
      }
760

    
761
      var operatorId = this.getOperatorParameter(fieldparam);
762
      if (params[fieldparam] != undefined && params[operatorId] != undefined) {
763
        var values: string [] = StringUtils.URIDecode(params[fieldparam]).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
764
        var operators: string [] = (StringUtils.URIDecode(params[operatorId])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
765
        if (values.length == operators.length) {
766
          for (var j = 0; j < values.length; j++) {
767
            if (this.fieldIdsMap[fieldId].type == "date") {
768
              var value: string = StringUtils.unquote(values[j]);
769
              var validDates: boolean = true;
770
              var dateField: AdvancedField = new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type, value, operators[j]);
771
              if (value.indexOf("range") != -1) {
772
                dateField.dateValue.type = "range";
773
                if (value.length < 26) {
774
                  validDates = false;
775
                } else {
776
                  if (!Dates.isValidDate(value.substring(5, 15)) || !Dates.isValidDate(value.substring(16, 26))) {
777
                    validDates = false;
778
                  } else {
779
                    dateField.dateValue.from = Dates.getDateFromString(value.substring(5, 15));
780
                    dateField.dateValue.to = Dates.getDateFromString(value.substring(16, 26));
781
                  }
782
                }
783
                //  "rangeYYYY-MM-DD:YYYY-MM-DD"
784
              } else {
785
                dateField.dateValue.setDatesByType(value);
786
              }
787
              if (validDates) {
788
                this.selectedFields.push(dateField);
789
              }
790

    
791
            } else {
792
              this.selectedFields.push(new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type, values[j], operators[j]));
793
            }
794
          }
795
        }
796
      }
797
    }
798
    if (params['keyword'] && params['keyword'].length > 0) {
799
      this.selectedFields.push(new AdvancedField(this.fieldIds[0], this.fieldIdsMap[this.fieldIds[0]].param, this.fieldIdsMap[this.fieldIds[0]].name, this.fieldIdsMap[this.fieldIds[0]].type, params['keyword'], "and"));
800
    }
801
    if (this.selectedFields.length == 0) {
802
      this.selectedFields.push(new AdvancedField(this.fieldIds[0], this.fieldIdsMap[this.fieldIds[0]].param, this.fieldIdsMap[this.fieldIds[0]].name, this.fieldIdsMap[this.fieldIds[0]].type, "", "and"));
803
    }
804
  }
805

    
806
  /**
807
   * Create Search API query based on the selected fields of the advanced form
808
   */
809
  getSearchAPIQueryForAdvancedSearhFields() {
810

    
811
    var params = "";
812
    var countParams = 0;
813
    for (var i = 0; i < this.selectedFields.length; i++) {
814
      if (this.fieldIdsMap[this.selectedFields[i].id] != undefined && (this.selectedFields[i].value != "" || this.selectedFields[i].type == "date")) {
815
        //console.log("createQueryParameters::"+this.selectedFields[i].type);
816
        if (this.selectedFields[i].type == "date") {
817
          if (this.selectedFields[i].dateValue.type != "any") {
818
            params += (countParams == 0 ? "" : this.selectedFields[i].operatorId) + " " + this.selectedFields[i].id + this.fieldIdsMap[this.selectedFields[i].id].equalityOperator + '"' + StringUtils.URIEncode(Dates.getDateToString(this.selectedFields[i].dateValue.from)) + " "
819
              + StringUtils.URIEncode(Dates.getDateToString(this.selectedFields[i].dateValue.to)) + '"' + " ";
820
          }
821
        } else {
822
          if (this.selectedFields[i].id == "q") {
823
            // console.log(this.selectedFields[i].value)
824
/*            var op = "";
825
            var doisParams = "";
826
            if ((this.entityType == 'publication' || this.entityType == 'dataset' || this.entityType == 'software' || this.entityType == 'other' || this.entityType == "result")) {
827
              var DOIs: Identifier[] = Identifier.getIdentifiersFromString(this.selectedFields[i].value);
828
              for (let identifier of DOIs) {
829
                // console.log(identifier)
830
                // pidclassid exact \"doi\" and pid exact \"10.1016/j.nima.2015.11.134\"
831
                //and (authorid exact \"0000-0001-7291-3210 \" )"
832
                if(identifier.class == "ORCID"){
833
                  doisParams += (doisParams.length > 0 ? " or " : "") +'(authorid="' + identifier.id + '")';
834
                }else{
835
                  doisParams += (doisParams.length > 0 ? " or " : "") +'(pidclassid exact "' + identifier.class + '" and pid="' +  identifier.id + '")';
836
                }
837
              }
838
            }
839
            if (doisParams.length > 0) {
840
              params += this.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId ,countParams,true, true) + " or " + doisParams;
841
            } else {
842
              params += this.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId,countParams,true);
843
            }*/
844
            params += NewSearchPageComponent.createKeywordQuery(this.entityType,this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams);
845
            //TODO deposit case
846
            // console.log(this.usedBy)
847
            // console.log(this.keywordFields)
848

    
849
            if(this.usedBy == "deposit") {
850

    
851
              if(this.keywordFields.length > 0) {
852
                params += " or ("
853
              }
854
              for(let j=0; j< this.keywordFields.length ; j++) {
855
                if(j > 0) {
856
                  params += " or "
857
                }
858
                params += NewSearchPageComponent.createQuotedKeywordQuery(this.selectedFields[i].value, this.keywordFields[j].name, " or ", countParams,false);
859
                // let field = this.keywordFields[i];
860
                //keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(keyword);
861
                // params += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(keyword));
862
              }
863
              if(this.keywordFields.length > 0) {
864
                params += " ) "
865
              }
866
            }
867

    
868
          } else if (countParams == 0 && this.selectedFields[i].operatorId == "not" && this.fieldIdsMap[this.selectedFields[i].id].equalityOperator != "=") {
869
            params += " " + this.selectedFields[i].id + " <> " + '"' + StringUtils.URIEncode(this.selectedFields[i].value) + '"' + " ";
870
          } else if(this.fieldIdsMap[this.selectedFields[i].id].equalityOperator == "=") {
871
            params+=NewSearchPageComponent.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams, false);
872
          }else{
873
              params += (countParams == 0 ? "" : " " + this.selectedFields[i].operatorId + " ") + this.selectedFields[i].id + this.fieldIdsMap[this.selectedFields[i].id].equalityOperator + '"' + encodeURIComponent(this.selectedFields[i].value) + '"' + " ";
874

    
875
          }
876
        }
877
        countParams++;
878
      }
879
    }
880

    
881
    // console.log("ParameterS:")
882
    // console.log(params)
883
    return params;
884
  }
885
  public static createKeywordQuery(entityType:string, value:string, id, operatorId, countParams=0){
886
    let params = "";
887
    let doisParams = "";
888
    var DOIs: Identifier[] = Identifier.getIdentifiersFromString(value);
889
    if ((entityType == 'publication' || entityType == 'dataset' || entityType == 'software' || entityType == 'other' || entityType == "result")) {
890
      for (let identifier of DOIs) {
891
        // console.log(identifier)
892
        // pidclassid exact \"doi\" and pid exact \"10.1016/j.nima.2015.11.134\"
893
        //and (authorid exact \"0000-0001-7291-3210 \" )"
894
        if(identifier.class == "ORCID"){
895
          doisParams += (doisParams.length > 0 ? " or " : "") +'(authorid="' + identifier.id + '")';
896
        }else{
897
          doisParams += (doisParams.length > 0 ? " or " : "") +'(pidclassid exact "' + identifier.class + '" and pid="' +  identifier.id + '")';
898
        }
899
      }
900
    }
901
    if (doisParams.length > 0) {
902
      params += "(" + this.createQuotedKeywordQuery(value, id, operatorId ,countParams,true, true) + " or " + doisParams+")";
903
    } else {
904
      //if it is PIDs but no doisquery produced, forced to use quotes as the query will fail due to special characters
905
      params += this.createQuotedKeywordQuery(value, id, operatorId,countParams,true,
906
        (DOIs.length > 0 && doisParams.length == 0) );
907
    }
908
    return params;
909

    
910
  }
911
  private static createQuotedKeywordQuery(fieldValue, fieldId, fieldOperator, countParams:number, isSearchAll:boolean, forceQuotted:boolean=false){
912
    let params = "";
913
    let countQuote = (fieldValue.match(/'/g) || []).length;
914
    let countDoubleQuote = (fieldValue.match(/"/g) || []).length;
915
    let quotedParts = [];
916
    if(countQuote % 2 == 0 && countDoubleQuote % 2 ==0){
917
      quotedParts = (fieldValue)?fieldValue.match(/(["'])(.*?)*?\1/g):[];
918
    }
919
    params+= (countParams == 0 ? "" : fieldOperator);
920
    params+=   " (";
921
    if(forceQuotted){
922
      return (countParams == 0 ? "" : " "+fieldOperator+" ") + this.getQuotedQueryPart(fieldId, '"'+ fieldValue+'"',isSearchAll);
923
    }
924
    if(quotedParts && quotedParts.length == 1 && quotedParts[0] == fieldValue ){
925
      params+=this.getQuotedQueryPart(fieldId, fieldValue,isSearchAll);
926
    }else if( quotedParts && quotedParts.length > 0){
927
      for(let i=0; i< quotedParts.length; i++){
928
        params+=(i>0)?" and ":"";
929
        params+=this.getQuotedQueryPart(fieldId, quotedParts[i],isSearchAll);
930
      }
931
      let startPoint = 0;
932
      let endPoint = 0;
933
      for(let i=0; i< quotedParts.length; i++){
934
        let index = fieldValue.indexOf(quotedParts[i]);
935
        endPoint = (i+1<quotedParts.length)? fieldValue.indexOf(quotedParts[i+1]):fieldValue.length;
936
        // console.log(fieldValue.indexOf(quotedParts[i+1]) +" - "+fieldValue.length);
937
        // console.log(" SP "+ startPoint+" EP: "+endPoint);
938
        if(index==startPoint){
939
          startPoint +=quotedParts[i].length;
940
        }else if(startPoint < index){
941
          endPoint = index;
942
        }
943
        // console.log(" SP "+ startPoint+" EP: "+endPoint);
944
        if(decodeURIComponent(fieldValue.substring(startPoint,endPoint)).split(" ").join("").length > 0) {
945
          params += " and " + this.getNoQuotedQueryPart(fieldId, fieldValue.substring(startPoint, endPoint), isSearchAll);
946
        }
947
        // console.log("For "+i+"  " +params+" SP "+ startPoint+" EP: "+endPoint);
948
        // startPoint = (i+1<quotedParts.length)? fieldValue.indexOf(quotedParts[i+i]):fieldValue.length;//(startPoint<index  )?(index + quotedParts[i].length):fieldValue.length;
949
        startPoint = ((i+1<quotedParts.length)?(fieldValue.indexOf(quotedParts[i+1])+quotedParts[i+1].length):(endPoint== index?(index+quotedParts[i].length):endPoint));
950
      }
951
      if(startPoint !=fieldValue.length && decodeURIComponent(fieldValue.substring(startPoint,fieldValue.length)).split(" ").join("").length > 0){
952
        params+=" and " + this.getNoQuotedQueryPart(fieldId, fieldValue.substring(startPoint,fieldValue.length),isSearchAll);
953
      }
954
    }else{
955
      params+=this.getNoQuotedQueryPart(fieldId, fieldValue,isSearchAll);
956
    }
957
    params += ")";
958
    return params;
959
  }
960

    
961
  private static getQuotedQueryPart(fieldId:string, value:string,  isSearchAll:boolean){
962
      return (isSearchAll?"__all":fieldId)+" exact "+StringUtils.URIEncode(value);
963
  }
964
  private static getNoQuotedQueryPart(fieldId:string, value:string,  isSearchAll:boolean){
965
    //split the keywords of the vlaue and query seperately for each keyword using quotes to allow characters like .@
966
    let valueKeywords= value.split(" ");
967
    let query = "";
968
    let i=0;
969
    for(let keyword of valueKeywords ){
970
      if(keyword.length > 0){
971
        query+= (i!=0?" and ":"")+(isSearchAll?"(":fieldId+"=")+"\""+StringUtils.URIEncode(keyword) +"\""+ (isSearchAll?")":"");
972
        i++;
973
      }
974
    }
975
    return query
976
  }
977

    
978
  /**
979
   * Create Search API query based on the filters of refine fields
980
   * @param URLparams
981
   * @param firstLoad
982
   */
983
  getSearchAPIQueryForRefineFields(URLparams, firstLoad: boolean) {
984

    
985
    var allFqs = "";
986
    // console.log(this.refineFields)
987
    for (var i = 0; i < this.refineFields.length; i++) {
988
      var filterId = this.refineFields[i];
989

    
990
      if (URLparams[filterId] != undefined) {
991
        let values = (StringUtils.URIDecode(StringUtils.URIDecode(URLparams[filterId]))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
992
        var countvalues = 0;
993
        var fq = "";
994
        let filterOp: string = this.searchFieldsHelper.getFieldOperator(filterId);
995
        // console.info(filterId, filterOp);
996
        for (let value of values) {
997
          countvalues++;
998
          var paramId = this.fieldIdsMap[filterId].param;
999
          // parameters+='&' + paramId+ '='+ value;//+"&" + this.fieldIdsMap[paramId].operator + "="+((countvalues == 1)?"and":"or");
1000
          fq += (fq.length > 0 ? " " + filterOp + " " : "") + filterId + " exact " + (value);
1001
        }
1002
        if (countvalues > 0) {
1003
          fq = "&fq=" + StringUtils.URIEncode(fq);
1004
        }
1005
        allFqs += fq;
1006
      }
1007
    }
1008
    this.customFilterEnabled = URLparams["cf"] == "true";
1009
    if(this.customFilter && (this.customFilter.isHiddenFilter || (this.refineFields.indexOf(this.customFilter.queryFieldName) == -1 && this.customFilterEnabled))){
1010
      allFqs += "&fq=" + StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId)));
1011
    }
1012

    
1013
    if (this.quickFilter && this.entityType == "result") {
1014
      if((firstLoad && URLparams[this.quickFilter.filterId] == undefined && URLparams["qf"] == undefined)   || URLparams["qf"] == "true"
1015
        || ((URLparams[this.quickFilter.filterId] != undefined && StringUtils.URIDecode(URLparams[this.quickFilter.filterId]).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1).indexOf(StringUtils.quote(this.quickFilter.value)) != -1))) {
1016
        this.quickFilter.selected = true;
1017
      } else {
1018
        this.quickFilter.selected = false;
1019
      }
1020
      if ((firstLoad && URLparams[this.quickFilter.filterId] == undefined && URLparams["qf"] == undefined)
1021
      ||( URLparams[this.quickFilter.filterId] == undefined && URLparams["qf"] == "true")) {
1022
        allFqs += "&fq=resultbestaccessright exact " + StringUtils.quote(this.quickFilter.value);
1023
      }
1024
    }
1025

    
1026
    if (this.entityType == "result") {
1027
      if (URLparams["type"]) {
1028
        let types = URLparams["type"].split(",");
1029
        if(types.indexOf("publications")!=-1 && types.indexOf("datasets")!=-1 && types.indexOf("software")!=-1 && types.indexOf("other")!=-1 ){
1030
          allFqs += "&type=results";
1031
        }else{
1032
          for (let type of types) {
1033
            allFqs += "&type=" + type;
1034
          }
1035
        }
1036
      }else{
1037
        allFqs += "&type=results";
1038
      }
1039
    } else if (this.entityType == "publication") {
1040
      allFqs += "&type=publications";
1041
    } else if (this.entityType == "dataset") {
1042
      allFqs += "&type=datasets";
1043
    } else if (this.entityType == "software") {
1044
      allFqs += "&type=software";
1045
    } else if (this.entityType == "other") {
1046
      allFqs += "&type=other";
1047
    } else if(this.entityType == "project") {
1048
      allFqs += "&type=projects";
1049
    } else if(this.entityType == "organization") {
1050
      allFqs += "&type=organizations";
1051
    } else if(this.entityType == "dataprovider") {
1052
      allFqs += "&type=datasources";
1053
    }
1054
    // console.log("AllFqs (check type): "+allFqs);
1055
    // console.log("type: "+this.entityType);
1056
    // var keyword = URLparams['keyword'];
1057
    // var doiQuery = "";
1058
    // var keywordQuery = "";
1059
    // if((keyword && keyword.length > 0)){
1060
    //   if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
1061
    //     var DOIs:string[] = DOI.getDOIsFromString(keyword);
1062
    //     var doisParams = "";
1063
    //
1064
    //     for(var i =0 ;i < DOIs.length; i++){
1065
    //       doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
1066
    //     }
1067
    //     if(doisParams.length > 0){
1068
    //       doiQuery += "&"+doisParams;
1069
    //     }else {
1070
    //       keywordQuery += "&q="+StringUtils.URIEncode(keyword);
1071
    //     }
1072
    //   }else{
1073
    //     if(this.usedBy == "deposit") {
1074
    //       if(this.keywordFields.length > 0) {
1075
    //         keywordQuery = "&fq=";
1076
    //       }
1077
    //
1078
    //       for(let i=0; i< this.keywordFields.length ; i++) {
1079
    //         if(i > 0) {
1080
    //           keywordQuery += " or ";
1081
    //         }
1082
    //         let field = this.keywordFields[i];
1083
    //         //keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(keyword);
1084
    //         keywordQuery += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(keyword));
1085
    //       }
1086
    //     } else {
1087
    //       keywordQuery += "&q=" + StringUtils.URIEncode(keyword);
1088
    //     }
1089
    //
1090
    //   }
1091
    // }
1092
    //TODO add DOI?
1093
     return allFqs;
1094

    
1095
  }
1096

    
1097
  /**
1098
   * Create Search API query based on the filters of refine fields
1099
   * @param URLparams
1100
   */
1101
  getSearchAPIQueryForRangeFields(URLparams) {
1102
    let allFqs = "";
1103
    for (let i = 0; i < this.rangeFields.length; i++) {
1104
      let filterId = this.rangeFields[i][0]+"-range-"+this.rangeFields[i][1];
1105
      let filterParam = this.searchFieldsHelper.getFieldParam(filterId, this.entityType);
1106

    
1107
      if (URLparams[filterParam] != undefined) {
1108
        let values = (StringUtils.URIDecode(StringUtils.URIDecode(URLparams[filterParam]))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
1109
        var countvalues = 0;
1110
        var fq = "";
1111
        var fqFrom = "";
1112
        var fqTo = "";
1113
        let filterOp: string = this.searchFieldsHelper.getFieldOperator(filterId);
1114

    
1115
        for (let value of values) {
1116
          if (this.fieldIdsMap[filterId].filterType == "range") {
1117

    
1118
            let selectedFromValue;
1119
            let selectedToValue;
1120

    
1121
            let years: string[] = (value.substring(5)).split(":");
1122
            let yearFrom: string = (Dates.isValidYear(years[0]) ? years[0] : null);
1123
            //(Number.isInteger(parseInt(years[0], 10)) ? years[0] : null);
1124
            let yearTo: string = (Dates.isValidYear(years[1]) ? years[1] : null);
1125
            //console.log("getSearchAPIQueryForRangeFields: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
1126
            if(yearFrom) {
1127
              selectedFromValue = yearFrom;
1128
            }
1129
            if(yearTo) {
1130
              selectedToValue = yearTo;
1131
            }
1132
            if(yearFrom || yearTo) {
1133

    
1134
            // if (value.length <= 14) {
1135
            //   if(Dates.isValidYear(value.substring(5, 9))) {
1136
            //     selectedFromValue = value.substring(5, 9);
1137
            //   }
1138
            //   if(Dates.isValidYear(value.substring(10, 14))) {
1139
            //     selectedToValue = value.substring(10, 14);
1140
            //   }
1141

    
1142
              /*if(this.rangeFields[i][0] == this.rangeFields[i][1]) {
1143
                //console.log(selectedFromValue + " - "+selectedToValue);
1144
                if (selectedFromValue && selectedToValue) {
1145
                  let equalityOp = this.fieldIdsMap[filterId].equalityOperator;
1146
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOp + "\"" + selectedFromValue + " " + selectedToValue + "\"";
1147
                  fq = "&fq=" + StringUtils.URIEncode(fq);
1148
                } else if (selectedFromValue) {
1149
                  let equalityOp = this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator;
1150
                  if(equalityOp == " = ") {
1151
                    equalityOp = " >= ";
1152
                  }
1153
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOp + "\"" + selectedFromValue + "\"";
1154
                  fq = "&fq=" + StringUtils.URIEncode(fq);
1155
                } else if (selectedToValue) {
1156
                  let equalityOp = this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator;
1157
                  if(equalityOp == " = ") {
1158
                    equalityOp = " <= ";
1159
                  }
1160
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOp + "\"" + selectedToValue + "\"";
1161
                  fq = "&fq=" + StringUtils.URIEncode(fq);
1162
                }
1163
              } else {
1164
                let equalityOpFrom = this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator;
1165
                let equalityOpTo = this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator;
1166

    
1167
                if (selectedFromValue) {
1168
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOpFrom + "\"" + selectedFromValue + "\"";
1169
                  // fq = "&fq=" + StringUtils.URIEncode(fq);
1170
                }
1171
                if (selectedToValue) {
1172
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][1] + equalityOpTo + "\"" + selectedToValue + "\"";
1173
                  // fq = "&fq=" + StringUtils.URIEncode(fq);
1174
                }
1175
                if(selectedFromValue || selectedToValue) {
1176
                  fq = "&fq=" + StringUtils.URIEncode(fq);
1177
                }
1178
              }*/
1179
              fq = NewSearchPageComponent.createRangeFilterQuery(this.rangeFields[i], selectedFromValue, selectedToValue, this.fieldIdsMap[filterId].equalityOperator, this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator, this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator, filterOp );
1180
            }
1181
          }
1182
        }
1183
        allFqs += fq +fqFrom + fqTo;
1184
      }
1185
    }
1186

    
1187
    return allFqs;
1188

    
1189
  }
1190
  // createRangeFilterQuery(this.rangeFields[i], selectedFromValue, selectedToValue, this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator, this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator; filterOp )
1191
public static createRangeFilterQuery(rangeField,selectedFromValue, selectedToValue, equalityOp, equalityOpFrom, equalityOpTo, filterOp ){
1192
    let fq="";
1193
  if(rangeField[0] == rangeField[1]) {
1194
    //console.log(selectedFromValue + " - "+selectedToValue);
1195
    if (selectedFromValue && selectedToValue) {
1196
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOp + "\"" + selectedFromValue + " " + selectedToValue + "\"";
1197
      fq = "&fq=" + StringUtils.URIEncode(fq);
1198
    } else if (selectedFromValue) {
1199
      if(equalityOpFrom == " = ") {
1200
        equalityOpFrom = " >= ";
1201
      }
1202
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOpFrom + "\"" + selectedFromValue + "\"";
1203
      fq = "&fq=" + StringUtils.URIEncode(fq);
1204
    } else if (selectedToValue) {
1205
      if(equalityOpTo == " = ") {
1206
        equalityOpTo = " <= ";
1207
      }
1208
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOpTo + "\"" + selectedToValue + "\"";
1209
      fq = "&fq=" + StringUtils.URIEncode(fq);
1210
    }
1211
  } else {
1212

    
1213
    if (selectedFromValue) {
1214
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOpFrom + "\"" + selectedFromValue + "\"";
1215
      // fq = "&fq=" + StringUtils.URIEncode(fq);
1216
    }
1217
    if (selectedToValue) {
1218
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[1] + equalityOpTo + "\"" + selectedToValue + "\"";
1219
      // fq = "&fq=" + StringUtils.URIEncode(fq);
1220
    }
1221
    if(selectedFromValue || selectedToValue) {
1222
      fq = "&fq=" + StringUtils.URIEncode(fq);
1223
    }
1224

    
1225
  }
1226
  return fq;
1227
}
1228
  /**
1229
   * Sets parameterNames and parameterValues arrays
1230
   * used in paging, advanced search link, Goto()
1231
   * @param filters either query filters or filters defined by the URL parameters
1232
   * @param rangeFilters defined by the URL parameters
1233
   * @param includePage
1234
   */
1235
  buildPageURLParameters(filters:Filter[], rangeFilters: RangeFilter[], includePage: boolean) {
1236
    this.parameterNames.splice(0, this.parameterNames.length);
1237
    this.parameterValues.splice(0, this.parameterValues.length);
1238
    for (var i = 0; i < this.selectedFields.length; i++) {
1239
      //default operator is and
1240
      this.parameterNames.push("f"+i);
1241
      this.parameterValues.push(this.selectedFields[i].id + (this.selectedFields[i].operatorId!='and'?(","+this.selectedFields[i].operatorId):''));
1242
      this.parameterNames.push("fv"+i);
1243
      if (this.selectedFields[i].type == "date") {
1244

    
1245
        if (this.selectedFields[i].dateValue.type == "range") {
1246
          this.parameterValues.push(StringUtils.URIEncode("range" + Dates.getDateToString(this.selectedFields[i].dateValue.from) + ":" + Dates.getDateToString(this.selectedFields[i].dateValue.to)));
1247
        } else {
1248
          this.parameterValues.push(StringUtils.URIEncode(this.selectedFields[i].dateValue.type));
1249
        }
1250

    
1251
      } else {
1252
        // console.log(this.selectedFields[i].value +" " + StringUtils.URIEncode(this.selectedFields[i].value))
1253
        this.parameterValues.push(StringUtils.URIEncode(this.selectedFields[i].value));
1254
      }
1255
    }
1256
    if (includePage) {
1257
      this.parameterNames.push("page");
1258
      this.parameterValues.push("" + this.searchUtils.page);
1259
    }
1260

    
1261
    //if (this.searchUtils.size != this.resultsPerPage) {
1262
    if (this.resultsPerPageChanged) {
1263
      this.parameterNames.push("size");
1264
      //this.parameterValues.push("" + this.searchUtils.size);
1265
      this.parameterValues.push("" + this.resultsPerPageChanged);
1266
    }
1267

    
1268
    //if (this.sort && this.searchUtils.sortBy) {
1269
    if (this.sort && this.sortByChanged) {
1270
      this.parameterNames.push("sortBy");
1271
      //this.parameterValues.push(this.searchUtils.sortBy);
1272
      this.parameterValues.push(this.sortedByChanged);
1273
    }
1274
    for (let filter of filters) {
1275
      var filterLimits = "";
1276
      if (filter.countSelectedValues > 0) {
1277
        for (let value of filter.values) {
1278
          if (value.selected == true) {
1279
            filterLimits += ((filterLimits.length == 0) ? '' : ',') + '"' + (value.id) + '"';
1280
          }
1281
        }
1282
        if (filterLimits.length > 0) {
1283
          this.parameterNames.push(filter.filterId);
1284
          this.parameterValues.push(filterLimits);
1285
        }
1286
      }
1287
    }
1288
    for (let filter of rangeFilters) {
1289
      var filterLimits = "";
1290
      let yearFrom: string = (Dates.isValidYear(filter.selectedFromValue) ? filter.selectedFromValue : null);
1291
      let yearTo: string = (Dates.isValidYear(filter.selectedToValue) ? filter.selectedToValue : null);
1292
      if(yearFrom || yearTo) {
1293
        this.parameterNames.push(filter.filterId);
1294
        this.parameterValues.push("range" + (yearFrom ? yearFrom : "") + ":" + (yearTo ? yearTo : ""));
1295
      }
1296
      // if (filter.countSelectedValues > 0) {
1297
      //   for (let value of filter.values) {
1298
      //     if (value.selected == true) {
1299
      //       filterLimits += ((filterLimits.length == 0) ? '' : ',') + '"' + (value.id) + '"';
1300
      //     }
1301
      //   }
1302
      //   if (filterLimits.length > 0) {
1303
      //     this.parameterNames.push(filter.filterId);
1304
      //     this.parameterValues.push(filterLimits);
1305
      //   }
1306
      // }
1307
    }
1308
    if (this.searchUtils.keyword.length > 0) {
1309
      this.parameterNames.push("keyword");
1310
      this.parameterValues.push(this.searchUtils.keyword);
1311
    }
1312

    
1313
    if (this.resultTypes && this.entityType == "result") {
1314
      let values = [];
1315
      if (this.resultTypes.publication) {
1316
        values.push("publications");
1317
      }
1318
      if (this.resultTypes.dataset) {
1319
        values.push("datasets");
1320
      }
1321
      if (this.resultTypes.software) {
1322
        values.push("software");
1323
      }
1324
      if (this.resultTypes.other) {
1325
        values.push("other");
1326
      }
1327
      this.selectedTypesNum = 0;
1328
      if (values.length > 0 && values.length != 4) {
1329
        this.parameterNames.push("type");
1330
        this.parameterValues.push(values.join(","));
1331
        this.selectedTypesNum = values.length;
1332
      }
1333
      if(this.quickFilter) {
1334
        this.parameterNames.push("qf");
1335
        this.parameterValues.push("" + this.quickFilter.selected);
1336
      }
1337
    }
1338
    if(this.customFilterEnabled){
1339
      this.parameterNames.push("cf");
1340
      this.parameterValues.push("true");
1341
    }
1342
    // if (this.searchUtils.size != this.resultsPerPage) {
1343
    //   // allLimits += ((allLimits.length == 0) ? '?' : '&') + 'size=' + this.searchUtils.size;
1344
    //   this.parameterNames.push("size");
1345
    //   this.parameterValues.push("" + this.searchUtils.size);
1346
    // }
1347
    // if (this.sort && this.searchUtils.sortBy) {
1348
    //   // allLimits += ((allLimits.length == 0) ? '?' : '&') + 'sortBy=' + this.searchUtils.sortBy;
1349
    //   this.parameterNames.push("sortBy");
1350
    //   this.parameterValues.push(this.searchUtils.sortBy);
1351
    // }
1352
    // console.log(this.parameterNames)
1353
    // console.log(this.parameterValues)
1354
  }
1355

    
1356
  /**
1357
   * create filters based on URL params
1358
   * @param URLparams
1359
   */
1360
  getRefineFiltersFromURL(URLparams) {
1361
    let fields = new SearchFields();
1362
    let filters: Filter[] = [];
1363
    for (let i = 0; i < this.refineFields.length; i++) {
1364
      let filterId = this.refineFields[i];
1365
      if (URLparams[filterId] != undefined) {
1366
        let filter = new Filter();
1367
        filter.title = fields.getFieldName(filterId, this.entityType);
1368
        filter.filterId = filterId;
1369
        filter.originalFilterId = filterId;
1370
        filter.values = [];
1371
        let values = StringUtils.URIDecode(URLparams[filterId]).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
1372
        for (let value of values) {
1373

    
1374
          let v: Value = new Value();
1375
          v.name = RefineResultsUtils.keepPartAfterCharacters(StringUtils.unquote(value), "||");
1376
          v.name = (v.name.indexOf("::")!=-1)?v.name.substring(v.name.indexOf("::")+2).split("::").join("|"):v.name; // for funding streams
1377
          v.id = StringUtils.unquote(value);
1378
          v.selected = true;
1379
          filter.values.push(v);
1380
          // console.log(v)
1381
          filter.countSelectedValues++;
1382
        }
1383
        filters.push(filter)
1384
      }
1385
    }
1386

    
1387
    if (this.quickFilter) {
1388
      if (this.entityType == "result" && (URLparams[this.quickFilter.filterId] == undefined) && (URLparams["qf"] == undefined || URLparams["qf"] == "true")) {
1389
        let filter = new Filter();
1390
        filter.title = fields.getFieldName(this.quickFilter.filterId, this.entityType);
1391
        filter.filterId = this.quickFilter.filterId;
1392
        filter.originalFilterId = this.quickFilter.filterId;
1393
        filter.values = [];
1394
        let v: Value = new Value();
1395
        v.name = this.quickFilter.value;
1396
        v.id = this.quickFilter.value;
1397
        v.selected = true;
1398
        filter.values.push(v);
1399
        filter.countSelectedValues = 1;
1400
        filters.push(filter)
1401
      }
1402
    }
1403
    if (this.entityType == "result") {
1404
      this.resultTypes = null;
1405
      this.resultTypes = {
1406

    
1407
      };
1408

    
1409
      if (URLparams["type"]) {
1410

    
1411
        this.resultTypes['publication'] = (URLparams["type"].split(",").indexOf("publications") != -1);
1412
        this.resultTypes['dataset'] = (URLparams["type"].split(",").indexOf("datasets") != -1);
1413
        this.resultTypes['software'] = (URLparams["type"].split(",").indexOf("software") != -1);
1414
        this.resultTypes['other'] = (URLparams["type"].split(",").indexOf("other") != -1);
1415

    
1416
      } else {
1417
        this.resultTypes['publication'] = false;
1418
        this.resultTypes['dataset'] = false;
1419
        this.resultTypes['software'] = false;
1420
        this.resultTypes['other'] = false;
1421
      }
1422

    
1423
    }
1424

    
1425
    this.URLCreatedFilters = filters;
1426
  }
1427

    
1428
  /**
1429
   * create range filters based on URL params
1430
   * @param URLparams
1431
   */
1432
  getRangeFiltersFromURL(URLparams) {
1433
    let fields = new SearchFields();
1434
    let filters: RangeFilter[] = [];
1435
    for (let i = 0; i < this.rangeFields.length; i++) {
1436
      let filterId = this.rangeFields[i][0]+"-range-"+this.rangeFields[i][1];
1437
      let filterParam = fields.getFieldParam(filterId, this.entityType);
1438
      //console.log("rangeFilter (from url): filterId - filterParam");
1439
      //console.log(filterId + " - "+ filterParam);
1440
      if (URLparams[filterParam] != undefined) {
1441
        let filter = new RangeFilter();
1442
        filter.title = fields.getFieldName(filterId, this.entityType);
1443
        filter.filterId = filterParam;
1444
        filter.originalFilterIdFrom = this.rangeFields[i][0];
1445
        filter.originalFilterIdTo = this.rangeFields[i][1];
1446

    
1447

    
1448
        let values = (decodeURIComponent(URLparams[filterParam])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
1449
        for (let j = 0; j < values.length; j++) {
1450
          if (this.fieldIdsMap[filterId].filterType == "range") {
1451
            let value: string = StringUtils.unquote(values[j]);
1452
            let validDates: boolean = true;
1453
            // if (value.length < 14) {
1454
            //   validDates = false;
1455
            // } else {
1456
            //   if (!Dates.isValidYear(value.substring(5, 9)) || !Dates.isValidYear(value.substring(10, 14))) {
1457
            //     validDates = false;
1458
            //   } else {
1459
            //     filter.selectedFromValue = value.substring(5, 9);
1460
            //     filter.selectedToValue = value.substring(10, 14);
1461
            //   }
1462
            // }
1463
            let years: string[] = (value.substring(5)).split(":");
1464
            let yearFrom: string = (Dates.isValidYear(years[0]) ? years[0] : null);
1465
            let yearTo: string = (Dates.isValidYear(years[1]) ? years[1] : null);
1466
            //console.log("getRangeFiltersFromURL: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
1467
            if(yearFrom) {
1468
              filter.selectedFromValue = yearFrom;
1469
              //filter.selectedFromAndToValues = yearFrom;
1470
            }
1471
            /*if(yearFrom && yearTo) {
1472
              filter.selectedFromAndToValues += "-";
1473
            }*/
1474
            if(yearTo) {
1475
              filter.selectedToValue = yearTo;
1476
              //filter.selectedFromAndToValues += yearTo;
1477
            }
1478
            //console.log("filter.selectedFromAndToValues: "+filter.selectedFromAndToValues);
1479
            if(!yearFrom && !yearTo) {
1480
              validDates = false;
1481
            }
1482

    
1483
          }
1484
        }
1485
        //console.log(filters);
1486
        filters.push(filter)
1487
      }
1488
    }
1489
    // console.log("Empty Filters");
1490
    // console.log(filters);
1491
    this.URLCreatedRangeFilters = filters;
1492
    // return filters;
1493

    
1494
  }
1495

    
1496
  /**
1497
   * Checks if query has no results, display Filters from URL parameters
1498
   * Mark checked  the selected filters
1499
   * Count the checked
1500
   * @param filters
1501
   */
1502
  public prepareFiltersToShow(filters: Filter[], totalResults): Filter[] {
1503
    if (this.URLCreatedFilters.length > 0 && totalResults == 0) {
1504
      this.showUnknownFilters = true;
1505
      this.filters = this.URLCreatedFilters;
1506
    } else if (totalResults != 0) {
1507
      this.showUnknownFilters = false;
1508
      this.filters = filters;
1509
    }else if((this.URLCreatedFilters.length == 0 && totalResults == 0)){
1510
      this.showUnknownFilters = true;
1511
      this.filters = filters;
1512
    }
1513

    
1514
    this.buildPageURLParameters(this.URLCreatedFilters, this.URLCreatedRangeFilters, true);
1515
    //this.checkSelectedRangeFilters(this.rangeFilters);
1516

    
1517
    this.checkSelectedFilters(this.filters);
1518
    this.countSelectedFilters(this.filters);
1519
    return this.filters;
1520
  }
1521

    
1522
  /**
1523
   * Mark checked  the selected range filters
1524
   */
1525
  public prepareRangeFiltersToShow() {
1526
    this.rangeFilters = RangeFilter.parse(this.rangeFields, this.entityType); // OK
1527

    
1528
    //this.buildPageURLRangeParameters(this.rangeFilters, true);
1529
    this.checkSelectedRangeFilters(this.rangeFilters);
1530
    this.countSelectedRangeFilters(this.rangeFilters);
1531
    return this.rangeFilters;
1532
  }
1533

    
1534
  /**
1535
   * Used to set the variables and search page, and prepare it before the getResults query
1536
   * @param fieldIds
1537
   * @param selectedFields
1538
   * @param refineFields
1539
   * @param rangeFields
1540
   * @param fieldIdsMap
1541
   * @param customFilter
1542
   * @param params
1543
   * @param entityType
1544
   * @param quickFilter
1545
   */
1546
  prepareSearchPage(fieldIds, selectedFields, refineFields, rangeFields, fieldIdsMap, customFilter, params, entityType, quickFilter=null){
1547
    // console.log(this.refineFields);
1548
    this.entityType = entityType;
1549
    this.fieldIds = fieldIds;
1550
    this.selectedFields = selectedFields;
1551
    this.refineFields = refineFields;
1552
    this.rangeFields = rangeFields;
1553
    this.fieldIdsMap = fieldIdsMap;
1554
    this.customFilter = customFilter;
1555
    this.quickFilter = quickFilter;
1556
    this.getRangeFiltersFromURL(params);
1557
    this.getRefineFiltersFromURL(params);
1558
    this.createAdvancedSearchSelectedFiltersFromURLParameters(params);
1559
  }
1560

    
1561
  removeResultType(type){
1562
    if(this.resultTypes && this.resultTypes[type]){
1563
      this.resultTypes[type]=false;
1564
      this.goTo(1);
1565
    }
1566
  }
1567
}
(17-17/55)