Project

General

Profile

1
import {ChangeDetectorRef, 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
import {Subscriber} from "rxjs";
26

    
27
declare var UIkit: any;
28

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

    
93
  subscriptions = [];
94
  public parameterNames: string[] = [];
95
  public parameterValues: string[] = [];
96

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

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

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

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

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

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

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

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

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

    
201
  ngOnDestroy() {
202
    this.subscriptions.forEach(subscription => {
203
      if (subscription instanceof Subscriber) {
204
        subscription.unsubscribe();
205
      }
206
    });
207
  }
208

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

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

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

    
263

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

    
290
  goTo(page: number = 1, scroll:boolean = true) {
291
    if(this.offcanvasElement && (typeof document !== 'undefined')) {
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.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe());
308
    }
309
    /* End Piwik Code */
310
  }
311

    
312
  queryChanged($event) {
313
    if($event == "filters_update"){
314
      this.cdr.detectChanges();
315
      return;
316
    }
317
    this.goTo(1, false);
318
  }
319

    
320

    
321
  sizeChanged($event) {
322
    //this.searchUtils.size = $event.value;
323
    this.resultsPerPageChanged = $event;
324

    
325
    this.goTo(1);
326
  }
327

    
328
  sortByChanged($event) {
329
    //this.searchUtils.sortBy = $event.value;
330
    this.sortedByChanged = $event;
331
    this.goTo(1);
332
  }
333

    
334

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

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

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

    
371
  /*
372
  * 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 )
373
  */
374
  public getFields(): string[] {
375
    var selected_filters: string[] = this.getSelectedFilters();
376
    if (selected_filters.length == 0) {
377
      selected_filters = this.getSelectedParameters();
378
    }
379
    var fields: string[] = [];
380
    for (var i = 0; i < this.refineFields.length; i++) {
381
      var dependentTo = this.searchFieldsHelper.DEPENDENT_FIELDS[this.refineFields[i]];
382

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

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

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

    
404

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

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

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

    
466
    this.rangeFilters = filters;
467
    for (let i = 0; i < filters.length; i++) {
468
      let filter: RangeFilter = filters[i];
469

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

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

    
498
              if(!yearFrom && !yearTo) {
499
                validDates = false;
500
              }
501

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

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

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

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

    
560
        }
561
        if (filteredValues.length > 0) {
562
          filter.values = filteredValues;
563
        }
564
      }
565

    
566
    }
567

    
568
    return filters;
569
  }
570

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

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

    
591
  private clearKeywords() {
592
    if (this.searchUtils.keyword.length > 0) {
593
      this.searchUtils.keyword = '';
594
    }
595
    this.goTo(1);
596
  }
597

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

    
626
  closeCustomFilterModal() {
627
    this.removeFilter(this.currentValueToRemove, this.currentFilterToRemove, true);
628
    this.isCustomFilterSelected = false;
629
  }
630

    
631
  public removeRangeFilter(filter: RangeFilter) {
632
    filter.selectedFromValue = null;
633
    filter.selectedToValue = null;
634
    this.goTo(1);
635
  }
636

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

    
648
  }
649

    
650
  filterChanged($event) {
651
    if (this.quickFilter && this.quickFilter.filter) {
652
      this.removeValueFromQuickFilter();
653
    }
654
    this.goTo(1);
655

    
656
  }
657

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

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

    
694
  }
695
  // for loading
696
  public openLoading() {
697
    this.loading.open();
698
  }
699

    
700
  public closeLoading() {
701
    this.loading.close();
702
  }
703

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

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

    
743
          } else {
744
            this.selectedFields.push(new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type,value, operator));
745
          }
746

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

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

    
794
            } else {
795
              this.selectedFields.push(new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type, values[j], operators[j]));
796
            }
797
          }
798
        }
799
      }
800
    }
801
    if (params['keyword'] && params['keyword'].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, params['keyword'], "and"));
803
    }
804
    if (this.selectedFields.length == 0) {
805
      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"));
806
    }
807
  }
808

    
809
  /**
810
   * Create Search API query based on the selected fields of the advanced form
811
   */
812
  getSearchAPIQueryForAdvancedSearhFields() {
813

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

    
852
            if(this.usedBy == "deposit") {
853

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

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

    
878
          }
879
        }
