Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
PostgreSQL Full-Text Search

PostgreSQL Full-Text Search

Implement full-text search in Google Antigravity with PostgreSQL tsvector and ranking.

searchpostgresqlfull-textperformance
by antigravity-team
⭐0Stars
.antigravity
# PostgreSQL Full-Text Search for Google Antigravity

Implement powerful search using PostgreSQL full-text search.

## Search Setup

```sql
-- Add search vector column
ALTER TABLE public.posts ADD COLUMN IF NOT EXISTS search_vector tsvector;

-- Create GIN index
CREATE INDEX IF NOT EXISTS idx_posts_search ON public.posts USING gin(search_vector);

-- Update function
CREATE OR REPLACE FUNCTION update_posts_search_vector() RETURNS TRIGGER AS $$
BEGIN
    NEW.search_vector = 
        setweight(to_tsvector('english', COALESCE(NEW.title, '')), 'A') ||
        setweight(to_tsvector('english', COALESCE(NEW.content, '')), 'B');
    RETURN NEW;
END; $$ LANGUAGE plpgsql;

-- Trigger
CREATE TRIGGER posts_search_update BEFORE INSERT OR UPDATE ON public.posts FOR EACH ROW EXECUTE FUNCTION update_posts_search_vector();

-- Search function
CREATE OR REPLACE FUNCTION search_posts(query TEXT, limit_count INT DEFAULT 20)
RETURNS TABLE (id UUID, title TEXT, content TEXT, rank REAL) AS $$
BEGIN
    RETURN QUERY SELECT p.id, p.title, p.content, ts_rank(p.search_vector, plainto_tsquery('english', query)) AS rank
    FROM public.posts p WHERE p.search_vector @@ plainto_tsquery('english', query) ORDER BY rank DESC LIMIT limit_count;
END; $$ LANGUAGE plpgsql;
```

## Search API

```typescript
// app/api/search/route.ts
import { NextRequest, NextResponse } from "next/server";
import { createClient } from "@/lib/supabase/server";

export async function GET(request: NextRequest) {
    const query = request.nextUrl.searchParams.get("q");
    const limit = parseInt(request.nextUrl.searchParams.get("limit") || "20");

    if (!query || query.length < 2) return NextResponse.json({ results: [] });

    const supabase = createClient();
    const { data: results, error } = await supabase.rpc("search_posts", { query, limit_count: limit });

    if (error) return NextResponse.json({ error: error.message }, { status: 500 });
    return NextResponse.json({ results });
}
```

## Search Component

```typescript
// components/SearchInput.tsx
"use client";

import { useState, useEffect, useRef, useCallback } from "react";
import debounce from "lodash.debounce";
import Link from "next/link";

export function SearchInput() {
    const [query, setQuery] = useState("");
    const [results, setResults] = useState<any[]>([]);
    const [loading, setLoading] = useState(false);
    const [open, setOpen] = useState(false);
    const ref = useRef<HTMLDivElement>(null);

    const search = useCallback(debounce(async (q: string) => {
        if (q.length < 2) { setResults([]); return; }
        setLoading(true);
        try {
            const response = await fetch(`/api/search?q=${encodeURIComponent(q)}`);
            const { results } = await response.json();
            setResults(results);
            setOpen(true);
        } catch (e) {
            console.error(e);
        } finally {
            setLoading(false);
        }
    }, 300), []);

    useEffect(() => { search(query); }, [query, search]);

    useEffect(() => {
        const handleClick = (e: MouseEvent) => {
            if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
        };
        document.addEventListener("mousedown", handleClick);
        return () => document.removeEventListener("mousedown", handleClick);
    }, []);

    return (
        <div ref={ref} className="search-container">
            <input type="search" value={query} onChange={(e) => setQuery(e.target.value)} onFocus={() => results.length > 0 && setOpen(true)} placeholder="Search..." />
            {loading && <span>Searching...</span>}
            {open && results.length > 0 && (
                <ul className="search-results">
                    {results.map((r) => (
                        <li key={r.id}>
                            <Link href={`/posts/${r.id}`} onClick={() => setOpen(false)}>
                                <strong>{r.title}</strong>
                                <p>{r.content?.substring(0, 100)}...</p>
                            </Link>
                        </li>
                    ))}
                </ul>
            )}
        </div>
    );
}
```

## Search with Filters

```typescript
// lib/search.ts
import { createClient } from "@/lib/supabase/server";

export async function searchWithFilters(query: string, filters: { category?: string; dateFrom?: string }, page = 1, limit = 20) {
    const supabase = createClient();
    let builder = supabase.from("posts").select("*", { count: "exact" }).textSearch("search_vector", query, { type: "websearch" });

    if (filters.category) builder = builder.eq("category", filters.category);
    if (filters.dateFrom) builder = builder.gte("created_at", filters.dateFrom);

    const { data, count, error } = await builder.range((page - 1) * limit, page * limit - 1).order("created_at", { ascending: false });
    return { results: data, total: count, error };
}
```

## Highlight Terms

```typescript
// utils/highlight.ts
export function highlightTerms(text: string, query: string): string {
    if (!query.trim()) return text;
    const terms = query.split(/\s+/).filter(Boolean);
    let result = text;
    terms.forEach((term) => {
        result = result.replace(new RegExp(`(${term})`, "gi"), "<mark>$1</mark>");
    });
    return result;
}
```

## Best Practices

1. **Indexing**: Create GIN indexes for search
2. **Debouncing**: Debounce search input
3. **Highlighting**: Highlight matches
4. **Pagination**: Paginate large results
5. **Analytics**: Track search queries

When to Use This Prompt

This search prompt is ideal for developers working on:

  • search applications requiring modern best practices and optimal performance
  • Projects that need production-ready search code with proper error handling
  • Teams looking to standardize their search development workflow
  • Developers wanting to learn industry-standard search patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their search implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the search code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this search prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For search projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...