Search a Post
The searchPosts() function is used to search posts based on various parameters such as page, page size, search term, and search type. It returns a SearchPostResponse object containing the results of the search.
Steps to Search Posts
- Create an instance of
SearchPostRequestwith the required parameters:searchfor the search term,pagefor pagination,pageSizefor the number of results per page, andsearchTypefor the type of search. - Call the
searchPosts()function using the instance of theSearchPostRequestclass. - Use the SearchPostResponse as per your requirement.
// Create an instance of SearchPostRequest
final SearchPostRequest request = (SearchPostRequestBuilder()
..page(1)
..pageSize(10)
..search('YOUR_SEARCH_TERM')
..searchType('SEARCH_TYPE'))
.build();
// Get the response from calling the function
final SearchPostResponse searchPostResponse = await lmFeedClient.searchPosts(request);
// Process the response, as per requirement
if (searchPostResponse.success) {
// your function to handle successful search
handleSearchSuccess(searchPostResponse.posts);
} else {
// your function to handle error message
handleSearchError(searchPostResponse.errorMessage);
}
Additional Features
Search Types
The searchType parameter in the SearchPostRequest class allows you to specify the type of search to perform. The available search types are:
text: Search based on the text content of the post.heading: Search based on the heading of the post.
Models
SearchPostRequest
| Variable | Type | Description | Optional |
|---|---|---|---|
| page | int? | The page number to fetch. | ✔ |
| pageSize | int? | The number of items per page. | ✔ |
| search | String? | The search term used to query posts. | ✔ |
| searchType | String? | The type of search to perform (e.g., text) | ✔ |
SearchPostResponse
| Variable | Type | Description | Optional |
|---|---|---|---|
| success | bool | API success status | |
| errorMessage | String? | Error message in case of failure | ✔ |
| posts | List<Post> | List of posts returned by the search | ✔ |
| repostedPosts | Map<String, Post> | Map of reposted post IDs to Post entities | ✔ |
| topics | Map<String, Topic> | Map of topic IDs to Topic entities | ✔ |
| users | Map<String, User> | Map of user UUIDs to User entities | ✔ |
| widgets | Map<String, WidgetModel> | Map of widget IDs to WidgetModel entities | ✔ |
| userTopics | Map<String, List<String>> | Map of user-specific topics | ✔ |