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

Add SharePoint and MS archived content options to search request and … #4215

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions docs/usage/search-results/data-sources/microsoft-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ The _'Microsoft Search'_ data source retrieve items from the Microsoft search en
| **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.
| **Enable result Types** | Display results according to the result types defined in the Microsoft Search admin center. **This option can only be used if `External Items` entity type is selected and the layout type is "Adaptive Cards** | None.
| **Show SharePoint Embedded (hidden) in search results** | By default content in SharePoint Embedded Containers is not [visible](https://learn.microsoft.com/en-us/sharepoint/dev/embedded/concepts/content-experiences/search-content) in Microsoft Search. Add the relevant ContainerTypeids to the query template, like ContainerTypeId:"1adc34ca-aef3-4e13-aacf-39b43affd198" and the contain is now returned. | None.
| **Show MS Archived content in search results** | By default contain archived with Microsoft Archive is hidden from Microsoft Search, but this option sets the required "includeHiddenContent" and "isArchived" properties, which ensures that the contant is now returned by the API. | None.
71 changes: 61 additions & 10 deletions search-parts/src/dataSources/MicrosoftSearchDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ export interface IMicrosoftSearchDataSourceProperties {
* More information: https://learn.microsoft.com/en-us/graph/search-concept-collapse
*/
collapseProperties: ICollapseProperty[];
/**
* Specifies if the search results should include the SharePoint embedded data.
* More information: https://learn.microsoft.com/en-us/sharepoint/dev/embedded/concepts/content-experiences/search-content
*/
showSPEmbeddedContent: boolean;

/**
* Specifies if the search results should include the Microsoft Search archived content.
* More information: https://learn.microsoft.com/en-us/graph/api/resources/sharepointonedriveoptions?view=graph-rest-beta
*/
showMSArchivedContent: boolean;
}

export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDataSourceProperties> {
Expand Down Expand Up @@ -294,6 +305,7 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
onPropertyChange: this.onCustomPropertyUpdate.bind(this),
textDisplayValue: entityTypesDisplayValue.filter(e => e).join(",")
}),

new PropertyPaneAsyncCombo('dataSourceProperties.fields', {
availableOptions: this._availableFields,
allowMultiSelect: true,
Expand All @@ -312,6 +324,16 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
label: "Enable result types",
disabled: this.properties.entityTypes.indexOf(EntityType.ExternalItem) === -1
})
,
PropertyPaneToggle('dataSourceProperties.showSPEmbeddedContent', {
label: commonStrings.DataSources.MicrosoftSearch.showSPEmbeddedContentLabel,

})
,
PropertyPaneToggle('dataSourceProperties.showMSArchivedContent', {
label: commonStrings.DataSources.MicrosoftSearch.showMSArchivedContentLabel,

})
];

let useBetaEndpointFields: IPropertyPaneField<any>[] = [
Expand Down Expand Up @@ -374,6 +396,10 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
);
}





// Sorting results is currently only supported on the following SharePoint and OneDrive types: driveItem, listItem, list, site , ExternalItem.
if (this.properties.entityTypes.indexOf(EntityType.DriveItem) !== -1 ||
this.properties.entityTypes.indexOf(EntityType.ListItem) !== -1 ||
Expand Down Expand Up @@ -671,6 +697,8 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
} else {
this._microsoftSearchUrl = `${this.context?.pageContext?.legacyPageContext?.msGraphEndpointUrl}/v1.0/search/query`;
}
this.properties.showSPEmbeddedContent = this.properties.showSPEmbeddedContent !== undefined ? this.properties.showSPEmbeddedContent : false;
this.properties.showMSArchivedContent = this.properties.showMSArchivedContent !== undefined ? this.properties.showMSArchivedContent : false;
}

private async buildMicrosoftSearchQuery(dataContext: IDataContext): Promise<IMicrosoftSearchQuery> {
Expand All @@ -684,6 +712,10 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
let contentSources: string[] = [];
let queryText = '*'; // Default query string if not specified, the API does not support empty value
let from = 0;
// let sharePointOneDriveOptions = ""
let includeHiddenContent = false;



// Query text
if (dataContext.inputQueryText) {
Expand Down Expand Up @@ -755,17 +787,16 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa

// Build aggregation filters
if (dataContext.filters.selectedFilters.length > 0) {
if (dataContext.filters.filterOperator === 'and') {
// Make sure, if we have multiple filters, at least two filters have values to avoid apply an operator ('or','and') on only one condition failing the query.
const refinementStrings = DataFilterHelper.buildFqlRefinementString(dataContext.filters.selectedFilters, this.moment);
if (!isEmpty(refinementStrings)) {
aggregationFilters = aggregationFilters.concat(refinementStrings);

// Make sure, if we have multiple filters, at least two filters have values to avoid apply an operator ('or','and') on only one condition failing the query.
if (dataContext.filters.selectedFilters.length > 1 && dataContext.filters.selectedFilters.filter(selectedFilter => selectedFilter.values.length > 0).length > 1) {
const refinementString = DataFilterHelper.buildFqlRefinementString(dataContext.filters.selectedFilters, dataContext.filters.filtersConfiguration, this.moment).join(',');
if (!isEmpty(refinementString)) {
aggregationFilters = aggregationFilters.concat([`${dataContext.filters.filterOperator}(${refinementString})`]);
}

} else {
const refinementStrings = DataFilterHelper.buildKqlRefinementString(dataContext.filters.selectedFilters, this.moment);
if (!isEmpty(refinementStrings)) {
queryTemplate = refinementStrings ? `${queryTemplate} AND ${refinementStrings}` : queryTemplate;
}
aggregationFilters = aggregationFilters.concat(DataFilterHelper.buildFqlRefinementString(dataContext.filters.selectedFilters, dataContext.filters.filtersConfiguration, this.moment));
}
}

Expand Down Expand Up @@ -800,16 +831,36 @@ export class MicrosoftSearchDataSource extends BaseDataSource<IMicrosoftSearchDa
});
}
}

if(this.properties.showMSArchivedContent === true && this.properties.showSPEmbeddedContent === true)
{
includeHiddenContent = true;
}
if(this.properties.showMSArchivedContent === true && this.properties.showSPEmbeddedContent === false)
{
includeHiddenContent = true;
// and show only archived content
queryTemplate = queryTemplate + " AND isarchived:true";

}
if(this.properties.showMSArchivedContent === false && this.properties.showSPEmbeddedContent === true)
{
includeHiddenContent = true;
// hide archived content
queryTemplate = queryTemplate + " AND NOT isarchived:true";
}
// Build search request
let searchRequest: IMicrosoftSearchRequest = {
entityTypes: this.properties.entityTypes,
query: {
queryString: queryText,
queryTemplate: queryTemplate
},
sharePointOneDriveOptions: {
includeHiddenContent: includeHiddenContent
},
size: dataContext.itemsCountPerPage
};


//If bookmark or Acronym, paging is not supported
if (this.properties.entityTypes.indexOf(EntityType.Bookmark) === -1 && this.properties.entityTypes.indexOf(EntityType.Acronym) === -1) {
Expand Down
Loading