> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# Search & Discovery

> Add full-text post search, community search, trending communities, content recommendations, and category browsing.

<Info>**SDK v7.x** · Last verified March 2026 · iOS · Android · Web · Flutter</Info>

<Accordion title="Speed run — just the code" icon="forward">
  ```typescript theme={null}
  // 1. Semantic search for communities
  CommunityRepository.semanticSearchCommunities(
    { query: 'gaming', limit: 10 },
    ({ data }) => { renderResults(data); }
  );

  // 2a. Semantic (AI) search for posts
  PostRepository.semanticSearchPosts(
    { query: 'healthy recipes', dataTypes: ['text', 'image'], limit: 20 },
    ({ data }) => { renderResults(data); }
  );

  // 2b. Hashtag/keyword search for posts
  PostRepository.searchPostsByHashtag(
    { query: 'recipe', limit: 20 },
    ({ data }) => { renderResults(data); }
  );

  // 3. Get trending communities
  CommunityRepository.getTrendingCommunities(
    { limit: 10 },
    ({ data }) => { renderTrending(data); }
  );
  ```

  Full walkthrough below ↓
</Accordion>

<Tip>
  **Platform note** — code samples below use TypeScript. Every method has an equivalent in the iOS (Swift), Android (Kotlin), and Flutter (Dart) SDKs — see the linked SDK reference in each step.
</Tip>

Discovery turns a closed social app into a growing platform. This guide walks through implementing full-text search for posts and communities, surfacing trending content, and building a category-based browsing experience.

```mermaid theme={null}
graph TD
    A[User wants to find content] --> B{Discovery method}
    B -->|Search bar| C[Intelligent Search]
    B -->|Explore tab| D[Trending Communities]
    B -->|Category browse| E[Community Categories]
    B -->|Algorithm-driven| F[Recommended Communities]
    C --> G[Search posts]
    C --> H[Search communities]
    D & E & F --> I[Community cards]
    G & H & I --> J[User navigates to content]

    classDef action fill:#e1f5fe,stroke:#0288d1,color:#01579b
    classDef decision fill:#fff8e1,stroke:#f9a825,color:#f57f17
    classDef process fill:#f3e5f5,stroke:#7b1fa2,color:#4a148c
    classDef outcome fill:#e8f5e9,stroke:#388e3c,color:#1b5e20

    class A action
    class B decision
    class C,D,E,F,G,H,I process
    class J outcome
```

<Info>
  **Prerequisites**: SDK installed and authenticated. Note: only public communities appear in search results — private communities are excluded.
</Info>

<Note>
  **After completing this guide you'll have:**

  * Full-text post search integrated into your app's search bar
  * Community search with trending and recommended community lists
  * User-facing category browsing connected to community filtering
</Note>

***

## Quick Start: Search Communities

Community search is the primary discovery surface — query by name with optional membership and category filters:

```typescript TypeScript theme={null}
import { CommunityRepository } from '@amityco/ts-sdk';

const unsubscriber = CommunityRepository.semanticSearchCommunities(
  {
    query: 'gaming',
    communityMembershipStatus: AmityCommunityMemberStatusFilter.ALL,
  },
  ({ data: communities, onNextPage, hasNextPage, loading }) => {
    if (communities) { /* render community search results */ }
  },
);
```

Full reference → [Intelligent Search: Communities](/social-plus-sdk/social/discovery-engagement/search/intelligent-search-community)

***

## Step-by-Step Implementation