880
        countParams++;
881
      }
882
    }
883

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

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

    
964
  private static getQuotedQueryPart(fieldId:string, value:string,  isSearchAll:boolean){
965
      return (isSearchAll?"__all":fieldId)+" exact "+StringUtils.URIEncode(value);
966
  }
967
  private static getNoQuotedQueryPart(fieldId:string, value:string,  isSearchAll:boolean){
968
    //split the keywords of the vlaue and query seperately for each keyword using quotes to allow characters like .@
969
    let valueKeywords= value.split(" ");
970
    let query = "";
971
    let i=0;
972
    for(let keyword of valueKeywords ){
973
      if(keyword.length > 0){
974
        query+= (i!=0?" and ":"")+(isSearchAll?"(":fieldId+"=")+"\""+StringUtils.URIEncode(this.checkForReservedWords(keyword)) +"\""+ (isSearchAll?")":"");
975
        i++;
976
      }
977
    }
978
    return query
979
  }
980
  private static checkForReservedWords(keyword:string){
981
    let reservedWords = ["AND", "OR", "NOT"];
982
    if(reservedWords.indexOf(keyword)!=-1){
983
      return keyword.toLowerCase();
984
    }
985
    return keyword;
986
  }
987
  /**
988
   * Create Search API query based on the filters of refine fields
989
   * @param URLparams
990
   * @param firstLoad
991
   */
992
  getSearchAPIQueryForRefineFields(URLparams, firstLoad: boolean) {
993

    
994
    var allFqs = "";
995
    // console.log(this.refineFields)
996
    for (var i = 0; i < this.refineFields.length; i++) {
997
      var filterId = this.refineFields[i];
998

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

    
1022
    if (this.quickFilter && this.entityType == "result") {
1023
      if((firstLoad && URLparams[this.quickFilter.filterId] == undefined && URLparams["qf"] == undefined)   || URLparams["qf"] == "true"
1024
        || ((URLparams[this.quickFilter.filterId] != undefined && StringUtils.URIDecode(URLparams[this.quickFilter.filterId]).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1).indexOf(StringUtils.quote(this.quickFilter.value)) != -1))) {
1025
        this.quickFilter.selected = true;
1026
      } else {
1027
        this.quickFilter.selected = false;
1028
      }
1029
      if ((firstLoad && URLparams[this.quickFilter.filterId] == undefined && URLparams["qf"] == undefined)
1030
      ||( URLparams[this.quickFilter.filterId] == undefined && URLparams["qf"] == "true")) {
1031
        allFqs += "&fq=resultbestaccessright exact " + StringUtils.quote(this.quickFilter.value);
1032
      }
1033
    }
1034

    
1035
    if (this.entityType == "result") {
1036
      if (URLparams["type"]) {
1037
        let types = URLparams["type"];
1038
        types = Array.isArray(types) ? types.join(',').split(","):types.split(",");
1039
        types.map( function (t) {
1040
          return StringUtils.unquote(StringUtils.URIDecode(t));
1041
        } );
1042

    
1043
        if(types.indexOf("publications")!=-1 && types.indexOf("datasets")!=-1 && types.indexOf("software")!=-1 && types.indexOf("other")!=-1 ){
1044
          allFqs += "&type=results";
1045
        }else{
1046
          for (let type of types) {
1047
            allFqs += "&type=" + StringUtils.unquote(StringUtils.URIDecode(type));
1048
          }
1049
        }
1050
      }else{
1051
        allFqs += "&type=results";
1052
      }
1053
    } else if (this.entityType == "publication") {
1054
      allFqs += "&type=publications";
1055
    } else if (this.entityType == "dataset") {
1056
      allFqs += "&type=datasets";
1057
    } else if (this.entityType == "software") {
1058
      allFqs += "&type=software";
1059
    } else if (this.entityType == "other") {
1060
      allFqs += "&type=other";
1061
    } else if(this.entityType == "project") {
1062
      allFqs += "&type=projects";
1063
    } else if(this.entityType == "organization") {
1064
      allFqs += "&type=organizations";
1065
    } else if(this.entityType == "dataprovider") {
1066
      allFqs += "&type=datasources";
1067
    }
1068
    // console.log("AllFqs (check type): "+allFqs);
1069
    // console.log("type: "+this.entityType);
1070
    // var keyword = URLparams['keyword'];
1071
    // var doiQuery = "";
1072
    // var keywordQuery = "";
1073
    // if((keyword && keyword.length > 0)){
1074
    //   if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
1075
    //     var DOIs:string[] = DOI.getDOIsFromString(keyword);
1076
    //     var doisParams = "";
1077
    //
1078
    //     for(var i =0 ;i < DOIs.length; i++){
1079
    //       doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
1080
    //     }
1081
    //     if(doisParams.length > 0){
1082
    //       doiQuery += "&"+doisParams;
1083
    //     }else {
1084
    //       keywordQuery += "&q="+StringUtils.URIEncode(keyword);
1085
    //     }
1086
    //   }else{
1087
    //     if(this.usedBy == "deposit") {
1088
    //       if(this.keywordFields.length > 0) {
1089
    //         keywordQuery = "&fq=";
1090
    //       }
1091
    //
1092
    //       for(let i=0; i< this.keywordFields.length ; i++) {
1093
    //         if(i > 0) {
1094
    //           keywordQuery += " or ";
1095
    //         }
1096
    //         let field = this.keywordFields[i];
1097
    //         //keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(keyword);
1098
    //         keywordQuery += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(keyword));
1099
    //       }
1100
    //     } else {
1101
    //       keywordQuery += "&q=" + StringUtils.URIEncode(keyword);
1102
    //     }
1103
    //
1104
    //   }
1105
    // }
1106
    //TODO add DOI?
1107
     return allFqs;
1108

    
1109
  }
