Skip to content

Commit

Permalink
[ACS-5839] migrate from QueryBody to SearchResult type (#8861)
Browse files Browse the repository at this point in the history
* [ci:force] migrate from QueryBody to SearchQuery

* [ci:force] migrate from QueryBody to SearchQuery

* [ci:force] migrate from QueryBody to SearchQuery

* [ci:force] update docs and variables as per code review
  • Loading branch information
DenysVuika committed Aug 31, 2023
1 parent c73e95c commit c83d92c
Show file tree
Hide file tree
Showing 18 changed files with 340 additions and 480 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
* limitations under the License.
*/

import { QueryBody } from '@alfresco/js-api';
import { SearchRequest } from '@alfresco/js-api';
import { SearchConfigurationInterface } from '@alfresco/adf-content-services';
import { Injectable } from '@angular/core';

@Injectable()
export class TestSearchConfigurationService implements SearchConfigurationInterface {

public generateQueryBody(searchTerm: string, maxResults: number, skipCount: number): QueryBody {
const defaultQueryBody: QueryBody = {
public generateQueryBody(searchTerm: string, maxResults: number, skipCount: number): SearchRequest {
return {
query: {
query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm
},
Expand All @@ -35,9 +34,8 @@ export class TestSearchConfigurationService implements SearchConfigurationInterf
filterQueries: [
/* eslint-disable-next-line */
{ query: "TYPE:'cm:folder'" },
{ query: 'NOT cm:creator:System' }]
{ query: 'NOT cm:creator:System' }
]
};

return defaultQueryBody;
}
}
2 changes: 1 addition & 1 deletion docs/breaking-changes/breaking-change-2.6.0-3.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This document lists all the deprecated ADF v2.x components that were removed for
This modification has enabled us to remove some code duplication between the two modules.

- [PR ADF-1873](https://github.com/Alfresco/alfresco-ng2-components/pull/4145):
- `adf-search-control`: The `QueryBody`, and
- `adf-search-control`: The `SearchRequest`, and
`customQueryBody` inputs of the [`SearchControlComponent`](../content-services/components/search-control.component.md) have been removed in favor of the
[custom search configuration interface](../core/interfaces/search-configuration.interface.md).
The inputs were deprecated in v2.1.0.
Expand Down
3 changes: 1 addition & 2 deletions docs/content-services/components/search.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ By doing this, you can get the results as the user types into the input text.
### Custom search configuration

You can get finer control over the parameters of a search by defining them in a custom
[QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md)
object. The recommended way to do this is with a custom implementation of the
**SearchRequest** object. The recommended way to do this is with a custom implementation of the
[Search Configuration interface](../../core/interfaces/search-configuration.interface.md). The ADF source provides a standard implementation of this
interface, [`SearchConfigurationService`](../../core/services/search-configuration.service.md) that you can use as a base to adapt to your needs. See the
[Search Configuration interface](../../core/interfaces/search-configuration.interface.md) page for full details of how to
Expand Down
16 changes: 8 additions & 8 deletions docs/content-services/services/search-query-builder.service.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Stores information from all the custom search and faceted search widgets, compil
Adds a facet bucket to a field.
- _field:_ [`FacetField`](../../../lib/content-services/src/lib/search/models/facet-field.interface.ts) - The target field
- _bucket:_ [`FacetFieldBucket`](../../../lib/content-services/src/lib/search/models/facet-field-bucket.interface.ts) - Bucket to add
- **buildQuery**(): `QueryBody`<br/>
- **buildQuery**(): `SearchRequest`<br/>
Builds the current query.
- **Returns** `QueryBody` - The finished query
- **execute**(queryBody?: `QueryBody`)<br/>
- **Returns** `SearchRequest` - The finished query
- **execute**(queryBody?: `SearchRequest`)<br/>
Builds and executes the current query.
- _queryBody:_ `QueryBody` - (Optional)
- _queryBody:_ `SearchRequest` - (Optional)
- **getDefaultConfiguration**(): [`SearchConfiguration`](../../../lib/content-services/src/lib/search/models/search-configuration.interface.ts)`|undefined`<br/>

- **Returns** [`SearchConfiguration`](../../../lib/content-services/src/lib/search/models/search-configuration.interface.ts)`|undefined` -
Expand Down Expand Up @@ -81,18 +81,18 @@ Stores information from all the custom search and faceted search widgets, compil
- _bucket:_ [`FacetFieldBucket`](../../../lib/content-services/src/lib/search/models/facet-field-bucket.interface.ts) - Bucket to remove
- **resetToDefaults**()<br/>

- **search**(queryBody: `QueryBody`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ResultSetPaging`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/search-rest-api/docs/ResultSetPaging.md)`>`<br/>
- **search**(queryBody: `SearchRequest`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ResultSetPaging`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/search-rest-api/docs/ResultSetPaging.md)`>`<br/>

- _queryBody:_ `QueryBody` -
- _queryBody:_ `SearchRequest` -
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ResultSetPaging`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/search-rest-api/docs/ResultSetPaging.md)`>` -

- **setScope**(scope: `RequestScope`)<br/>

- _scope:_ `RequestScope` -

- **update**(queryBody?: `QueryBody`)<br/>
- **update**(queryBody?: `SearchRequest`)<br/>
Builds the current query and triggers the `updated` event.
- _queryBody:_ `QueryBody` - (Optional)
- _queryBody:_ `SearchRequest` - (Optional)
- **updateSelectedConfiguration**(index: `number`)<br/>

- _index:_ `number` -
Expand Down
26 changes: 9 additions & 17 deletions docs/core/interfaces/search-configuration.interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ Provides fine control of parameters to a search.

## Methods

`generateQueryBody(searchTerm: string, maxResults: string, skipCount: string): QueryBody`<br/>
Generates a QueryBody object with custom search parameters.
`generateQueryBody(searchTerm: string, maxResults: string, skipCount: string): SearchRequest`<br/>
Generates a request object with custom search parameters.

## Details

The interface defines a service that generates a custom
[QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md)
object. This object can then be supplied to a search operation to refine the search parameters.
**SearchRequest** object. This object can then be supplied to a search operation to refine the search parameters.

A standard implementation, the
[Search Configuration service](../services/search-configuration.service.md) is provided in the ADF Core library
Expand All @@ -29,37 +28,30 @@ described below.
1. Implement the service class

Create your own service class to implement the [`SearchConfigurationInterface`](../../core/interfaces/search-configuration.interface.md). This defines the
the `generateQueryBody` method that returns the QueryBody object. See the
[QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md)
page in the Alfresco JS API for further details about the options this object provides.
`generateQueryBody` method that returns the query object.

An example implementation is given below:

```ts
import { QueryBody } from '@alfresco/js-api';
import { SearchRequest } from '@alfresco/js-api';
import { SearchConfigurationInterface } from '@alfresco/adf-core';

export class TestSearchConfigurationService implements SearchConfigurationInterface {

constructor() {
}

public generateQueryBody(searchTerm: string, maxResults: string, skipCount: string): QueryBody {
const defaultQueryBody: QueryBody = {
generateQueryBody(searchTerm: string, maxItems: string, skipCount: string): SearchRequest {
return {
query: {
query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm
},
include: ['path', 'allowableOperations'],
paging: {
maxItems: maxResults,
skipCount: skipCount
maxItems,
skipCount
},
filterQueries: [
{ query: "TYPE:'cm:folder'" },
{ query: 'NOT cm:creator:System' }]
};

return defaultQueryBody;
}
}
```
Expand Down
11 changes: 5 additions & 6 deletions docs/core/services/search-configuration.service.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ Provides fine control of parameters to a search.

### Methods

- **generateQueryBody**(searchTerm: `string`, maxResults: `number`, skipCount: `number`): `QueryBody`<br/>
Generates a QueryBody object with custom search parameters.
- **generateQueryBody**(searchTerm: `string`, maxResults: `number`, skipCount: `number`): `SearchRequest`<br/>
Generates a request object with custom search parameters.
- _searchTerm:_ `string` - Term text to search for
- _maxResults:_ `number` - Maximum number of search results to show in a page
- _skipCount:_ `number` - The offset of the start of the page within the results list
- **Returns** `QueryBody` - Query body defined by the parameters
- **Returns** `SearchRequest` - Query body defined by the parameters

## Details

The `generateQueryBody` method returns a
[QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md)
object. This configures the search to use `searchTerm` along with `maxResults` and `skipCount`
The `generateQueryBody` method returns a **SearchRequest** object.
This configures the search to use `searchTerm` along with `maxResults` and `skipCount`
specified for the paging of the search results.

This service is a standard implementation of the
Expand Down
6 changes: 3 additions & 3 deletions docs/core/services/search.service.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Accesses the Content Services Search API.
- _maxResults:_ `number` - Maximum number of items in the list of results
- _skipCount:_ `number` - Number of higher-ranked items to skip over in the list
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ResultSetPaging`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/search-rest-api/docs/ResultSetPaging.md)`>` - List of search results
- **searchByQueryBody**(queryBody: `QueryBody`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ResultSetPaging`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/search-rest-api/docs/ResultSetPaging.md)`>`<br/>
Performs a search with its parameters supplied by a QueryBody object.
- _queryBody:_ `QueryBody` - Object containing the search parameters
- **searchByQueryBody**(queryBody: `SearchRequest`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ResultSetPaging`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/search-rest-api/docs/ResultSetPaging.md)`>`<br/>
Performs a search with its parameters supplied by a SearchRequest object.
- _queryBody:_ `SearchRequest` - Object containing the search parameters
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ResultSetPaging`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/search-rest-api/docs/ResultSetPaging.md)`>` - List of search results

## Details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@
* limitations under the License.
*/

import { QueryBody } from '@alfresco/js-api';
import { SearchRequest } from '@alfresco/js-api';

export interface SearchConfigurationInterface {

/**
* Generates a QueryBody object with custom search parameters.
* Generates a query object with custom search parameters.
*
* @param searchTerm Term text to search for
* @param maxResults Maximum number of search results to show in a page
* @param skipCount The offset of the start of the page within the results list
* @returns Query body defined by the parameters
*/
generateQueryBody(searchTerm: string, maxResults: number, skipCount: number): QueryBody;

generateQueryBody(searchTerm: string, maxResults: number, skipCount: number): SearchRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { CustomResourcesService } from '../document-list/services/custom-resourc
import { NodeEntryEvent, ShareDataRow } from '../document-list';
import { TranslateModule } from '@ngx-translate/core';
import { SearchQueryBuilderService } from '../search';
import { mockQueryBody } from '../mock/search-query.mock';
import { mockSearchRequest } from '../mock/search-query.mock';
import { SitesService } from '../common/services/sites.service';
import { NodesApiService } from '../common/services/nodes-api.service';

Expand Down Expand Up @@ -168,16 +168,16 @@ describe('ContentNodeSelectorPanelComponent', () => {
expect(component.searchTerm).toEqual('search-term');
}));

it('should perform a search when the queryBody gets updated and it is defined', fakeAsync(() => {
it('should perform a search when the search request gets updated and it is defined', fakeAsync(() => {
typeToSearchBox('search-term');

tick(debounceSearch);
fixture.detectChanges();

expect(searchSpy).toHaveBeenCalledWith(mockQueryBody);
expect(searchSpy).toHaveBeenCalledWith(mockSearchRequest);
}));

it('should NOT perform a search and clear the results when the queryBody gets updated and it is NOT defined', async () => {
it('should NOT perform a search and clear the results when the search request gets updated and it is NOT defined', async () => {
spyOn(component, 'clearSearch');

searchQueryBuilderService.userQuery = '';
Expand Down Expand Up @@ -212,22 +212,22 @@ describe('ContentNodeSelectorPanelComponent', () => {
tick(debounceSearch);
fixture.detectChanges();

expect(searchSpy).toHaveBeenCalledWith(mockQueryBody);
expect(searchSpy).toHaveBeenCalledWith(mockSearchRequest);
}));

it('should the query include the show files filterQuery', fakeAsync(() => {
component.showFilesInResult = true;
typeToSearchBox('search-term');

const expectedQueryBody = mockQueryBody;
expectedQueryBody.filterQueries.push({
const expectedRequest = mockSearchRequest;
expectedRequest.filterQueries.push({
query: `TYPE:'cm:folder' OR TYPE:'cm:content'`
});

tick(debounceSearch);
fixture.detectChanges();

expect(searchSpy).toHaveBeenCalledWith(expectedQueryBody);
expect(searchSpy).toHaveBeenCalledWith(expectedRequest);
}));

it('should reset the currently chosen node in case of starting a new search', fakeAsync(() => {
Expand Down Expand Up @@ -257,11 +257,11 @@ describe('ContentNodeSelectorPanelComponent', () => {

component.siteChanged({ entry: { guid: 'namek' } } as SiteEntry);

const expectedQueryBody = mockQueryBody;
expectedQueryBody.filterQueries = [{ query: `ANCESTOR:'workspace://SpacesStore/namek'` }];
const expectedRequest = mockSearchRequest;
expectedRequest.filterQueries = [{ query: `ANCESTOR:'workspace://SpacesStore/namek'` }];

expect(searchSpy.calls.count()).toBe(2);
expect(searchSpy).toHaveBeenCalledWith(expectedQueryBody);
expect(searchSpy).toHaveBeenCalledWith(expectedRequest);
}));

it('should create the query with the right parameters on changing the site selectBox value from a custom dropdown menu', fakeAsync(() => {
Expand All @@ -277,17 +277,17 @@ describe('ContentNodeSelectorPanelComponent', () => {

component.siteChanged({ entry: { guid: '-sites-' } } as SiteEntry);

const expectedQueryBodyWithSiteChange = mockQueryBody;
expectedQueryBodyWithSiteChange.filterQueries = [
const expectedRequest = mockSearchRequest;
expectedRequest.filterQueries = [
{
query: `ANCESTOR:'workspace://SpacesStore/-sites-' OR ANCESTOR:'workspace://SpacesStore/123456testId' OR ANCESTOR:'workspace://SpacesStore/09876543testId'`
}
];

expect(searchSpy).toHaveBeenCalled();
expect(searchSpy.calls.count()).toBe(2);
expect(searchSpy).toHaveBeenCalledWith(mockQueryBody);
expect(searchSpy).toHaveBeenCalledWith(expectedQueryBodyWithSiteChange);
expect(searchSpy).toHaveBeenCalledWith(mockSearchRequest);
expect(searchSpy).toHaveBeenCalledWith(expectedRequest);
}));

it('should get the corresponding node ids on search when a known alias is selected from dropdown', fakeAsync(() => {
Expand Down Expand Up @@ -404,10 +404,10 @@ describe('ContentNodeSelectorPanelComponent', () => {
typeToSearchBox('search-term');
tick(debounceSearch);

const expectedQueryBody = mockQueryBody;
expectedQueryBody.filterQueries = [{ query: `ANCESTOR:'workspace://SpacesStore/my-root-id'` }];
const expectedRequest = mockSearchRequest;
expectedRequest.filterQueries = [{ query: `ANCESTOR:'workspace://SpacesStore/my-root-id'` }];

expect(searchSpy).toHaveBeenCalledWith(expectedQueryBody);
expect(searchSpy).toHaveBeenCalledWith(expectedRequest);
}));

it('should emit showingSearch event with true while searching', async () => {
Expand Down Expand Up @@ -476,10 +476,10 @@ describe('ContentNodeSelectorPanelComponent', () => {
component.restrictRootToCurrentFolderId = true;
component.siteChanged({ entry: { guid: 'my-site-id' } } as SiteEntry);

const expectedQueryBodyWithSiteChange = mockQueryBody;
expectedQueryBodyWithSiteChange.filterQueries = [{ query: `ANCESTOR:'workspace://SpacesStore/my-site-id'` }];
const expectedRequest = mockSearchRequest;
expectedRequest.filterQueries = [{ query: `ANCESTOR:'workspace://SpacesStore/my-site-id'` }];

expect(searchSpy).toHaveBeenCalledWith(expectedQueryBodyWithSiteChange);
expect(searchSpy).toHaveBeenCalledWith(expectedRequest);
});

it('should restrict the breadcrumb to the currentFolderId in case restrictedRoot is true', async () => {
Expand Down Expand Up @@ -735,7 +735,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
});

it('should set its loading state to true to perform a new search', async () => {
component.prepareDialogForNewSearch(mockQueryBody);
component.prepareDialogForNewSearch(mockSearchRequest);
fixture.detectChanges();
await fixture.whenStable();

Expand Down

0 comments on commit c83d92c

Please sign in to comment.