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

# Busca unificada multi-coleção (v2)

> Executa busca em múltiplas coleções configuradas (services, courses, jobs). Suporta keyword, semantic e hybrid search. Retorna documentos com estrutura unificada incluindo campo 'collection' e 'type'.



## OpenAPI

````yaml https://raw.githubusercontent.com/prefeitura-rio/app-busca-search/refs/heads/main/docs/openapi-v3.json get /api/v2/search
openapi: 3.0.0
info:
  description: >-
    API para busca textual e vetorial usando Typesense e embeddings gerados via
    Google Gemini
  title: Mecanismo de Busca API
  termsOfService: http://swagger.io/terms/
  contact:
    name: Prefeitura do Rio de Janeiro
    url: https://prefeitura.rio
    email: contato@prefeitura.rio
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: '1.0'
servers:
  - url: https://services.pref.rio/app-busca-search
    description: Production server
  - url: https://services.staging.app.dados.rio/app-busca-search
    description: Staging server
security: []
paths:
  /api/v2/search:
    get:
      tags:
        - search-v2
      summary: Busca unificada multi-coleção (v2)
      description: >-
        Executa busca em múltiplas coleções configuradas (services, courses,
        jobs). Suporta keyword, semantic e hybrid search. Retorna documentos com
        estrutura unificada incluindo campo 'collection' e 'type'.
      parameters:
        - description: Texto da busca
          name: q
          in: query
          required: true
          schema:
            type: string
        - description: 'Tipo de busca: keyword, semantic, hybrid'
          name: type
          in: query
          required: true
          schema:
            type: string
        - description: 'Número da página (mínimo: 1)'
          name: page
          in: query
          schema:
            type: integer
            default: 1
        - description: 'Resultados por página (máximo: 100)'
          name: per_page
          in: query
          schema:
            type: integer
            default: 10
        - description: >-
            Incluir documentos inativos (aplica-se apenas a coleções com filtro
            de status)
          name: include_inactive
          in: query
          schema:
            type: boolean
            default: false
        - description: >-
            Alpha para busca hybrid (0-1). Alpha=0.3 significa 30% texto + 70%
            vetor.
          name: alpha
          in: query
          schema:
            type: number
            default: 0.3
        - description: Score mínimo para busca keyword (0-1, filtra text_match normalizado)
          name: threshold_keyword
          in: query
          schema:
            type: number
        - description: >-
            Score mínimo para busca semantic (0-1, filtra por similaridade
            vetorial)
          name: threshold_semantic
          in: query
          schema:
            type: number
        - description: Score mínimo para busca hybrid (0-1, filtra score híbrido)
          name: threshold_hybrid
          in: query
          schema:
            type: number
        - description: >-
            Override dos campos de busca (comma-separated). Ex:
            titulo,descricao,conteudo
          name: search_fields
          in: query
          schema:
            type: string
        - description: 'Override dos pesos de busca (comma-separated). Ex: 4,2,1'
          name: search_weights
          in: query
          schema:
            type: string
        - description: >-
            Filtrar busca por collections específicas (comma-separated). Ex:
            prefrio_services_base,hub_search. Se não especificado, busca em
            todas.
          name: collections
          in: query
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.UnifiedSearchResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  type: string
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  type: string
      security:
        - bearerAuth: []
components:
  schemas:
    models.UnifiedSearchResponse:
      type: object
      properties:
        collections:
          description: Which collections were searched
          type: array
          items:
            type: string
        filtered_count:
          description: Após aplicar thresholds
          type: integer
        metadata:
          description: Para AI search
          type: object
          additionalProperties: true
        page:
          type: integer
        per_page:
          type: integer
        results:
          type: array
          items:
            $ref: '#/components/schemas/models.UnifiedDocument'
        search_type:
          $ref: '#/components/schemas/models.SearchType'
        total_count:
          description: Total original do Typesense (across all collections)
          type: integer
    models.UnifiedDocument:
      type: object
      properties:
        collection:
          description: Which collection this document belongs to
          type: string
        data:
          description: Raw document data from Typesense
          type: object
          additionalProperties: true
        id:
          type: string
        score_info:
          $ref: '#/components/schemas/models.ScoreInfo'
        type:
          description: Document type from collection config (service, course, job, etc.)
          type: string
    models.SearchType:
      type: string
      enum:
        - keyword
        - semantic
        - hybrid
        - ai
      x-enum-varnames:
        - SearchTypeKeyword
        - SearchTypeSemantic
        - SearchTypeHybrid
        - SearchTypeAI
    models.ScoreInfo:
      type: object
      properties:
        final_score:
          description: Score final após aplicar recency boost
          type: number
        hybrid_score:
          description: Score híbrido combinado 0-1
          type: number
        passed_threshold:
          description: Se passou no threshold
          type: boolean
        recency_factor:
          description: Fator de recência aplicado (1.0 = recente, decai com o tempo)
          type: number
        text_match_normalized:
          description: Score normalizado 0-1 do text_match
          type: number
        threshold_applied:
          description: 'Tipo de threshold aplicado: "keyword", "semantic", "hybrid", "none"'
          type: string
        threshold_value:
          description: Valor do threshold aplicado
          type: number
        vector_similarity:
          description: Similaridade vetorial 0-1 (1 = idêntico)
          type: number
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````