1110

    
1111
  /**
1112
   * Create Search API query based on the filters of refine fields
1113
   * @param URLparams
1114
   */
1115
  getSearchAPIQueryForRangeFields(URLparams) {
1116
    let allFqs = "";
1117
    for (let i = 0; i < this.rangeFields.length; i++) {
1118
      let filterId = this.rangeFields[i][0]+"-range-"+this.rangeFields[i][1];
1119
      let filterParam = this.searchFieldsHelper.getFieldParam(filterId, this.entityType);
1120

    
1121
      if (URLparams[filterParam] != undefined) {
1122
        let values = (StringUtils.URIDecode(StringUtils.URIDecode(URLparams[filterParam]))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
1123
        var countvalues = 0;
1124
        var fq = "";
1125
        var fqFrom = "";
1126
        var fqTo = "";
1127
        let filterOp: string = this.searchFieldsHelper.getFieldOperator(filterId);
1128

    
1129
        for (let value of values) {
1130
          if (this.fieldIdsMap[filterId].filterType == "range") {
1131

    
1132
            let selectedFromValue;
1133
            let selectedToValue;
1134

    
1135
            let years: string[] = (value.substring(5)).split(":");
1136
            let yearFrom: string = (Dates.isValidYear(years[0]) ? years[0] : null);
1137
            //(Number.isInteger(parseInt(years[0], 10)) ? years[0] : null);
1138
            let yearTo: string = (Dates.isValidYear(years[1]) ? years[1] : null);
1139
            //console.log("getSearchAPIQueryForRangeFields: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
1140
            if(yearFrom) {
1141
              selectedFromValue = yearFrom;
1142
            }
1143
            if(yearTo) {
1144
              selectedToValue = yearTo;
1145
            }
1146
            if(yearFrom || yearTo) {
1147

    
1148
            // if (value.length <= 14) {
1149
            //   if(Dates.isValidYear(value.substring(5, 9))) {
1150
            //     selectedFromValue = value.substring(5, 9);
1151
            //   }
1152
            //   if(Dates.isValidYear(value.substring(10, 14))) {
1153
            //     selectedToValue = value.substring(10, 14);
1154
            //   }
1155

    
1156
              /*if(this.rangeFields[i][0] == this.rangeFields[i][1]) {
1157
                //console.log(selectedFromValue + " - "+selectedToValue);
1158
                if (selectedFromValue && selectedToValue) {
1159
                  let equalityOp = this.fieldIdsMap[filterId].equalityOperator;
1160
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOp + "\"" + selectedFromValue + " " + selectedToValue + "\"";
1161
                  fq = "&fq=" + StringUtils.URIEncode(fq);
1162
                } else if (selectedFromValue) {
1163
                  let equalityOp = this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator;
1164
                  if(equalityOp == " = ") {
1165
                    equalityOp = " >= ";
1166
                  }
1167
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOp + "\"" + selectedFromValue + "\"";
1168
                  fq = "&fq=" + StringUtils.URIEncode(fq);
1169
                } else if (selectedToValue) {
1170
                  let equalityOp = this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator;
1171
                  if(equalityOp == " = ") {
1172
                    equalityOp = " <= ";
1173
                  }
1174
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOp + "\"" + selectedToValue + "\"";
1175
                  fq = "&fq=" + StringUtils.URIEncode(fq);
1176
                }
1177
              } else {
1178
                let equalityOpFrom = this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator;
1179
                let equalityOpTo = this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator;
1180

    
1181
                if (selectedFromValue) {
1182
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOpFrom + "\"" + selectedFromValue + "\"";
1183
                  // fq = "&fq=" + StringUtils.URIEncode(fq);
1184
                }
1185
                if (selectedToValue) {
1186
                  fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][1] + equalityOpTo + "\"" + selectedToValue + "\"";
1187
                  // fq = "&fq=" + StringUtils.URIEncode(fq);
1188
                }
1189
                if(selectedFromValue || selectedToValue) {
1190
                  fq = "&fq=" + StringUtils.URIEncode(fq);
1191
                }
1192
              }*/
1193
              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 );
1194
            }
1195
          }
1196
        }
1197
        allFqs += fq +fqFrom + fqTo;
1198
      }
1199
    }
1200

    
1201
    return allFqs;
1202

    
1203
  }
