Skip to main content

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​

  1. Create an instance of SearchPostRequest with the required parameters: search for the search term, page for pagination, pageSize for the number of results per page, and searchType for the type of search.
  2. Call the searchPosts() function using the instance of the SearchPostRequest class.
  3. 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​

VariableTypeDescriptionOptional
pageint?The page number to fetch.✔
pageSizeint?The number of items per page.✔
searchString?The search term used to query posts.✔
searchTypeString?The type of search to perform (e.g., text)✔

SearchPostResponse​

VariableTypeDescriptionOptional
successboolAPI success status
errorMessageString?Error message in case of failure✔
postsList<Post>List of posts returned by the search✔
repostedPostsMap<String, Post>Map of reposted post IDs to Post entities✔
topicsMap<String, Topic>Map of topic IDs to Topic entities✔
usersMap<String, User>Map of user UUIDs to User entities✔
widgetsMap<String, WidgetModel>Map of widget IDs to WidgetModel entities✔
userTopicsMap<String, List<String>>Map of user-specific topics✔