<Steps>
  <Step title="Search communities">
    Search communities by name with optional filters: membership status (`all`, `member`, `notMember`), sort order, and category.

    ```typescript TypeScript theme={null}
    import { CommunityRepository } from '@amityco/ts-sdk';

    const unsubscriber = CommunityRepository.semanticSearchCommunities(
      { query: 'game', communityMembershipStatus: AmityCommunityMemberStatusFilter.ALL },
      ({ data: communities, onNextPage, hasNextPage, loading }) => {
        if (communities) { /* render community results */ }
      },
    );
    ```

    Full reference → [Intelligent Search: Communities](/social-plus-sdk/social/discovery-engagement/search/intelligent-search-community)
  </Step>

  <Step title="Get trending communities">
    Trending communities are ranked by recent activity (posts, members, engagement). Surface these on your explore page for new users.

    ```typescript TypeScript theme={null}
    import { CommunityRepository } from '@amityco/ts-sdk';

    const unsubscriber = CommunityRepository.getTrendingCommunities(
      { limit: 5 },
      ({ data: communities, loading }) => {
        if (communities) { /* render trending section */ }
      },
    );
    ```

    Full reference → [Trending & Recommended Communities](/social-plus-sdk/social/communities-spaces/discovery/trending-and-recommended-communities)
  </Step>

  <Step title="Get recommended communities">
    Recommended communities are personalized for the current user based on their activity and interests. Returns up to 15 communities.

    ```typescript TypeScript theme={null}
    import { CommunityRepository } from '@amityco/ts-sdk';

    const unsubscriber = CommunityRepository.getRecommendedCommunities(
      { limit: 5, includeDiscoverablePrivateCommunity: true },
      ({ data: communities, loading }) => {
        if (communities) { /* render recommended section */ }
      },
    );
    ```

    Full reference → [Trending & Recommended Communities](/social-plus-sdk/social/communities-spaces/discovery/trending-and-recommended-communities)
  </Step>

  <Step title="Browse communities by category">
    Organize communities into browsable categories. Query all categories, then filter communities by a selected category.

    ```typescript TypeScript theme={null}
    import { CategoryRepository } from '@amityco/ts-sdk';

    const unsubscriber = CategoryRepository.getCategories(
      {},
      ({ data: categories, loading }) => {
        if (categories) { /* render category filter pills */ }
      },
    );
    ```

    Full reference → [Community Categories](/social-plus-sdk/social/communities-spaces/organization/community-categories) · [Query Communities](/social-plus-sdk/social/communities-spaces/discovery/query-communities)
  </Step>

  <Step title="Search posts">
    Two complementary search methods are available for posts:

    * **Semantic search** (`PostRepository.semanticSearchPosts`) — AI-powered natural-language search. Best for open-ended queries like "healthy breakfast ideas".
    * **Hashtag/keyword search** (`PostRepository.searchPostsByHashtag`) — exact hashtag and keyword matching. Best for tag-driven browsing like `#recipe`.

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

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

        renderResults(posts);

        if (hasNextPage) {
          onNextPage?.();
        }
      },
    );

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

        renderResults(posts);
      },
    );

    semanticSearchUnsubscriber();
    hashtagSearchUnsubscriber();
    ```

    Full reference → [Intelligent Search: Posts](/social-plus-sdk/social/discovery-engagement/search/intelligent-search-post)
  </Step>
</Steps>

***

## Connect to Moderation & Analytics

<AccordionGroup>
  <Accordion title="Analytics: search usage" icon="chart-bar">
    Track search query volume and discovery patterns in **Admin Console → Analytics Dashboard → Social Insights** to understand what users are looking for and which communities are growing.

    → [Admin Console: Analytics](/analytics-and-moderation/console/analytics/)
  </Accordion>

  <Accordion title="Admin: category management" icon="tag">
    Create and manage community categories in the Admin Console. Categories appear in the community creation flow and in the discovery browse view.

    → [Admin Console: Product Management](/analytics-and-moderation/console/product-management/overview)
  </Accordion>
</AccordionGroup>

***

## Common Mistakes

<Warning>
  **Firing a search API call on every keystroke** — This creates excessive API calls and flickers results. Debounce the input by 300–500ms before searching.

  ```typescript theme={null}
  // ❌ Bad — search on every key
  <input onChange={(e) => search(e.target.value)} />

  // ✅ Good — debounce
  const debouncedSearch = useMemo(
    () => debounce((q) => search(q), 400), []
  );
  <input onChange={(e) => debouncedSearch(e.target.value)} />
  ```
</Warning>

<Warning>
  **Not handling empty search results** — "No results found" is not enough. Suggest alternative queries, show trending content, or recommend popular communities to keep users engaged.
</Warning>

<Warning>
  **Searching without a minimum query length** — Single-character searches return too many results and waste resources. Require at least 2–3 characters before triggering a search.
</Warning>

## Best Practices

<AccordionGroup>
  <Accordion title="Search UX" icon="magnifying-glass">
    * Add a 300ms debounce to search input before firing the query — prevents excessive API calls while the user types
    * Show suggested/recent searches before the user starts typing
    * Display skeleton placeholders while results load
    * Clearly differentiate post results from community results with distinct card styles
    * Show a "No results" empty state with suggestions if the query returns 0 results
  </Accordion>

  <Accordion title="Explore/Discover UX" icon="compass">
    * Show trending communities prominently for logged-in users with no following history
    * Once a user has joined 5+ communities, replace trending with personalized recommendations
    * Use horizontal scrolling category pills for browsing — they take less vertical space than a list
    * Cache trending and recommended results for 5-10 minutes — they don't need to be real-time
  </Accordion>

  <Accordion title="Performance" icon="gauge">
    * Use `searchPosts()` Live Collection — this handles debounced re-querying automatically on most platforms
    * Limit search result sets to 20-30 items; use pagination for deeper results
    * Pre-load categories at app launch and cache locally — they change infrequently
  </Accordion>
</AccordionGroup>

***

<Tip>
  **Dive deeper**: [Discovery & Engagement API Reference](/social-plus-sdk/social/discovery-engagement/overview) has full parameter tables, method signatures, and platform-specific details for every API used in this guide.
</Tip>

## Next Steps

<Card title="Your next step → User Search & People Discovery" icon="arrow-right" href="/use-cases/social/user-search-and-people-discovery">
  Content search is working — now let users find each other with people search and suggestions.
</Card>

Or explore related guides:

<CardGroup cols={3}>
  <Card title="Community Platform" href="/use-cases/social/community-platform" icon="users">
    Build the communities that discovery surfaces
  </Card>

  <Card title="Build a Social Feed" href="/use-cases/social/build-a-social-feed" icon="rectangle-list">
    Show content from discovered communities in a feed
  </Card>

  <Card title="Notifications & Engagement" href="/use-cases/social/notifications-and-engagement" icon="bell">
    Notify users about trending content they'd be interested in
  </Card>
</CardGroup>
