Skip to content

Commit

Permalink
Show dates (optional). Fix Test panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuess committed Jun 16, 2024
1 parent eb8c4c9 commit 32d4f26
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 154 deletions.
2 changes: 1 addition & 1 deletion src/components/Blocks/FacetedSearchBlockEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Edit = ({ data, onChangeBlock, block, selected }) => {
</Container>
</SidebarPortal>

<FacetedSearchBlockView />
<FacetedSearchBlockView data={data} />
</div>
);
};
Expand Down
2 changes: 0 additions & 2 deletions src/components/Blocks/FacetedSearchBlockView.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react';

import FacetedSearch from '../Views/FacetedSearch';

const View = ({ data }) => {
Expand Down
31 changes: 29 additions & 2 deletions src/components/Blocks/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ export const SearchBlockSchema = ({ data = {}, intl }) => {
'allowed_content_types',
'allowed_review_states',
'searchedFields',
'batchSize',
],
},
{
id: 'results',
title: 'Results',
fields: ['extrainfo_fields', 'subjectsFieldname'],
fields: [
'extrainfo_fields',
'subjectsFieldname',
'showNewsItemPublishedDate',
'showEventStartDate',
],
},
{
id: 'divers',
Expand Down Expand Up @@ -143,6 +149,11 @@ export const SearchBlockSchema = ({ data = {}, intl }) => {
creatable: true,
default: ['title^1.4', 'description^1.2', 'blocks_plaintext'],
},
batchSize: {
title: 'Batch size',
type: 'number',
default: 10,
},
facet_fields: {
title: 'Facets',
description: 'Fields to filter on.',
Expand All @@ -167,7 +178,23 @@ export const SearchBlockSchema = ({ data = {}, intl }) => {
title: 'Field name of tags field',
description:
'Show tags to search for. Let the field empty to not show tags.',
default: '',
default: 'subjects',
},
showNewsItemPublishedDate: {
title: 'Show published date of news items',
type: 'array',
widget: 'array',
items: {
vocabulary: { '@id': 'plone.app.vocabularies.UserFriendlyTypes' },
},
},
showEventStartDate: {
title: 'Show start date of events',
type: 'array',
widget: 'array',
items: {
vocabulary: { '@id': 'plone.app.vocabularies.UserFriendlyTypes' },
},
},
relocation: {
title: 'Relocation',
Expand Down
37 changes: 22 additions & 15 deletions src/components/Searchkit/CustomESRequestSerializer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class CustomESRequestSerializer {

// fields with boosting
let searchedFields = [...this.searchedFields];

let searchedFields_simple = searchedFields.map((fld) => {
const fieldname = fld.split('^')[0];
return fld.replace(fieldname, `${fieldname}.${this.language}`);
Expand Down Expand Up @@ -223,14 +223,19 @@ export class CustomESRequestSerializer {

bodyParams['highlight'] = {
number_of_fragments: 20,
fields: ['title', 'description', 'blocks_plaintext'].map(fieldname => {
return {
[fieldname]: {
matched_fields: [`${fieldname}.${this.language}`, `${fieldname}.${this.language}_exact`],
type: 'fvh',
},
}
})
fields: ['title', 'description', 'blocks_plaintext'].map(
(fieldname) => {
return {
[fieldname]: {
matched_fields: [
`${fieldname}.${this.language}`,
`${fieldname}.${this.language}_exact`,
],
type: 'fvh',
},
};
},
),
};
}

Expand Down Expand Up @@ -258,12 +263,14 @@ export class CustomESRequestSerializer {
// Generate terms of global filters
let terms = [];
// If isMultilingual, search only in language

this.language && volto_config.settings.isMultilingual && terms.push({
terms: {
language: [this.language],
},
});

this.language &&
volto_config.settings.isMultilingual &&
terms.push({
terms: {
language: [this.language],
},
});
this.allowed_content_types?.length > 0 &&
terms.push({
terms: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Searchkit/CustomESResponseSerializer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class CustomESResponseSerializer {
hit._source['highlight'] = hit.highlight;
return hit._source;
}) || [],
total: hits?.total.value < 11 ? hits.hits.length : hits?.total.value || 0,
total: hits?.total.value || 0,
};
return foo;
}
Expand Down
4 changes: 1 addition & 3 deletions src/components/Searchkit/ElasticSearchHighlights.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react';
import { useIntl } from 'react-intl';
import messages from '../../messages';

export const ElasticSearchHighlights = ({ highlight, indexResult }) => {
export const ElasticSearchHighlights = ({ highlight }) => {
const [toggleDetails, setToggleDetails] = React.useState(false);

const intl = useIntl();
Expand All @@ -32,7 +32,6 @@ export const ElasticSearchHighlights = ({ highlight, indexResult }) => {
onClick={showDetails}
role="button"
onKeyPress={showDetails}
tabIndex={indexResult}
>
{fragments.slice(0, 3).map((el, index) => {
return <div dangerouslySetInnerHTML={{ __html: el }} key={index} />;
Expand All @@ -44,7 +43,6 @@ export const ElasticSearchHighlights = ({ highlight, indexResult }) => {
onClick={showDetails}
role="button"
onKeyPress={showDetails}
tabIndex={indexResult}
>
{Object.keys(highlight)
.reverse()
Expand Down
2 changes: 1 addition & 1 deletion src/components/Searchkit/SearchBarSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const _SearchBarSection = (props) => {
sortOrder: 'asc',
layout: 'list',
page: 1,
size: 10,
size: props.currentQueryState.data.batchSize,
queryString: '',
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Searchkit/SectionsSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const _SectionsSearch = (props) => {
sortOrder: 'desc',
layout: 'list',
page: 1,
size: 10,
size: props.currentQueryState.data.batchSize,
filters: currentQueryState.filters,
};
if (currentQueryState.queryString) {
Expand Down
Loading

0 comments on commit 32d4f26

Please sign in to comment.