Skip to content
Snippets Groups Projects
Commit 5ddd7985 authored by esikkala's avatar esikkala
Browse files

Full text search improvements

parent 8fa95ef6
No related branches found
No related tags found
No related merge requests found
......@@ -31,9 +31,9 @@ export const fetchResults = ({ resultClass, facetClass, sortBy, variant }) => ({
type: FETCH_RESULTS,
resultClass, facetClass, sortBy, variant
});
export const fetchResultsClientSide = ({ jenaIndex, query }) => ({
export const fetchResultsClientSide = ({ resultClass, jenaIndex, query }) => ({
type: FETCH_RESULTS_CLIENT_SIDE,
jenaIndex, query
resultClass, jenaIndex, query
});
export const fetchResultsFailed = (resultClass, error, message) => ({
type: FETCH_RESULTS_FAILED,
......@@ -43,9 +43,9 @@ export const updatePaginatedResults = ({ resultClass, data }) => ({
type: UPDATE_PAGINATED_RESULTS,
resultClass, data
});
export const updateResults = ({ resultClass, data }) => ({
export const updateResults = ({ resultClass, jenaIndex, data }) => ({
type: UPDATE_RESULTS,
resultClass, data
resultClass, jenaIndex, data
});
export const sortResults = (resultClass, sortBy) => ({
type: SORT_RESULTS,
......
......@@ -5,7 +5,6 @@ import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import ResultTableCell from './ResultTableCell';
import TableRow from '@material-ui/core/TableRow';
import Typography from '@material-ui/core/Typography';
import CircularProgress from '@material-ui/core/CircularProgress';
import purple from '@material-ui/core/colors/purple';
import querystring from 'querystring';
......@@ -139,7 +138,6 @@ class ResultTable extends React.Component {
if (fetching) {
return (
<div className={classes.progressContainer}>
<Typography className={classes.progressTitle} variant="h4" color='primary'>Fetching data</Typography>
<CircularProgress style={{ color: purple[500] }} thickness={5} />
</div>
);
......
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import MaterialTable from 'material-table';
import SearchIcon from '@material-ui/icons/Search';
import ClearIcon from '@material-ui/icons/Clear';
......@@ -7,57 +8,93 @@ import FirstPageIcon from '@material-ui/icons/FirstPage';
import LastPageIcon from '@material-ui/icons/LastPage';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
import CircularProgress from '@material-ui/core/CircularProgress';
import purple from '@material-ui/core/colors/purple';
import { has } from 'lodash';
const styles = () => ({
progressContainer: {
width: '100%',
height: 'calc(100% - 72px)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
},
});
class ResultTable2 extends React.Component {
render() {
console.log(this.props.data)
return (
<div style={{ maxWidth: '100%' }}>
<MaterialTable
columns={[
{
title: 'Label',
field: 'prefLabel',
render: rowData =>
<a
target='_blank' rel='noopener noreferrer'
href={rowData.id}
>
{rowData.prefLabel}
</a>
},
{ title: 'URI', field: 'id' },
{
title: 'Type',
field: 'type',
render: rowData =>
<a
target='_blank' rel='noopener noreferrer'
href={rowData.type.id}
>
{rowData.type.prefLabel}
</a>
},
{ title: 'Source', field: 'source' },
]}
data={this.props.data}
title="Search results"
icons={{
Search: SearchIcon,
ResetSearch: ClearIcon,
FirstPage: FirstPageIcon,
LastPage: LastPageIcon,
NextPage: ChevronRightIcon,
PreviousPage: ChevronLeftIcon
}}
/>
</div>
);
//console.log(this.props.data)
if (this.props.fetching) {
return (
<div className={this.props.classes.progressContainer}>
<CircularProgress style={{ color: purple[500] }} thickness={5} />
</div>
);
} else {
return (
<div style={{ maxWidth: '100%' }}>
<MaterialTable
columns={[
{
title: 'Label',
field: 'prefLabel',
render: rowData =>
<a
target='_blank' rel='noopener noreferrer'
href={rowData.id}
>
{rowData.prefLabel}
</a>
},
{
title: 'Type',
field: 'type',
render: rowData => rowData.type.prefLabel
},
{
title: 'Data provider link',
field: 'dataProviderUrl',
render: rowData => {
console.log(rowData)
if (has(rowData, 'source') && has(rowData, 'dataProviderUrl')) {
return(
<a
target='_blank' rel='noopener noreferrer'
href={rowData.dataProviderUrl}
>
{rowData.source.prefLabel}
</a>
);
}
}
},
]}
data={this.props.data}
title="Full text search results"
icons={{
Search: SearchIcon,
ResetSearch: ClearIcon,
FirstPage: FirstPageIcon,
LastPage: LastPageIcon,
NextPage: ChevronRightIcon,
PreviousPage: ChevronLeftIcon
}}
options={{
pageSize: 25,
pageSizeOptions: [10, 15, 20, 25]
}}
/>
</div>
);
}
}
}
ResultTable2.propTypes = {
classes: PropTypes.object.isRequired,
data: PropTypes.array,
fetching: PropTypes.bool.isRequired
};
export default ResultTable2;
export default withStyles(styles)(ResultTable2);
......@@ -66,6 +66,7 @@ class TopBarSearchField extends React.Component {
if (event.key === 'Enter' && this.hasValidQuery()) {
this.props.clearResults();
this.props.fetchResultsClientSide({
resultClass: 'all',
jenaIndex: 'text',
query: this.state.value
});
......@@ -77,6 +78,7 @@ class TopBarSearchField extends React.Component {
if (this.hasValidQuery()) {
this.props.clearResults();
this.props.fetchResultsClientSide({
resultClass: 'all',
jenaIndex: 'text',
query: this.state.value
});
......
......@@ -16,11 +16,11 @@ const All = props => {
value: 0,
icon: 'CalendarViewDay',
},
[`${perspectiveUrl}/map`]: {
label: 'map',
value: 1,
icon: 'AddLocation',
},
// [`${perspectiveUrl}/map`]: {
// label: 'map',
// value: 1,
// icon: 'AddLocation',
// },
}}
/>
<Route
......@@ -29,10 +29,19 @@ const All = props => {
/>
<Route
path={`${perspectiveUrl}/table`}
render={() =>
<ResultTable2
data={props.results}
/>
render={() => {
if (props.results.length > 0) {
return(
<ResultTable2
data={props.results}
fetching={props.textResultsFetching}
/>
);
} else {
return null;
}
}
}
/>
</React.Fragment>
......@@ -41,6 +50,8 @@ const All = props => {
All.propTypes = {
results: PropTypes.array,
textResultsFetching: PropTypes.bool.isRequired,
spatialResultsFetching: PropTypes.bool,
updatePage: PropTypes.func,
sortResults: PropTypes.func,
routeProps: PropTypes.object.isRequired,
......
......@@ -261,6 +261,7 @@ let SemanticPortal = (props) => {
<Paper className={classes.resultsContainerPaper}>
<All
results={props.clientSideFacetedSearch.results}
textResultsFetching={props.clientSideFacetedSearch.textResultsFetching}
routeProps={routeProps}
/>
</Paper>
......
......@@ -111,7 +111,11 @@ const fetchResultsClientSideEpic = (action$, state$) => action$.pipe(
requestUrl = `${searchUrl}?latMin=${latMin}&longMin=${longMin}&latMax=${latMax}&longMax=${longMax}`;
}
return ajax.getJSON(requestUrl).pipe(
map(response => updateResults({ resultClass: 'all', data: response })),
map(response => updateResults({
resultClass: 'all',
jenaIndex: action.jenaIndex,
data: response
})),
catchError(error => of({
type: FETCH_RESULTS_FAILED,
resultClass: 'all',
......
......@@ -10,19 +10,20 @@ export const countQuery = `
`;
export const jenaQuery = `
SELECT ?id ?prefLabel ?dataProviderUrl ?type__id ?type__prefLabel
SELECT ?id ?prefLabel ?dataProviderUrl ?source__id ?source__prefLabel ?type__id ?type__prefLabel
WHERE {
<QUERY>
?id skos:prefLabel ?prefLabel .
?id a ?type__id .
?type__id rdfs:label|skos:prefLabel ?type__prefLabel_ .
?type__id rdfs:label|skos:prefLabel ?type__prefLabel_ .
BIND(STR(?type__prefLabel_) AS ?type__prefLabel) # ignore language tags
OPTIONAL {
?id dct:source ?source__id .
?source__id skos:prefLabel ?source__prefLabel .
OPTIONAL { ?source__id skos:prefLabel ?source__prefLabel_ }
BIND(COALESCE(?source__prefLabel_, ?source__id) as ?source__prefLabel)
}
OPTIONAL {
?id mmm-schema:data_provider_url ?dataProviderUrl
?id mmm-schema:data_provider_url|owl:sameAs ?dataProviderUrl
}
}
`;
......
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