Skip to content
Snippets Groups Projects
Commit 426e883e authored by Esko Ikkala's avatar Esko Ikkala
Browse files

Add tentative filter to facet and result queries

parent e6ebe4f8
No related branches found
No related tags found
No related merge requests found
......@@ -149,9 +149,9 @@ export const fetchFacet = (property) => ({
type: FETCH_FACET,
property
});
export const updateFacet = ({ values }) => ({
export const updateFacet = ({ facetValues }) => ({
type: UPDATE_FACET,
values
facetValues
});
export const clearFacet = () => ({
type: CLEAR_FACET,
......
......@@ -51,6 +51,7 @@ class FacetDialog extends React.Component {
render() {
const { classes, propertyLabel, facet } = this.props;
console.log(facet)
return (
<div className={classes.root}>
<IconButton
......@@ -69,7 +70,7 @@ class FacetDialog extends React.Component {
<Typography variant="h6">{propertyLabel}</Typography>
</DialogTitle>
<DialogContent>
{this.state.isLoading ? <CircularProgress style={{ color: purple[500] }} thickness={5} /> : <Tree data={facet.values} /> }
{this.state.isLoading ? <CircularProgress style={{ color: purple[500] }} thickness={5} /> : <Tree data={facet.facetValues.creationPlace} /> }
</DialogContent>
</Dialog>
</div>
......
......@@ -51,7 +51,7 @@ const getFacet = action$ => action$.pipe(
const searchUrl = hiplaApiUrl + 'facet';
const requestUrl = `${searchUrl}?property=${action.property}`;
return ajax.getJSON(requestUrl).pipe(
map(response => updateFacet({ values: response }))
map(response => updateFacet({ facetValues: response }))
);
})
);
......
import {
FETCH_FACET,
UPDATE_FACET,
CLEAR_FACET
} from '../actions';
export const INITIAL_STATE = {
values : [],
facetOptions : {
creationPlace: {
hierarchical: true,
},
author: {
hierarchical: false,
}
},
facetValues : {
creationPlace: [],
author: []
},
fetchingFacet : false
};
......@@ -16,17 +26,12 @@ const facet = (state = INITIAL_STATE, action) => {
case UPDATE_FACET:
return {
...state,
values: action.values,
fetchingFacet: false
};
case CLEAR_FACET:
return {
...state,
values: [],
facetValues: action.facetValues,
fetchingFacet: false
};
default:
return state;
}
};
export default facet;
......@@ -6,7 +6,6 @@ import {
CLEAR_SUGGESTIONS,
FETCH_RESULTS,
UPDATE_RESULTS,
CLEAR_RESULTS,
FETCH_MANUSCRIPTS,
FETCH_PLACES,
UPDATE_MANUSCRIPTS,
......
import express from 'express';
import bodyParser from 'body-parser';
import request from 'superagent';
import _ from 'lodash';
import { getManuscripts, getManuscriptCount, getPlaces, getFacet } from './sparql/Manuscripts';
const DEFAULT_PORT = 3001;
const app = express();
......@@ -19,10 +18,22 @@ app.use(function(req, res, next) {
app.use(express.static(__dirname + './../public/'));
const filterObj = {
creationPlace: {
predicate: '^<http://erlangen-crm.org/efrbroo/R18_created>/<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>',
values: ['<http://ldf.fi/mmm/place/7>', '<http://ldf.fi/mmm/place/5>']
},
author: {
predicate: '^<http://erlangen-crm.org/efrbroo/R18_created>/<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>',
values: ['<http://ldf.fi/mmm/person/84>', '<http://ldf.fi/mmm/person/894>']
}
};
//const filterObj = {}
app.get('/manuscripts', (req, res) => {
const page = req.query.page || 1;
return getManuscripts(page).then((data) => {
return getManuscripts(page, filterObj).then((data) => {
// console.log(data);
res.json(data);
})
......@@ -33,7 +44,7 @@ app.get('/manuscripts', (req, res) => {
});
app.get('/manuscript-count', (req, res) => {
return getManuscriptCount().then((data) => {
return getManuscriptCount(filterObj).then((data) => {
// console.log(data);
res.json(data);
})
......@@ -57,8 +68,12 @@ app.get('/places', (req, res) => {
app.get('/facet', (req, res) => {
const property = req.query.property;
return getFacet(property).then((data) => {
const facetValues = {
creationPlace: data,
author: []
};
//console.log(data);
res.json(data);
res.json(facetValues);
})
.catch((err) => {
console.log(err);
......
......@@ -30,6 +30,7 @@ module.exports = {
PREFIX sdbm: <https://sdbm.library.upenn.edu/>
SELECT (COUNT(DISTINCT ?id) as ?count)
WHERE {
<FILTER>
?id a frbroo:F4_Manifestation_Singleton .
}
`,
......@@ -49,6 +50,7 @@ module.exports = {
WHERE {
{
SELECT DISTINCT ?id {
<FILTER>
?id a frbroo:F4_Manifestation_Singleton .
}
<PAGE>
......
......@@ -8,16 +8,18 @@ import { makeObjectList } from './SparqlObjectMapper';
const sparqlSearchEngine = new SparqlSearchEngine();
export const getManuscripts = (page) => {
export const getManuscripts = (page, filterObj) => {
let { endpoint, manuscriptQuery } = datasetConfig['mmm'];
const pageSize = 5;
manuscriptQuery = manuscriptQuery.replace('<FILTER>', generateFilter(filterObj));
manuscriptQuery = manuscriptQuery.replace('<PAGE>', `ORDER BY ?id LIMIT ${pageSize} OFFSET ${page * pageSize}`);
//console.log(manuscriptQuery)
console.log(manuscriptQuery)
return sparqlSearchEngine.doSearch(manuscriptQuery, endpoint, makeObjectList);
};
export const getManuscriptCount = () => {
const { endpoint, countQuery } = datasetConfig['mmm'];
export const getManuscriptCount = (filterObj) => {
let { endpoint, countQuery } = datasetConfig['mmm'];
countQuery = countQuery.replace('<FILTER>', generateFilter(filterObj));
return sparqlSearchEngine.doSearch(countQuery, endpoint, mapCount);
};
......@@ -28,9 +30,21 @@ export const getPlaces = () => {
export const getFacet = (property) => {
const { endpoint } = datasetConfig['mmm'];
console.log(facetQuery)
return sparqlSearchEngine.doSearch(facetQuery, endpoint, mapFacet);
};
const generateFilter = (filterObj) => {
let filterStr = '';
for (let property in filterObj) {
filterStr += `
?id ${filterObj[property].predicate} ?${property}Filter
VALUES ?${property}Filter { ${filterObj[property].values.join(' ')} }
`;
}
return filterStr;
};
const facetQuery = `
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment