Skip to content

Commit

Permalink
feat: added usePloneRanking option in Search Block (#820)
Browse files Browse the repository at this point in the history
* feat: added usePloneRanking option in Search Block

* Update RELEASE.md

---------

Co-authored-by: Martina Bustacchini <[email protected]>
  • Loading branch information
2 people authored and pnicolli committed Dec 20, 2024
1 parent 0e4293d commit 7b12ae3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

### Novità

- ...
- Nel blocco 'Cerca' è stata aggiunta l'opzione "Usa l'ordinamento dei risultati di Plone" nella sezione 'Controlli'.

### Fix

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
existing listing template styles
- Inspired from
https://github.com/plone/volto/commit/211d9bea13119cc430db9d53a4740a860781ca2e
the way to handle search sort
the way to handle search sort. If searchableText is setted, discard default sorting and uses plone's ranking only if is configured from sidebar. (Changed applyDefaults fn passing usePloneRanking)
*/

import React from 'react';
Expand Down Expand Up @@ -52,7 +52,7 @@ const blockPropsAreChanged = (prevProps, nextProps) => {
return isEqual(prev, next);
};

const applyDefaults = (data, root) => {
const applyDefaults = (data, root, usePloneRanking) => {
const defaultQuery = [
{
i: 'path',
Expand All @@ -65,19 +65,13 @@ const applyDefaults = (data, root) => {
(item) => item['i'] === 'SearchableText',
).length;

const sort_on =
searchBySearchableText === 0
? data?.sort_on
? { sort_on: data.sort_on }
: { sort_on: 'effective' }
: undefined;
let sort_on = { sort_on: data?.sort_on ?? 'effective' };
let sort_order = { sort_order: data?.sort_order ?? 'descending' };

const sort_order =
searchBySearchableText === 0
? data?.sort_order
? { sort_order: data.sort_order }
: { sort_order: 'descending' }
: undefined;
if (usePloneRanking && searchBySearchableText > 0) {
sort_on = undefined;
sort_order = undefined;
}

const result = {
...data,
Expand Down Expand Up @@ -115,7 +109,7 @@ const SearchBlockView = (props) => {
}, [dataListingBodyVariation, mode]);

const root = useSelector((state) => state.breadcrumbs.root);
const listingBodyData = applyDefaults(searchData, root);
const listingBodyData = applyDefaults(searchData, root, data.usePloneRanking);
const { variations } = config.blocks.blocksConfig.listing;
const listingBodyVariation = variations.find(({ id }) => id === selectedView);
if (!Layout) return null;
Expand Down
16 changes: 16 additions & 0 deletions src/customizations/volto/components/manage/Blocks/Search/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ const messages = defineMessages({
id: 'Link to',
defaultMessage: 'Link to',
},
usePloneRanking: {
id: "Usa l'ordinamento dei risultati di Plone",
defaultMessage: "Usa l'ordinamento dei risultati di Plone",
},
usePloneRankingDescription: {
id: "Usa l'ordinamento dei risultati di Plone - descrizione",
defaultMessage:
"Se impostato, nel momento in cui un utente effettua una ricerca testuale per parola chiave, non viene usato l'ordinamento di default impostato nella sezione 'Ricerca iniziale', ma l'ordinamento di Plone in base all'ordine di importanza dei risultati da esso stabilito.",
},
});

const enhanceSchema = (originalSchema, formData) => {
Expand Down Expand Up @@ -285,6 +294,7 @@ const SearchSchema = ({ data = {}, intl }) => {
...(data.showSearchInput ?? true ? ['showSearchButton'] : []),
// ...(data.showSearchInput ? ['searchInputPrompt'] : []),
// ...(data.showSearchButton ? ['searchButtonLabel'] : []),
'usePloneRanking',
'showTotalResults',
],
},
Expand Down Expand Up @@ -316,6 +326,12 @@ const SearchSchema = ({ data = {}, intl }) => {
title: intl.formatMessage(messages.showTotalResults),
default: true,
},
usePloneRanking: {
type: 'boolean',
title: intl.formatMessage(messages.usePloneRanking),
description: intl.formatMessage(messages.usePloneRankingDescription),
default: false,
},
searchButtonLabel: {
title: intl.formatMessage(messages.searchButtonLabel),
placeholder: intl.formatMessage(messages.searchButtonPlaceholder),
Expand Down

0 comments on commit 7b12ae3

Please sign in to comment.