search.component.ts 2.18 KB
Newer Older
Paulo's avatar
Paulo committed
1
import { Component,Input,  OnInit} from '@angular/core';
2
import { ParseXmlService } from '../services/parse-xml.service';
Paulo's avatar
Paulo committed
3
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
Paulo's avatar
Paulo committed
4
5
import { SearchResult } from './models/search-result.model';

Administrator's avatar
Administrator committed
6
7
8
9
10
11
12
13
14
15
16


@Component({
  selector: 'app-search',
  templateUrl: './search.component.html',
  styleUrls: ['./search.component.scss']
})


export class SearchComponent implements OnInit {

Paulo's avatar
Paulo committed
17
  results: string[][] = [];
Administrator's avatar
Administrator committed
18

Paulo's avatar
Paulo committed
19
  //seachForm: FormGroup;
Paulo's avatar
Paulo committed
20
  submitted = false;
21

Paulo's avatar
Paulo committed
22
23
24
  searchForm = new FormGroup({
    searchTerm: new FormControl()
  });
Paulo's avatar
Paulo committed
25
26


Paulo's avatar
Paulo committed
27
  constructor(private parserService: ParseXmlService, private formBuild: FormBuilder) { }
Administrator's avatar
Administrator committed
28

Paulo's avatar
Paulo committed
29
  ngOnDestroy(): void {}
Paulo's avatar
Paulo committed
30

Paulo's avatar
Paulo committed
31
  ngOnInit(): void {}
Administrator's avatar
Administrator committed
32

Paulo's avatar
Paulo committed
33
  simpleSearch() {
Paulo's avatar
Paulo committed
34
    this.submitted = true;
Paulo's avatar
Paulo committed
35
    this.results = [];
Paulo's avatar
Paulo committed
36
37
38
    //effectuer une recherche plein text en SPARL sur la BDD Blazegraph
    //curl -X POST -H 'Accept: application/rdf+xml' -i 'http://10.6.10.9:8888/blazegraph/sparql' --data 'query=SELECT * where {?s a <http://www.w3.org/ns/dcat#Dataset> }'

Paulo's avatar
Paulo committed
39
    //if (searchData) {
Paulo's avatar
Paulo committed
40
      let query: string;
Paulo's avatar
Paulo committed
41
      let searchTerm = this.searchForm.get("searchTerm").value
Paulo's avatar
Paulo committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
      console.log("Log arrived : ", searchTerm)
      //query ='query=SELECT * where {?s a <http://www.w3.org/ns/dcat#Dataset> }'
      query = 'query=PREFIX dcat: <http://www.w3.org/ns/dcat#>\n\
            PREFIX dcterms: <http://purl.org/dc/terms/>\n\
            SELECT  ?title ?description ?uri \n\
            where {\n\
                  ?dataset a dcat:Dataset ;\n\
                  dcterms:title ?title ;\n\
                  dcterms:description ?description; \n\
                  dcat:keyword ?uri ; \n\
                  FILTER ( contains( ?description, "' + searchTerm + '") || contains( ?title, "' + searchTerm + '"))\n\.\n\
            }'

      this.parserService.getXmlResult(query).subscribe(
        data => {
Paulo's avatar
Paulo committed
57
58
59
60
61
          if (data){
            console.error("Data", data)
            data.results.bindings.forEach(element => {
              this.results.push(element);
            });
62
          }
Paulo's avatar
Paulo committed
63
          //console.warn('Data submited ', searchTerm, "Results : ", this.results);
Paulo's avatar
Paulo committed
64

Paulo's avatar
Paulo committed
65
66
67
68
      });
      
      
      this.searchForm.reset();
Paulo's avatar
Paulo committed
69
    }
Paulo's avatar
Paulo committed
70
  //}
Administrator's avatar
Administrator committed
71
72

}