1204
  // createRangeFilterQuery(this.rangeFields[i], selectedFromValue, selectedToValue, this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator, this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator; filterOp )
1205
public static createRangeFilterQuery(rangeField,selectedFromValue, selectedToValue, equalityOp, equalityOpFrom, equalityOpTo, filterOp ){
1206
    let fq="";
1207
  if(rangeField[0] == rangeField[1]) {
1208
    //console.log(selectedFromValue + " - "+selectedToValue);
1209
    if (selectedFromValue && selectedToValue) {
1210
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOp + "\"" + selectedFromValue + " " + selectedToValue + "\"";
1211
      fq = "&fq=" + StringUtils.URIEncode(fq);
1212
    } else if (selectedFromValue) {
1213
      if(equalityOpFrom == " = ") {
1214
        equalityOpFrom = " >= ";
1215
      }
1216
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOpFrom + "\"" + selectedFromValue + "\"";
1217
      fq = "&fq=" + StringUtils.URIEncode(fq);
1218
    } else if (selectedToValue) {
1219
      if(equalityOpTo == " = ") {
1220
        equalityOpTo = " <= ";
1221
      }
1222
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOpTo + "\"" + selectedToValue + "\"";
1223
      fq = "&fq=" + StringUtils.URIEncode(fq);
1224
    }
1225
  } else {
1226

    
1227
    if (selectedFromValue) {
1228
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOpFrom + "\"" + selectedFromValue + "\"";
1229
      // fq = "&fq=" + StringUtils.URIEncode(fq);
1230
    }
1231
    if (selectedToValue) {
1232
      fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[1] + equalityOpTo + "\"" + selectedToValue + "\"";
1233
      // fq = "&fq=" + StringUtils.URIEncode(fq);
1234
    }
1235
    if(selectedFromValue || selectedToValue) {
1236
      fq = "&fq=" + StringUtils.URIEncode(fq);
1237
    }
1238

    
1239
  }
1240
  return fq;
1241
}
1242
  /**
1243
   * Sets parameterNames and parameterValues arrays
1244
   * used in paging, advanced search link, Goto()
1245
   * @param filters either query filters or filters defined by the URL parameters
1246
   * @param rangeFilters defined by the URL parameters
1247
   * @param includePage
1248
   */
