<commit_before>import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/forkJoin';
import 'rxjs/add/operator/catch';
import { NgbDateParserFormatter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
import { Search, SearchArray } from '../models/search';

@Injectable()
export class DocumentService {
  apiPathMEM: string;
  apiPathEPIC: string;
  searchResult: SearchArray;

  constructor(private http: Http) {
    const { hostname } = window.location;
    if (hostname === 'localhost') {
      // Local
      this.apiPathMEM  = 'http://localhost:3000';
      this.apiPathEPIC = 'http://localhost:4000';
    } else if (hostname === 'mem-mmt-dev.pathfinder.gov.bc.ca') {
      // Dev
      this.apiPathMEM  = 'http://mem-mmt-dev.pathfinder.gov.bc.ca';
      this.apiPathEPIC = 'http://esm-master.pathfinder.gov.bc.ca';
    } else if (hostname === 'mem-mmt-test.pathfinder.gov.bc.ca') {
      // Test
      this.apiPathMEM  = 'http://mem-mmt-test.pathfinder.gov.bc.ca';
      this.apiPathEPIC = 'http://esm-test.pathfinder.gov.bc.ca';
    } else {
      // Prod
      this.apiPathMEM  = 'https://mines.empr.gov.bc.ca';
      this.apiPathEPIC = 'https://projects.eao.gov.bc.ca';
    }
  }
  get(keywords: string,
      project: string,
      owneroperator: string,
      datestart: NgbDateStruct,
      dateend: NgbDateStruct) {
    this.searchResult = new SearchArray();

    let query = '/search?types=document';
    if (keywords) {
        query += '&search=' + keywords;
    }
    if (project) {
        query += '&project=' + project;
    }
    if (owneroperator) {
        query += '&owneroperator=' + owneroperator;
    }
    if (datestart) {
        const d: Date = new Date(datestart.year, datestart.month - 1, datestart.day);
        console.log('datestart', d.toString());
        query += '&datestart=' + d.toString();
    }
    if (dateend) {
        const d: Date = new Date(dateend.year, dateend.month - 1, dateend.day);
        console.log('dateend', d.toString());
        query += '&dateend=' + d.toString();
    }

    // Field selection
    query += '&fields=_id project displayName description datePosted documentCategories collections keywords inspectionReport';

    const mem = this.http.get(`${this.apiPathMEM}/api${query}`)
    .map((res: Response) => {
        const data = res.text() ? res.json() : [];
        data.forEach(i => {
            i.hostname = this.apiPathMEM;
        });
        return data;
    });
    const epic = this.http.get(`${this.apiPathEPIC}/api/v2${query}`)
    .map((res: Response) => {
        const data = res.text() ? res.json() : [];
        data.forEach(i => {
            i.hostname = this.apiPathEPIC;
        });
        return data;
    });

    return Observable.forkJoin([mem, epic]);
  }

  private handleError(error: any) {
    const reason = (error.message) ? error.message : (error.status ? `${error.status} - ${error.statusText}` : 'Server error');
    console.log(reason);
    return Observable.throw(reason);
  }
}
<commit_msg>NOBUG: Update hostnames.<commit_after>import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/forkJoin';
import 'rxjs/add/operator/catch';
import { NgbDateParserFormatter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
import { Search, SearchArray } from '../models/search';

@Injectable()
export class DocumentService {
  apiPathMEM: string;
  apiPathEPIC: string;
  searchResult: SearchArray;

  constructor(private http: Http) {
    const { hostname } = window.location;
    if (hostname === 'localhost') {
      // Local
      this.apiPathMEM  = 'http://localhost:3000';
      this.apiPathEPIC = 'http://localhost:4000';
    } else if (hostname === 'www.mem-mmt-dev.pathfinder.gov.bc.ca') {
      // Dev
      this.apiPathMEM  = 'http://mem-mmt-dev.pathfinder.gov.bc.ca';
      this.apiPathEPIC = 'http://esm-master.pathfinder.gov.bc.ca';
    } else if (hostname === 'www.mem-mmt-test.pathfinder.gov.bc.ca') {
      // Test
      this.apiPathMEM  = 'http://mem-mmt-test.pathfinder.gov.bc.ca';
      this.apiPathEPIC = 'http://esm-test.pathfinder.gov.bc.ca';
    } else {
      // Prod
      this.apiPathMEM  = 'https://mines.empr.gov.bc.ca';
      this.apiPathEPIC = 'https://projects.eao.gov.bc.ca';
    }
  }
  get(keywords: string,
      project: string,
      owneroperator: string,
      datestart: NgbDateStruct,
      dateend: NgbDateStruct) {
    this.searchResult = new SearchArray();

    let query = '/search?types=document';
    if (keywords) {
        query += '&search=' + keywords;
    }
    if (project) {
        query += '&project=' + project;
    }
    if (owneroperator) {
        query += '&owneroperator=' + owneroperator;
    }
    if (datestart) {
        const d: Date = new Date(datestart.year, datestart.month - 1, datestart.day);
        console.log('datestart', d.toString());
        query += '&datestart=' + d.toString();
    }
    if (dateend) {
        const d: Date = new Date(dateend.year, dateend.month - 1, dateend.day);
        console.log('dateend', d.toString());
        query += '&dateend=' + d.toString();
    }

    // Field selection
    query += '&fields=_id project displayName description datePosted documentCategories collections keywords inspectionReport';

    const mem = this.http.get(`${this.apiPathMEM}/api${query}`)
    .map((res: Response) => {
        const data = res.text() ? res.json() : [];
        data.forEach(i => {
            i.hostname = this.apiPathMEM;
        });
        return data;
    });
    const epic = this.http.get(`${this.apiPathEPIC}/api/v2${query}`)
    .map((res: Response) => {
        const data = res.text() ? res.json() : [];
        data.forEach(i => {
            i.hostname = this.apiPathEPIC;
        });
        return data;
    });

    return Observable.forkJoin([mem, epic]);
  }

  private handleError(error: any) {
    const reason = (error.message) ? error.message : (error.status ? `${error.status} - ${error.statusText}` : 'Server error');
    console.log(reason);
    return Observable.throw(reason);
  }
}

{'fraction_non_alphanumeric': 0.16542308302905223, 'fraction_numerical': 0.00349261787585331, 'mean_word_length': 2.714622641509434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5269535', 'n_tokens_mistral': 2066, 'n_tokens_neox': 2043, 'n_words': 394}