Source: Router/SearchData.js

/**
 * SearchData Router
 * 
 * This router provides search endpoints for entities in the CommTool system.
 * Supports both fulltext search and semantic search using AI embeddings.
 * 
 * Routes:
 * - GET / - Search all entity types
 * - GET /:type - Search specific entity type
 * - GET /embedding - Semantic vector similarity search
 * 
 * @module SearchDataRouter
 */

// @ts-check
/**
 * @import {ExpressRequestAuthorized, ExpressResponse} from '../types.js'
 */

import express from 'express';
import * as searchController from './searchData/controller.js';

const api = express();

// *************** Search Routes ***************

/**
 * @swagger
 * /searchData:
 *   get:
 *     summary: Search all entity types
 *     description: Comprehensive fulltext search across multiple entity types
 *     parameters:
 *       - in: query
 *         name: search
 *         required: true
 *         schema:
 *           type: string
 *         description: Search term
 *       - in: query
 *         name: types
 *         schema:
 *           type: string
 *         description: Entity types filter (JSON array or single value)
 *       - in: query
 *         name: gender
 *         schema:
 *           type: string
 *         description: Gender filter
 *       - in: query
 *         name: stage
 *         schema:
 *           type: string
 *         description: Stage filter
 *       - in: query
 *         name: hierarchie
 *         schema:
 *           type: string
 *         description: Hierarchy filter
 *       - in: query
 *         name: changeable
 *         schema:
 *           type: boolean
 *         description: Include only changeable entities
 *       - in: query
 *         name: Timestamp
 *         schema:
 *           type: integer
 *         description: Historical query timestamp
 *     responses:
 *       200:
 *         description: Search results
 */
// @ts-expect-error - Custom types don't match Express RequestHandler signature
api.get('/', searchController.searchAll);

/**
 * @swagger
 * /searchData/{type}:
 *   get:
 *     summary: Search specific entity type
 *     description: Type-specific fulltext search with optimized queries
 *     parameters:
 *       - in: path
 *         name: type
 *         required: true
 *         schema:
 *           type: string
 *           enum: [member, person, extern, group, list, dlist, email]
 *         description: Entity type to search
 *       - in: query
 *         name: search
 *         required: true
 *         schema:
 *           type: string
 *         description: Search term
 *     responses:
 *       200:
 *         description: Type-specific search results
 */
// @ts-expect-error - Custom types don't match Express RequestHandler signature
api.get('/:type', searchController.searchByType);

/**
 * @swagger
 * /searchData/embedding:
 *   get:
 *     summary: Semantic search using AI embeddings
 *     description: |
 *       Search for entities using vector similarity search.
 *       Finds semantically similar content even if exact words don't match.
 *     parameters:
 *       - in: query
 *         name: search
 *         required: true
 *         schema:
 *           type: string
 *         description: Search query text
 *       - in: query
 *         name: type
 *         schema:
 *           type: string
 *         description: Filter by entity type (Person, Document, etc.)
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 10
 *         description: Maximum number of results
 *       - in: query
 *         name: threshold
 *         schema:
 *           type: number
 *           default: 0.7
 *         description: Minimum similarity threshold (0-1)
 *     responses:
 *       200:
 *         description: Search results with similarity scores
 *         content:
 *           application/json:
 *             schema:
 *               type: array
 *               items:
 *                 type: object
 *                 properties:
 *                   title:
 *                     type: string
 *                   value:
 *                     type: string
 *                   key:
 *                     type: string
 *                   type:
 *                     type: string
 *                   similarity:
 *                     type: number
 *                   distance:
 *                     type: number
 */
// @ts-expect-error - Custom types don't match Express RequestHandler signature
api.get('/embedding', searchController.searchEmbedding);

export default api;