Commit f0995d1e authored by Thibault Ehrhart's avatar Thibault Ehrhart

Rename genre filter into subject filter, add actual genres filter

parent 694c687a
......@@ -83,7 +83,7 @@ export class HomeComponent implements OnInit {
this.formGroupSearch.valueChanges.debounceTime(500).subscribe(form => {
console.debug('form=',form);
this.search.searchParams.date = form.date;
this.search.searchParams.genres = form.selectedSubjectCodes;
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;
......
......@@ -12,6 +12,7 @@ const { Client } = require('virtuoso-sparql-client');
export interface NewsContext {
id?: string;
subjects?: Array<string> | string;
genres?: Array<string> | string;
date?: string;
location?: string;
......@@ -73,9 +74,9 @@ export class NewsService {
SELECT DISTINCT ?sc ?prefLabel
WHERE {
{
SELECT DISTINCT ?genre WHERE {
SELECT DISTINCT ?subject WHERE {
GRAPH <http://asrael.eurecom.fr/agencefrancepresse/news> { ?s a rnews:NewsItem . }
?s dc:subject ?genre .
?s dc:subject ?subject .
}
}
{
......@@ -83,7 +84,7 @@ export class NewsService {
?sc skos:inScheme <http://cv.iptc.org/newscodes/subjectcode/> .
?sc skos:prefLabel ?prefLabel .
FILTER (LANG(?prefLabel) = "" || LANG(?prefLabel) = "en-gb")
FILTER (?sc = ?genre)
FILTER (?sc = ?subject)
}
}
ORDER BY ASC(?prefLabel)
......@@ -108,7 +109,7 @@ export class NewsService {
// Generate query
let query = `
${this.getPrefixes()}
SELECT DISTINCT ?s ?dateCreated ?dateModified ?datePublished ?description ?genre ?headline ?identifier ?language ?slug ?country ?locality (GROUP_CONCAT(DISTINCT ?annotations; separator="|") AS ?annotations)
SELECT DISTINCT ?s ?dateCreated ?dateModified ?datePublished ?description ?genre ?subject ?headline ?identifier ?language ?slug ?country ?locality (GROUP_CONCAT(DISTINCT ?annotations; separator="|") AS ?annotations)
WHERE {
GRAPH <http://asrael.eurecom.fr/agencefrancepresse/news> { ?s a rnews:NewsItem . }
VALUES ?s { <${uri}> }
......@@ -118,7 +119,8 @@ export class NewsService {
OPTIONAL {
?s rnews:description ?description .
}
OPTIONAL { ?s dc:subject ?genre . }
OPTIONAL { ?s rnews:genre ?genre . }
OPTIONAL { ?s dc:subject ?subject . }
OPTIONAL { ?s rnews:headline ?headline . }
OPTIONAL { ?s rnews:identifier ?identifier . }
OPTIONAL { ?s rnews:inLanguage ?language . }
......@@ -196,13 +198,22 @@ export class NewsService {
let client = new Client(environment.virtuosoAddress);
client.setOptions('application/json');
// Subjects filter
let subjectsFilter = '';
if (typeof context.subjects === 'string') {
context.subjects = [context.subjects];
}
if (Array.isArray(context.subjects) && context.subjects.length > 0) {
subjectsFilter = 'VALUES ?subject { ' + context.subjects.map(uri => '<' + uri + '>').join(' ') + ' }';
}
// Genres filter
let genresFilter = '';
if (typeof context.genres === 'string') {
context.genres = [context.genres];
}
if (Array.isArray(context.genres) && context.genres.length > 0) {
genresFilter = 'VALUES ?genre { ' + context.genres.map(uri => '<' + uri + '>').join(' ') + ' }';
genresFilter = 'FILTER (?genre NOT IN(' + context.genres.map(uri => '<' + uri + '>').join(',') + '))';
}
// Date filter
......@@ -245,7 +256,7 @@ export class NewsService {
// Generate query
let query = `
${this.getPrefixes()}
SELECT DISTINCT ?s ?dateCreated ?dateModified ?datePublished ?description ?genre ?headline ?identifier ?language ?slug ?country ?locality
SELECT DISTINCT ?s ?dateCreated ?dateModified ?datePublished ?description ?genre ?subject ?headline ?identifier ?language ?slug ?country ?locality
WHERE {
GRAPH <http://asrael.eurecom.fr/agencefrancepresse/news> { ?s a rnews:NewsItem . }
OPTIONAL { ?s rnews:dateCreated ?dateCreated . }
......@@ -256,7 +267,8 @@ export class NewsService {
${keywordsFilter}
FILTER (LANG(?description) = "" || LANG(?description = "en"))
}
OPTIONAL { ?s dc:subject ?genre . }
OPTIONAL { ?s rnews:genre ?genre . }
OPTIONAL { ?s dc:subject ?subject . }
OPTIONAL { ?s rnews:headline ?headline . }
OPTIONAL { ?s rnews:identifier ?identifier . }
OPTIONAL { ?s rnews:inLanguage ?language . }
......@@ -269,6 +281,8 @@ export class NewsService {
OPTIONAL { ?address schema:addressLocality ?locality }
}
}
FILTER (BOUND(?headline) || STRLEN(?headline) > 0)
${subjectsFilter}
${genresFilter}
${dateFilter}
${locationFilter}
......
......@@ -10,7 +10,13 @@ import { NewsService, NewsContext } from '../../services/news/news.service';
@Injectable()
export class SearchService {
searchParams: NewsContext = { annotations: [] };
searchParams: NewsContext = {
annotations: [],
genres: [
'http://cv.iptc.org/newscodes/genre/Program',
'http://cv.iptc.org/newscodes/genre/Advisory'
]
};
constructor() {
}
......
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