Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added collapse specification property #3043

Merged
merged 4 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/usage/search-results/data-sources/microsoft-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The _'Microsoft Search'_ data source retrieve items from the Microsoft search en
| **Entity types to search** | The entity types to search. See the [Microsoft Search API documentation](https://docs.microsoft.com/en-us/graph/api/resources/search-api-overview?view=graph-rest-beta) to see valid combinations. | Drive items (SharePoint & OneDrive)
| **Query template** | A query template allowing to use tokens to set a base query the same way as SharePoint search. | `{searchTerms}`
| **Use beta endpoint** | Flag to switch between `v1.0` and `beta` Microsoft Graph endpoint. |**false**
| **Collapse settings (beta only)** | Specifies the criteria used for collapsing search results. Applies only to sortable/refinable properties. [More information about the CollapseProperties](https://learn.microsoft.com/en-us/graph/search-concept-collapse) | None.
| **Enable spelling suggestions** | Flag to enable spelling suggestions. If enabled, the user will get the search results for the original search query and suggestions for spelling correction in the **queryAlterationResponse** property of the response for the typos in the query. |**false**
| **Enable spelling modifications** | Flag to enable spelling modifications. If enabled, the user will get the search results for the corrected query in case of no results for the original query with typos. The response will also include the spelling modification information in the **queryAlterationResponse** property. |**false**
| **Sort settings** | Configure the sort settings of the data source. Properties listed in the dropdown are all static properties marked as _'Sortable'_ in the [SharePoint search schema](https://docs.microsoft.com/sharepoint/technical-reference/). However, it does not list all possible _RefinableXXX_ or aliases fields. To use them, you must enter the value manually and press 'Enter' to validate. For a particular field, you can define if it should be used for initial sort (i.e. when the results are loaded for the first time) or be only available for users in the sort control (i.e. after the results are loaded). **The sort control does not consider default sort fields (i.e. select them by default) and you can only sort on a single field at a time according the fields you defined**. If no user sort fields are defined in the configuration, the sort control won't be displayed. | None.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ The _'SharePoint Search'_ data source retrieve items from the SharePoint search
| **Enable audience targeting** | Whether or not results should be targeted according to the audiences that the current user belongs to. [More information about modern audiences and how to configure them](https://support.microsoft.com/office/target-navigation-news-and-files-to-specific-audiences-33d84cb6-14ed-4e53-a426-74c38ea32293). | False.
| **Enable localization** | If enabled, the Web Part will try to translate the taxonomy term IDs found in result item properties and refinement values to their corresponding label according to the curent UI language. To get it work, you must map a new refinable managed property associated with `ows_taxId_` crawled property and turn this toggle 'on': <a href="../../../../assets/webparts/search-results/localization_crawled_property.png"><img src="../../../../assets/webparts/search-results/localization_crawled_property.png"/></a> If enabled and depending on how many items are currently being displayed, this could slightly decrease the loading performance. </br></br>**To use translated values in your template, you must use the '`Auto + <property_name>`' property format instead of the original property name**. For instance, to use translated values of the '_owstaxidmetadataalltagsinfo_' property, you must use the '**Auto**owstaxidmetadataalltagsinfo' auto created property. | False.
| **Hit-highlighted properties** | The list of SharePoint managed properties (separated by a comma) to return hit highlighted information (whether the search query match each specified managed property or not).<p><b>Note:</b> **HitHighlightedProperties** will be null if there is a field in **Hit-highlighted properties** doesn't exist in **Selected properties** </p> | None.

| **Collapse specification** | The CollapseSpecification property takes a Spec parameter that can contain multiple fields separated either by a comma or a space, which evaluated together specify a set of criteria used for collapsing. [More information about the CollapseSpecification](https://learn.microsoft.com/en-us/sharepoint/dev/general-development/customizing-search-results-in-sharepoint#collapse-similar-search-results-using-the-collapsespecification-property). | None.
66 changes: 62 additions & 4 deletions search-parts/src/dataSources/MicrosoftSearchDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ServiceScope } from '@microsoft/sp-core-library';
import { Dropdown, IComboBoxOption, IDropdownProps, ITextFieldProps, TextField } from 'office-ui-fabric-react';
import { PropertyPaneAsyncCombo } from "../controls/PropertyPaneAsyncCombo/PropertyPaneAsyncCombo";
import * as commonStrings from 'CommonStrings';
import { IMicrosoftSearchRequest, ISearchRequestAggregation, SearchAggregationSortBy, ISearchSortProperty, IMicrosoftSearchQuery, IQueryAlterationOptions } from '../models/search/IMicrosoftSearchRequest';
import { IMicrosoftSearchRequest, ISearchRequestAggregation, SearchAggregationSortBy, ISearchSortProperty, IMicrosoftSearchQuery, IQueryAlterationOptions, ICollapseProperty } from '../models/search/IMicrosoftSearchRequest';
import { DateHelper } from '../helpers/DateHelper';
import { DataFilterHelper } from "../helpers/DataFilterHelper";
import { IMicrosoftSearchResultSet } from "../models/search/IMicrosoftSearchResponse";
Expand Down Expand Up @@ -94,6 +94,12 @@ export interface IMicrosoftSearchDataSourceProperties {
* Indicates whether to trim away the duplicate SharePoint files from search results. Default value is false.
*/
trimDuplicates: boolean;

/**
* Specifies the criteria used for collapsing search results. Applies only to sortable/refinable properties.
* More information: https://learn.microsoft.com/en-us/graph/search-concept-collapse
*/
collapseProperties: ICollapseProperty[];
}

export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDataSourceProperties> {
Expand All @@ -109,6 +115,8 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
} as IComboBoxOption;
});

private _collapsibaleFields: IComboBoxOption[] = this._sortableFields;

private _availableEntityTypeOptions: IComboBoxOption[] = [
{
key: EntityType.Message,
Expand Down Expand Up @@ -318,6 +326,49 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
PropertyPaneToggle('dataSourceProperties.trimDuplicates', {
label: commonStrings.DataSources.MicrosoftSearch.TrimDuplicates
}),
this._propertyFieldCollectionData('dataSourceProperties.collapseProperties', {
manageBtnLabel: commonStrings.DataSources.MicrosoftSearch.CollapseProperties.EditCollapsePropertiesLabel,
key: 'collapseProperties',
enableSorting: true,
panelHeader: commonStrings.DataSources.MicrosoftSearch.CollapseProperties.EditCollapsePropertiesLabel,
panelDescription: commonStrings.DataSources.MicrosoftSearch.CollapseProperties.CollapsePropertiesDescription,
label: commonStrings.DataSources.MicrosoftSearch.CollapseProperties.CollapsePropertiesPropertyPaneFieldLabel,
value: this.properties.collapseProperties,
fields: [
{
id: 'fields',
title: commonStrings.DataSources.SearchCommon.Sort.SortFieldColumnLabel,
type: this._customCollectionFieldType.custom,
required: true,
onCustomRender: ((field, value, onUpdate, item, itemId, onError) => {

return React.createElement("div", { key: `${field.id}-${itemId}` },
React.createElement(AsyncCombo, {
defaultSelectedKeys: item[field.id] ? item[field.id] : '',
allowMultiSelect: true,
allowFreeform: true,
availableOptions: this._collapsibaleFields,
onUpdateOptions: ((options: IComboBoxOption[]) => {
this._collapsibaleFields = options;
}).bind(this),
clearTextOnFocus: true,
onUpdate: (options: IComboBoxOption[]) => {
const updateOptions = options?.length == 0 ? undefined : options.map(o => o.key as string);
onUpdate(field.id, updateOptions);
},
placeholder: commonStrings.DataSources.MicrosoftSearch.CollapseProperties.CollapsePropertiesFieldColumnPlaceholder,
useComboBoxAsMenuWidth: false // Used when screen resolution is too small to display the complete value
} as IAsyncComboProps));
}).bind(this)
},
{
id: 'limit',
title: commonStrings.DataSources.MicrosoftSearch.CollapseProperties.CollapseLimitFieldLabel,
type: this._customCollectionFieldType.number,
required: true
}
]
}),
PropertyPaneHorizontalRule()
);
}
Expand Down Expand Up @@ -607,6 +658,7 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
this.properties.useBetaEndpoint = this.properties.useBetaEndpoint !== undefined ? this.properties.useBetaEndpoint : false;
this.properties.enableResultTypes = this.properties.enableResultTypes !== undefined ? this.properties.enableResultTypes : false;
this.properties.trimDuplicates = this.properties.trimDuplicates !== undefined ? this.properties.trimDuplicates : false;
this.properties.collapseProperties = this.properties.collapseProperties !== undefined ? this.properties.collapseProperties : [];

if (this.properties.useBetaEndpoint) {
this._microsoftSearchUrl = "https://graph.microsoft.com/beta/search/query";
Expand Down Expand Up @@ -782,9 +834,15 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
searchRequest.contentSources = contentSources;
}

if (this.properties.trimDuplicates) {
// Default value is always 'false'
searchRequest.trimDuplicates = this.properties.trimDuplicates;
if (this.properties.useBetaEndpoint) {
if (this.properties.trimDuplicates) {
// Default value is always 'false'
searchRequest.trimDuplicates = this.properties.trimDuplicates;
}

if (this.properties.collapseProperties.length > 0) {
searchRequest.collapseProperties = this.properties.collapseProperties;
}
}

searchRequest.queryAlterationOptions = {
Expand Down
18 changes: 18 additions & 0 deletions search-parts/src/dataSources/SharePointSearchDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ export interface ISharePointSearchDataSourceProperties {
* "true" to remove the duplicate items; otherwise, false. The default value is true.
*/
trimDuplicates: boolean;

/**
* The CollapseSpecification property takes a Spec parameter that can contain multiple fields separated either by a comma or a space,
* which evaluated together specify a set of criteria used for collapsing.
* More information: https://learn.microsoft.com/en-us/sharepoint/dev/general-development/customizing-search-results-in-sharepoint#collapse-similar-search-results-using-the-collapsespecification-property
*/
collapseSpecification: string;
}

export class SharePointSearchDataSource extends BaseDataSource<ISharePointSearchDataSourceProperties> {
Expand Down Expand Up @@ -425,6 +432,16 @@ export class SharePointSearchDataSource extends BaseDataSource<ISharePointSearch
PropertyPaneToggle('dataSourceProperties.trimDuplicates', {
label: commonStrings.DataSources.SharePointSearch.TrimDuplicates
}),
new PropertyPaneNonReactiveTextField('dataSourceProperties.collapseSpecification', {
componentKey: `${BuiltinDataSourceProviderKeys.SharePointSearch}-collapseSpecification`,
defaultValue: this.properties.collapseSpecification,
label: commonStrings.DataSources.SharePointSearch.CollapseSpecificationLabel,
placeholderText: `ex: Author:1 ContentType:2`,
multiline: false,
allowEmptyValue: true,
applyBtnText: commonStrings.DataSources.SharePointSearch.ApplyQueryTemplateBtnText,
rows: 2
}),
PropertyPaneToggle('dataSourceProperties.enableAudienceTargeting', {
label: commonStrings.DataSources.SharePointSearch.EnableAudienceTargetingTglLabel,
checked: this.properties.enableAudienceTargeting,
Expand Down Expand Up @@ -909,6 +926,7 @@ export class SharePointSearchDataSource extends BaseDataSource<ISharePointSearch
}

searchQuery.TrimDuplicates = this.properties.trimDuplicates;
searchQuery.CollapseSpecification = this.properties.collapseSpecification;

if (dataContext.sorting?.selectedSortFieldName
&& dataContext.sorting?.selectedSortDirection) {
Expand Down
8 changes: 8 additions & 0 deletions search-parts/src/loc/commonStrings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ declare interface ICommonStrings {
TermNotFound: string;
ApplyQueryTemplateBtnText: string;
EnableAudienceTargetingTglLabel: string;
CollapseSpecificationLabel: string;
},
MicrosoftSearch: {
QueryTextFieldLabel: string;
Expand All @@ -148,6 +149,13 @@ declare interface ICommonStrings {
ApplyQueryTemplateBtnText: string;
UseBetaEndpoint: string;
TrimDuplicates: string;
CollapseProperties: {
EditCollapsePropertiesLabel: string;
CollapsePropertiesDescription: string;
CollapsePropertiesPropertyPaneFieldLabel: string;
CollapseLimitFieldLabel: string;
CollapsePropertiesFieldColumnPlaceholder: string;
}
},
SearchCommon: {
Sort: {
Expand Down
12 changes: 10 additions & 2 deletions search-parts/src/loc/da-dk.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ define([], function() {
TermNotFound: "(Term med ID '{0}' blev ikke fundet)",
ApplyQueryTemplateBtnText: "Anvend",
EnableAudienceTargetingTglLabel: "Aktivér målgruppestyring",
TrimDuplicates: "Trim dubletter"
TrimDuplicates: "Trim dubletter",
CollapseSpecificationLabel: "Skjul specifikation"
},
MicrosoftSearch: {
QueryTextFieldLabel: "Forespørgselstekst",
Expand All @@ -148,7 +149,14 @@ define([], function() {
QueryTemplateFieldDescription: "Søgemodifikator-skabelonen. Du kan også bruge {<tokens>} og KQL til at bygge en dynamisk forespørgsel. Alt sammenkædes til inputQueryText",
ApplyQueryTemplateBtnText: "Anvend",
UseBetaEndpoint: "Brug beta-endepunkt",
TrimDuplicates: "Trim dubletter"
TrimDuplicates: "Trim dubletter",
CollapseProperties: {
EditCollapsePropertiesLabel: "Rediger indstillinger for skjul",
CollapsePropertiesDescription: "Angiv indstillingerne for sammenbrud for søgeresultaterne. Du kan enten vælge et felt fra rullelisten (kun hvis datakildedataene allerede er hentet) eller indtaste din egen tilpassede værdi (tryk på 'Enter' for at gemme din indtastning)",
CollapsePropertiesPropertyPaneFieldLabel: "Indstillingerne for sammenbrud",
CollapseLimitFieldLabel: "Begrænse",
CollapsePropertiesFieldColumnPlaceholder: "Kollaps efter felt"
}
},
SearchCommon: {
Sort: {
Expand Down
12 changes: 10 additions & 2 deletions search-parts/src/loc/de-de.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ define([], function() {
TermNotFound: "(Begriff mit ID '{0}' nicht gefunden)",
ApplyQueryTemplateBtnText: "Übernehmen",
EnableAudienceTargetingTglLabel: "Zielgruppen Adressierung aktivieren",
TrimDuplicates: "Duplikate kürzen"
TrimDuplicates: "Duplikate kürzen",
CollapseSpecificationLabel: "Spezifikation einklappen"
},
MicrosoftSearch: {
QueryTextFieldLabel: "Abfragetext",
Expand All @@ -148,7 +149,14 @@ define([], function() {
QueryTemplateFieldDescription: "Die Suchvorlage. Es können auch {<tokens>} und KQL für die Erstellung einer dynamischen Query benutzt werden.",
ApplyQueryTemplateBtnText: "Anwenden",
UseBetaEndpoint: "Benutze den Beta-Endpunkt",
TrimDuplicates: "Duplikate kürzen"
TrimDuplicates: "Duplikate kürzen",
CollapseProperties: {
EditCollapsePropertiesLabel: "Bearbeiten Sie die Minimierungseinstellungen",
CollapsePropertiesDescription: "Angiv indstillingerne for sammenbrud for søgeresultaterne. Du kan enten vælge et felt fra rullelisten (kun hvis datakildedataene allerede er hentet) eller indtaste din egen tilpassede værdi (tryk på 'Enter' for at gemme din indtastning)",
CollapsePropertiesPropertyPaneFieldLabel: "Minimierungseinstellungen",
CollapseLimitFieldLabel: "Grenze",
CollapsePropertiesFieldColumnPlaceholder: "Nach Feld reduzieren"
}
},
SearchCommon: {
Sort: {
Expand Down
12 changes: 10 additions & 2 deletions search-parts/src/loc/en-us.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ define([], function() {
TermNotFound: "(Term with ID '{0}' not found)",
ApplyQueryTemplateBtnText: "Apply",
EnableAudienceTargetingTglLabel: "Enable audience targeting",
TrimDuplicates: "Trim duplicates"
TrimDuplicates: "Trim duplicates",
CollapseSpecificationLabel: "Collapse specification"
},
MicrosoftSearch: {
QueryTextFieldLabel: "Query text",
Expand All @@ -148,7 +149,14 @@ define([], function() {
QueryTemplateFieldDescription: "The search query template. You can also use {<tokens>} and KQL to build a dynamic query.",
ApplyQueryTemplateBtnText: "Apply",
UseBetaEndpoint: "Use beta endpoint",
TrimDuplicates: "Trim duplicates"
TrimDuplicates: "Trim duplicates",
CollapseProperties: {
EditCollapsePropertiesLabel: "Edit collapse settings",
CollapsePropertiesDescription: "Specify the collapse settings for the search results. You can either select a field from the dropdown list (only if the data source data have already be fetched) or type your own custom value (press 'Enter' to save your entry)",
CollapsePropertiesPropertyPaneFieldLabel: "Collapse settings",
CollapseLimitFieldLabel: "Limit",
CollapsePropertiesFieldColumnPlaceholder: "Collapse on field"
}
},
SearchCommon: {
Sort: {
Expand Down
Loading