> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-auto-generate-llmstxt.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Posts

> Search posts semantically or by hashtag with the SDK post repository APIs.

Use post search when users need to find content across accessible post targets. The SDK exposes semantic post search for natural-language queries and hashtag post search for explicit hashtag matching on TypeScript, iOS, and Android.

<Note>
  The current public Flutter SDK source reviewed for this page does not expose semantic post search or hashtag post search repository methods.
</Note>

## Parameters

| Parameter            | TypeScript               | iOS                      | Android                   |
| -------------------- | ------------------------ | ------------------------ | ------------------------- |
| Query                | `query`                  | `query`                  | `query`                   |
| Target               | `targetType`, `targetId` | `targetType`, `targetId` | `targetType`, `targetId`  |
| Data types           | `dataTypes`              | `dataTypes`              | `postTypes`               |
| Parent-only matching | `matchingOnlyParentPost` | `matchingOnlyParentPost` | `matchingOnlyParentPosts` |
| Mixed structure      | `includeMixedStructure`  | `includeMixedStructure`  | `includeMixedStructure`   |

## Semantic Search Posts

Use semantic search when a natural-language query should match accessible posts for the requested target and data types.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { PostRepository } from '@amityco/ts-sdk';

  let loadNextPage: (() => void) | undefined;
  let canLoadMore = false;

  const unsubscribe = PostRepository.semanticSearchPosts(
    {
      query: 'healthy breakfast ideas',
      targetType: 'community',
      targetId: communityId,
      dataTypes: ['text', 'image'],
      matchingOnlyParentPost: true,
      includeMixedStructure: false,
      limit: 20,
    },
    ({ data: posts, onNextPage, hasNextPage, loading, error }) => {
      if (loading) return;
      if (error) {
        handleError(error);
        return;
      }

      renderResults(posts);
      loadNextPage = onNextPage;
      canLoadMore = hasNextPage;
    },
  );

  function loadMorePosts() {
    if (canLoadMore) {
      loadNextPage?.();
    }
  }

  unsubscribe();
  ```

  ```swift iOS theme={null}
  let options = AmityPostSemanticSearchOptions(
      query: "healthy breakfast ideas",
      targetId: communityId,
      targetType: .community,
      dataTypes: ["text", "image"],
      matchingOnlyParentPost: true,
      includeMixedStructure: false
  )

  token = postRepository
      .semanticSearchPosts(options: options)
      .observe { collection, error in
          if let error {
              handleError(error)
              return
          }

          showSuccessMessage(collection.snapshots.count)
      }
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newPostRepository()
      .semanticSearchPosts(
          query = "healthy breakfast ideas",
          targetType = AmityPost.TargetType.COMMUNITY,
          targetId = communityId,
          postTypes = listOf(AmityPost.DataType.TEXT, AmityPost.DataType.IMAGE),
          matchingOnlyParentPosts = true,
          includeMixedStructure = false
      )
      .subscribe(
          { pagingData: PagingData<AmityPost> -> showSuccessMessage(pagingData) },
          { error -> handleGeneralError(error) }
      )
  ```
</CodeGroup>

## Hashtag Search Filters

| Parameter            | TypeScript               | iOS                      | Android                            |
| -------------------- | ------------------------ | ------------------------ | ---------------------------------- |
| Hashtags             | `hashtags`               | `hashtags`               | `hashtags`                         |
| Target               | `targetType`             | Not exposed              | Not exposed                        |
| Data types           | `dataTypes`              | `dataTypes`              | `dataTypes`                        |
| Parent-only matching | `matchingOnlyParentPost` | `matchingOnlyParentPost` | Not exposed in the snippet surface |
| Mixed structure      | `includeMixedStructure`  | `includeMixedStructure`  | `includeMixedStructure`            |

## Hashtag Search Posts

Hashtag search finds posts that contain one or more hashtags. Pass hashtag names without the `#` prefix.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { PostRepository } from '@amityco/ts-sdk';

  let loadNextHashtagPage: (() => void) | undefined;
  let canLoadMoreHashtagPosts = false;

  const unsubscribe = PostRepository.searchPostsByHashtag(
    {
      targetType: 'community',
      hashtags: ['recipe'],
      dataTypes: ['image'],
      matchingOnlyParentPost: true,
      includeMixedStructure: false,
      limit: 20,
    },
    ({ data: posts, onNextPage, hasNextPage, loading, error }) => {
      if (loading) return;
      if (error) {
        handleError(error);
        return;
      }

      renderResults(posts);
      loadNextHashtagPage = onNextPage;
      canLoadMoreHashtagPosts = hasNextPage;
    },
  );

  function loadMoreHashtagPosts() {
    if (canLoadMoreHashtagPosts) {
      loadNextHashtagPage?.();
    }
  }

  unsubscribe();
  ```

  ```swift iOS theme={null}
  let options = AmityPostHashtagSearchOptions(
      hashtags: ["recipe"],
      dataTypes: ["image"],
      matchingOnlyParentPost: true,
      includeMixedStructure: false
  )

  token = postRepository
      .searchPostsByHashtag(options: options)
      .observe { collection, error in
          if let error {
              handleError(error)
              return
          }

          showSuccessMessage(collection.snapshots.count)
      }
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newPostRepository()
      .searchPostsByHashtag(
          hashtags = listOf("recipe"),
          dataTypes = listOf(AmityPost.DataType.IMAGE),
          includeMixedStructure = false
      )
      .subscribe(
          { pagingData: PagingData<AmityPost> -> showSuccessMessage(pagingData) },
          { error -> handleGeneralError(error) }
      )
  ```
</CodeGroup>

## Notes

* For semantic post search, provide `targetType` and `targetId` together when scoping search to one user or community target.
* Use parent-only matching when the UI should show top-level posts instead of child posts from mixed or threaded structures.
* For hashtag search, TypeScript requires a `targetType`; iOS and Android expose hashtag search without a target type parameter.
* Search results are permission-aware from the backend response, but your UI should still handle empty results and authorization errors.

## Related Topics

<CardGroup cols={3}>
  <Card title="Query Posts" href="../../content-management/posts/retrieval/query-posts" icon="newspaper">
    Query live post collections by target, type, review state, tags, and pagination options.
  </Card>

  <Card title="Feeds and Timelines" href="../feed/overview" icon="rss">
    Query feed-style post collections for global, custom-ranking, user, and community feeds.
  </Card>

  <Card title="Search Overview" href="./overview" icon="sparkles">
    Review SDK search surfaces for community and post discovery.
  </Card>
</CardGroup>