1249
  buildPageURLParameters(filters:Filter[], rangeFilters: RangeFilter[], includePage: boolean) {
1250
    this.parameterNames.splice(0, this.parameterNames.length);
1251
    this.parameterValues.splice(0, this.parameterValues.length);
1252
    for (var i = 0; i < this.selectedFields.length; i++) {
1253
      //default operator is and
1254
      this.parameterNames.push("f"+i);
1255
      this.parameterValues.push(this.selectedFields[i].id + (this.selectedFields[i].operatorId!='and'?(","+this.selectedFields[i].operatorId):''));
1256
      this.parameterNames.push("fv"+i);
1257
      if (this.selectedFields[i].type == "date") {
1258

    
1259
        if (this.selectedFields[i].dateValue.type == "range") {
1260
          this.parameterValues.push(StringUtils.URIEncode("range" + Dates.getDateToString(this.selectedFields[i].dateValue.from) + ":" + Dates.getDateToString(this.selectedFields[i].dateValue.to)));
1261
        } else {
1262
          this.parameterValues.push(StringUtils.URIEncode(this.selectedFields[i].dateValue.type));
1263
        }
1264

    
1265
      } else {
1266
        // console.log(this.selectedFields[i].value +" " + StringUtils.URIEncode(this.selectedFields[i].value))
1267
        this.parameterValues.push(StringUtils.URIEncode(this.selectedFields[i].value));
1268
      }
1269
    }
1270
    if (includePage) {
1271
      this.parameterNames.push("page");
1272
      this.parameterValues.push("" + this.searchUtils.page);
1273
    }
1274

    
1275
    //if (this.searchUtils.size != this.resultsPerPage) {
1276
    if (this.resultsPerPageChanged) {
1277
      this.parameterNames.push("size");
1278
      //this.parameterValues.push("" + this.searchUtils.size);
1279
      this.parameterValues.push("" + this.resultsPerPageChanged);
1280
    }
1281

    
1282
    //if (this.sort && this.searchUtils.sortBy) {
1283
    if (this.sort && this.sortByChanged) {
1284
      this.parameterNames.push("sortBy");
1285
      //this.parameterValues.push(this.searchUtils.sortBy);
1286
      this.parameterValues.push(this.sortedByChanged);
1287
    }
1288
    for (let filter of filters) {
1289
      var filterLimits = "";
1290
      if (filter.countSelectedValues > 0) {
1291
        for (let value of filter.values) {
1292
          if (value.selected == true) {
1293
            filterLimits += ((filterLimits.length == 0) ? '' : ',') + '"' + (value.id) + '"';
1294
          }
1295
        }
1296
        if (filterLimits.length > 0) {
1297
          this.parameterNames.push(filter.filterId);
1298
          this.parameterValues.push(filterLimits);
1299
        }
1300
      }
1301
    }
1302
    for (let filter of rangeFilters) {
1303
      var filterLimits = "";
1304
      let yearFrom: string = (Dates.isValidYear(filter.selectedFromValue) ? filter.selectedFromValue : null);
1305
      let yearTo: string = (Dates.isValidYear(filter.selectedToValue) ? filter.selectedToValue : null);
1306
      if(yearFrom || yearTo) {
1307
        this.parameterNames.push(filter.filterId);
1308
        this.parameterValues.push("range" + (yearFrom ? yearFrom : "") + ":" + (yearTo ? yearTo : ""));
1309
      }
1310
      // if (filter.countSelectedValues > 0) {
1311
      //   for (let value of filter.values) {
1312
      //     if (value.selected == true) {
1313
      //       filterLimits += ((filterLimits.length == 0) ? '' : ',') + '"' + (value.id) + '"';
1314
      //     }
1315
      //   }
1316
      //   if (filterLimits.length > 0) {
1317
      //     this.parameterNames.push(filter.filterId);
1318
      //     this.parameterValues.push(filterLimits);
1319
      //   }
1320
      // }
1321
    }
1322
    if (this.searchUtils.keyword.length > 0) {
1323
      this.parameterNames.push("keyword");
1324
      this.parameterValues.push(this.searchUtils.keyword);
1325
    }
1326

    
1327
    if (this.resultTypes && (this.entityType == 'publication' || this.entityType == 'dataset' || this.entityType == 'software' || this.entityType == 'other' || this.entityType == "result")) {
1328
      let values = [];
1329
      for(let value of this.resultTypes.values){
1330
        if(value.selected) {
1331
          values.push(value.id);
1332
        }
1333
      }
1334
      this.selectedTypesNum = 0;
1335
      if (values.length > 0 && values.length != 4) {
1336
        this.parameterNames.push("type");
1337
        this.parameterValues.push(values.join(","));
1338
        this.selectedTypesNum = values.length;
1339
      }
1340
      if(this.quickFilter) {
1341
        this.parameterNames.push("qf");
1342
        this.parameterValues.push("" + this.quickFilter.selected);
1343
      }
1344
    }
1345
    if(this.customFilterEnabled){
1346
      this.parameterNames.push("cf");
1347
      this.parameterValues.push("true");
1348
    }
1349
    // if (this.searchUtils.size != this.resultsPerPage) {
1350
    //   // allLimits += ((allLimits.length == 0) ? '?' : '&') + 'size=' + this.searchUtils.size;
1351
    //   this.parameterNames.push("size");
1352
    //   this.parameterValues.push("" + this.searchUtils.size);
1353
    // }
1354
    // if (this.sort && this.searchUtils.sortBy) {
1355
    //   // allLimits += ((allLimits.length == 0) ? '?' : '&') + 'sortBy=' + this.searchUtils.sortBy;
1356
    //   this.parameterNames.push("sortBy");
1357
    //   this.parameterValues.push(this.searchUtils.sortBy);
1358
    // }
1359
    // console.log(this.parameterNames)
1360
    // console.log(this.parameterValues)
1361
  }
