mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ADF-2201] Search Configuration doc (#2876)
* [ADF-2201] Updated search component docs and tidied index page * [ADF-2201] Fixed incorrect link * [ADF-2201] Updated docs based on feedback * [ADF-2201] Fixed broken relative link
This commit is contained in:
+12
-54
@@ -19,7 +19,7 @@ Searches items for supplied search terms.
|
||||
| maxResults | number | 20 | Maximum number of results to show in the search. |
|
||||
| skipResults | number | 0 | Number of results to skip from the results pagination. |
|
||||
| displayWith | function | | Function that maps an option's value to its display value in the trigger |
|
||||
| queryBody| [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api. This input is deprecated, to use the extended query body function please refer to the suggested solution [here](./search.component.md#querybody) |
|
||||
| queryBody | [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api. This input is deprecated, to use the extended query body function please refer to the suggested solution [here](./search.component.md#custom-search-configuration) |
|
||||
|
||||
### Events
|
||||
|
||||
@@ -114,59 +114,17 @@ Yuo can do this by exporting the adf-search panel instance into a local template
|
||||
|
||||
In this way it is possible to fetch the results from the word typed into the input text straight into the adf-search component via the custom template variable.
|
||||
|
||||
## QueryBody
|
||||
This is an example on how you can provide your own class to generate your custom query body without giving it in input to the search component.
|
||||
### Custom search configuration
|
||||
|
||||
1. Service Class
|
||||
You need to create your own service class which will implement the SearchConfigurationInterface this will force you to create the method generateQueryBody that is the one which needs to return the QueryBody object.
|
||||
|
||||
```ts
|
||||
import { QueryBody } 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 = {
|
||||
query: {
|
||||
query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm
|
||||
},
|
||||
include: ['path', 'allowableOperations'],
|
||||
paging: {
|
||||
maxItems: maxResults,
|
||||
skipCount: skipCount
|
||||
},
|
||||
filterQueries: [
|
||||
{ query: "TYPE:'cm:folder'" },
|
||||
{ query: 'NOT cm:creator:System' }]
|
||||
};
|
||||
|
||||
return defaultQueryBody;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Provide your service class to the module
|
||||
Once you have created your service class to provide your custom query body you need to inform the component to use your class instead of the default one. This can be easily achieved via your component providers :
|
||||
|
||||
```ts
|
||||
import { SearchService, SearchConfigurationService } from '@alfresco/adf-core';
|
||||
import { TestSearchConfigurationService } from './search-config-test.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-search-extended-component',
|
||||
templateUrl: './search-extended.component.html',
|
||||
styleUrls: ['./search-extended.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
providers: [
|
||||
{ provide: SearchConfigurationService, useClass: TestSearchConfigurationService },
|
||||
SearchService
|
||||
]
|
||||
})
|
||||
```
|
||||
You need to add as provider even the SearchService to avoid the override of the module instance. So this component will have his own instance of the SearchService that will use as configuration the class you have provided.
|
||||
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
|
||||
[Search Configuration interface](search-configuration.interface.md) (the `queryBody` parameter of the `Search component` is now deprecated). The ADF source provides a standard implementation of this
|
||||
interface, `SearchConfigurationService` that you can use as a base to adapt to your needs. See the
|
||||
[Search Configuration interface](search-configuration.interface.md) page for full details of how to
|
||||
customize your search.
|
||||
|
||||
## See Also
|
||||
|
||||
- [Search configuration interface](search-configuration.interface.md)
|
||||
- [Search configuration service](search-configuration.service.md)
|
||||
|
||||
Reference in New Issue
Block a user