<commit_before>import {Injectable} from '@angular/core';
import {Subject} from "rxjs/Rx";
import {Http, URLSearchParams} from "@angular/http";

@Injectable()
export class DrupalService {
  private rootUrl = "https://localhost:3027/";
  private thisUrl = "https://researchit.cer.auckland.ac.nz/api/content";

  constructor(private http:Http) {
  }

 search(category:string, searchChange:Subject<any>, debounceDuration = 400) {
    return searchChange
      .debounceTime(debounceDuration)
      .distinctUntilChanged()
      .switchMap(value => this.rawSearch(category, value.searchTerm, value.subcategories));
  }
      
 contentsearch(category:string, searchChange:Subject<any>, debounceDuration = 400) {
    return searchChange
      .debounceTime(debounceDuration)
      .distinctUntilChanged()
      .switchMap(value => this.rawContentSearch(category, value.searchTerm, value.subcategories));
  }
     
  contentdetailsearch(category:string, searchChange:Subject<any>, debounceDuration = 400) {
      return searchChange
      .debounceTime(debounceDuration)
      .distinctUntilChanged()
      .switchMap(value => this.rawdetailSearch(category, value.searchTerm, value.subcategories));
  }

  rawSearch(category:string, term:string, subcategories:any[]) {
    var search = new URLSearchParams();

    if (term != undefined && term.trim() != "") {
      search.set('q', term);
    }
    else if (subcategories != undefined) {
      for (let subcat of subcategories) {
        if (subcat.value != "" && subcat.value != undefined)
          search.set(subcat.key, subcat.value);
      }
    }

     return this.http
      .get(this.rootUrl + category, {search})
      .map((response) => response.json());
  }
  
  rawContentSearch(category:string, term:string, subcategories:any[]) {
    var search = new URLSearchParams();

    if (term != undefined && term.trim() != "") {
      search.set('q', term);
    }
    else if (subcategories != undefined) {
      for (let subcat of subcategories) {
        if (subcat.value != "" && subcat.value != undefined)
          search.set(subcat.key, subcat.value);
      }
    }


       return this.http
      .get(this.thisUrl + "?type=" + category, {search})
      .map((response) => response.json());
      
   
  }
  
 rawdetailSearch(category:string, term:string, subcategories:any[]) {
    var search = new URLSearchParams();

    if (term != undefined && term.trim() != "") {
      search.set('q', term);
    }
    else if (subcategories != undefined) {
      for (let subcat of subcategories) {
        if (subcat.value != "" && subcat.value != undefined)
          search.set(subcat.key, subcat.value);
      }
    }


       return this.http
      .get(this.thisUrl + "/" + category, {search})<commit_msg>add headers<commit_after>import {Injectable} from '@angular/core';
import {Subject} from "rxjs/Rx";
import {Http, URLSearchParams, Headers} from "@angular/http";

@Injectable()
export class DrupalService {
  private rootUrl = "https://localhost:3027/";
  private thisUrl = "https://researchit.cer.auckland.ac.nz/api/content";
  private config;
  
  constructor(private http:Http) {
  //let headers = new Headers();
    //headers.set('Accept', 'application/json');
   // headers.append('Content-Type', 'application/json');
  //  this.http.defaults.headers.common['Accept']= 'application/json, text/plain';
  }

 search(category:string, searchChange:Subject<any>, debounceDuration = 400) {
    return searchChange
      .debounceTime(debounceDuration)
      .distinctUntilChanged()
      .switchMap(value => this.rawSearch(category, value.searchTerm, value.subcategories));
  }
      
 contentsearch(category:string, searchChange:Subject<any>, debounceDuration = 400) {
    return searchChange
      .debounceTime(debounceDuration)
      .distinctUntilChanged()
      .switchMap(value => this.rawContentSearch(category, value.searchTerm, value.subcategories));
  }
     
  contentdetailsearch(category:string, searchChange:Subject<any>, debounceDuration = 400) {
      return searchChange
      .debounceTime(debounceDuration)
      .distinctUntilChanged()
      .switchMap(value => this.rawdetailSearch(category, value.searchTerm, value.subcategories));
  }

  rawSearch(category:string, term:string, subcategories:any[]) {
    var dosearch = new URLSearchParams();
      console.log(dosearch);
    if (term != undefined && term.trim() != "") {
      dosearch.set('search_string', term);
    }
    else if (subcategories != undefined) {
      for (let subcat of subcategories) {
        if (subcat.value != "" && subcat.value != undefined)
          dosearch.set(subcat.key, subcat.value);
      }
    }
    let doheaders = new Headers();
    doheaders.set('Accept', 'application/json');
      return this.http
      .get(this.thisUrl + "/" + category, {search:dosearch, headers:doheaders})
      .map((response) => response.json());
  }
  
  rawContentSearch(category:string, term:string, subcategories:any[]) {
     var dosearch = new URLSearchParams();
      console.log(dosearch);
    if (term != undefined && term.trim() != "") {
      dosearch.set('search_string', term);
    }
    else if (subcategories != undefined) {
      for (let subcat of subcategories) {
        if (subcat.value != "" && subcat.value != undefined)
          dosearch.set(subcat.key, subcat.value);
      }
    }

    let doheaders = new Headers();
    doheaders.set('Accept', 'application/json');
      return this.http
      .get(this.thisUrl + "?type=" + category, {search:dosearch, headers:doheaders})
      .map((response) => response.json());
   
  }
  
 rawdetailSearch(category:string, term:string, subcategories:any[]) {
    var dosearch = new URLSearchParams();
      console.log(dosearch);
    if (term != undefined && term.trim() != "") {
      dosearch.set('search_string', term);
    }
    else if (subcategories != undefined) {
      for (let subcat of subcategories) {
        if (subcat.value != "" && subcat.value != undefined)
          dosearch.set(subcat.key, subcat.value);
      }
    }

      let doheaders = new Headers();
    doheaders.set('Accept', 'application/json');
      return this.http
      .get(this.thisUrl + "/" + category, {search:dosearch, headers:doheaders})
{'fraction_non_alphanumeric': 0.14704939063502245, 'fraction_numerical': 0.004169339320076972, 'mean_word_length': 3.3013793103448275, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, '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': '1980790', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1842, 'n_words': 368}