Commit 0fadc3b8 authored by Thibault Ehrhart's avatar Thibault Ehrhart

Add additional filters (images, languages)

parent 4e6e3243
......@@ -81,6 +81,26 @@
[typeahead]="annotation.typeahead">
</ng-select>
</div>
<div>Additional filters</div>
<hr><br>
<div class="form-group">
<input id="inputHasMedias" type="checkbox" formControlName="hasMedias">
<label for="inputHasMedias">Must have an image</label>
</div>
<div class="form-group">
<label for="inputLanguage">Language</label>
<ng-select [items]="languages"
class="form-control"
bindLabel="label"
bindValue="id"
placeholder="Select a language"
clearAllText="Clear"
formControlName="language">
</ng-select>
</div>
</form>
</div>
<div class="column sidebar-search-results padding-top" *ngIf="!isFullscreen">
......
......@@ -32,6 +32,7 @@ export class HomeComponent implements OnInit {
locations: NgOption[] = [];
schemas: NgOption[] = [];
selectedSchema: any = null;
languages: NgOption[] = [];
annotations: any = [{
id: 'http://adel.eurecom.fr/Stanford/Location',
label: 'Location',
......@@ -98,7 +99,9 @@ export class HomeComponent implements OnInit {
date: new FormControl(),
who: new FormControl(),
keywords: new FormControl(),
schema: new FormControl()
schema: new FormControl(),
language: new FormControl(),
hasMedias: new FormControl()
});
this.formGroupSearch.valueChanges.debounceTime(500).subscribe(form => {
......@@ -107,6 +110,8 @@ export class HomeComponent implements OnInit {
this.search.searchParams.subjects = form.selectedSubjectCodes;
this.search.searchParams.location = form.location ? form.location.trim() : null;
this.search.searchParams.keywords = form.keywords ? form.keywords.trim() : null;
this.search.searchParams.hasMedias = form.hasMedias;
this.search.searchParams.language = form.language;
this.search.searchParams.schemaProperties = [];
// Schema properties
......@@ -229,6 +234,14 @@ export class HomeComponent implements OnInit {
annotation.options.length = 0;
this.formGroupSearch.addControl('annotation_' + annotation.id, new FormControl(''));
});
// Load languages
this.languages.length = 0;
this.newsService.getLanguages().subscribe((data: any) => {
this.languages = data.results.bindings.map((b: any) => {
return { id: b.lang.value, label: b.lang.value };
});
});
}
ngOnDestroy() {
......
......@@ -20,6 +20,8 @@ export interface NewsContext {
annotations?: Array<any>;
schema?: string;
schemaProperties?: Array<any>;
language?: string;
hasMedias?: boolean;
}
@Injectable()
......@@ -96,6 +98,20 @@ export class NewsService {
`));
}
getLanguages(): Observable<any> {
let client = new Client(environment.virtuosoAddress);
client.setOptions('application/json');
return Observable.fromPromise(client.query(`
${this.getPrefixes()}
SELECT DISTINCT ?lang
WHERE {
GRAPH <http://asrael.eurecom.fr/agencefrancepresse/news> { ?s a rnews:NewsItem . }
?s rnews:inLanguage ?lang .
}
GROUP BY ?lang
`));
}
getPrefixes() {
return `
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
......@@ -268,6 +284,9 @@ export class NewsService {
})
}
// Language filter
const languageFilter = context.language ? '?s rnews:inLanguage ' + JSON.stringify(context.language) + ' .': '';
// Annotations filter
let annotationsFilter = '';
console.log('context=',context);
......@@ -292,6 +311,9 @@ export class NewsService {
}
}
// Has medias
const hasMediasFilter = context.hasMedias ? 'FILTER EXISTS { ?s rnews:associatedMedia ?associatedMedia }' : '';
// Offset/limit
let offset = 0;
let limit = 100;
......@@ -315,7 +337,9 @@ export class NewsService {
${dateFilter}
${locationFilter}
${schemaFilter}
${languageFilter}
${annotationsFilter}
${hasMediasFilter}
}
ORDER BY DESC(?dateCreated)
OFFSET ${offset}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment