managarten/services/mana-search/src/search/search.controller.ts
Claude bd72b4d6d5
feat(search): implement mana-search microservice
Central search microservice for all ManaCore apps featuring:

- NestJS API on port 3021
- SearXNG meta-search engine integration (40+ search engines)
- Redis caching layer for search results and extracted content
- Content extraction with markdown conversion
- Prometheus metrics for monitoring

API Endpoints:
- POST /api/v1/search - Web search with categories/engines
- POST /api/v1/extract - Content extraction from URLs
- POST /api/v1/extract/bulk - Bulk extraction
- GET /health - Health check
- GET /metrics - Prometheus metrics

Search categories: general, news, science, it, images, videos
Supported engines: Google, Bing, DuckDuckGo, Wikipedia, arXiv,
GitHub, StackOverflow, and many more.

https://claude.ai/code/session_01Rk3YVJCU3nM8uvVPghRz6r
2026-01-28 20:41:59 +00:00

64 lines
1.6 KiB
TypeScript

import { Controller, Post, Get, Body, Delete, Logger } from '@nestjs/common';
import { SearchService } from './search.service';
import { CacheService } from '../cache/cache.service';
import { SearchRequestDto } from './dto/search-request.dto';
import { SearchResponse } from './dto/search-response.dto';
@Controller('search')
export class SearchController {
private readonly logger = new Logger(SearchController.name);
constructor(
private readonly searchService: SearchService,
private readonly cacheService: CacheService,
) {}
/**
* Perform a web search
* POST /api/v1/search
*/
@Post()
async search(@Body() request: SearchRequestDto): Promise<SearchResponse> {
this.logger.log(`Search request: "${request.query}"`);
return this.searchService.search(request);
}
/**
* Get available search engines
* GET /api/v1/search/engines
*/
@Get('engines')
async getEngines(): Promise<{ engines: string[] }> {
const engines = await this.searchService.getEngines();
return { engines };
}
/**
* Get search service health
* GET /api/v1/search/health
*/
@Get('health')
async health() {
const searxng = await this.searchService.healthCheck();
const cache = await this.cacheService.healthCheck();
const cacheStats = this.cacheService.getStats();
return {
searxng,
cache: {
...cache,
stats: cacheStats,
},
};
}
/**
* Clear search cache
* DELETE /api/v1/search/cache
*/
@Delete('cache')
async clearCache(): Promise<{ cleared: boolean; keysRemoved: number }> {
const keysRemoved = await this.cacheService.clear();
return { cleared: true, keysRemoved };
}
}