1362

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

    
1381
          let v: Value = new Value();
1382
          v.name = RefineResultsUtils.keepPartAfterCharacters(StringUtils.unquote(value), "||");
1383
          v.name = (v.name.indexOf("::")!=-1)?v.name.substring(v.name.indexOf("::")+2).split("::").join("|"):v.name; // for funding streams
1384
          v.id = StringUtils.unquote(value);
1385
          v.selected = true;
1386
          filter.values.push(v);
1387
          // console.log(v)
1388
          filter.countSelectedValues++;
1389
        }
1390
        filters.push(filter)
1391
      }
1392
    }
1393

    
1394
    if (this.quickFilter) {
1395
      if (this.entityType == "result" && (URLparams[this.quickFilter.filterId] == undefined) && (URLparams["qf"] == undefined || URLparams["qf"] == "true")) {
1396
        let filter = new Filter();
1397
        filter.title = fields.getFieldName(this.quickFilter.filterId, this.entityType);
1398
        filter.filterId = this.quickFilter.filterId;
1399
        filter.originalFilterId = this.quickFilter.filterId;
1400
        filter.values = [];
1401
        let v: Value = new Value();
1402
        v.name = this.quickFilter.value;
1403
        v.id = this.quickFilter.value;
1404
        v.selected = true;
1405
        filter.values.push(v);
1406
        filter.countSelectedValues = 1;
1407
        filters.push(filter)
1408
      }
1409
    }
1410
    if ((this.entityType == 'publication' || this.entityType == 'dataset' || this.entityType == 'software' || this.entityType == 'other' || this.entityType == "result")) {
1411
      this.resultTypes = {values:[],filterId:"type", countSelectedValues: 0, filterType: 'checkbox', originalFilterId: "", valueIsExact: true, title: "Result Types",filterOperator:"or"};
1412
      if (URLparams["type"]) {
1413
        let types = URLparams["type"];
1414
        types = Array.isArray(types) ? types.join(',').split(","):types.split(",");
1415
        for(let type of types){
1416
          if(["publications", "datasets","software", "other"].indexOf(StringUtils.unquote(type))!=-1 && this.resultTypeOptions[StringUtils.unquote(type)]){
1417
            this.resultTypes.values.push({name: this.resultTypeOptions[StringUtils.unquote(type)].name , id:StringUtils.unquote(type),selected:true, number:0});
1418
            this.resultTypes.countSelectedValues++;
1419
            }
1420
          }
1421

    
1422
      }
1423

    
1424
    }
1425

    
1426
    this.URLCreatedFilters = filters;
1427
  }
1428

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

    
1448

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

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

    
1495
  }
1496

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

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

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

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

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

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

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