2026-07-18 11:21:51 +02:00
|
|
|
import { apiClient } from './client';
|
|
|
|
|
|
|
|
|
|
export interface SearchResult {
|
2026-07-23 17:17:32 +02:00
|
|
|
type: 'contact' | 'mail' | 'file' | 'event';
|
2026-07-18 11:21:51 +02:00
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
url: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SearchResponse {
|
|
|
|
|
results: SearchResult[];
|
|
|
|
|
facets?: Record<string, Array<{ value: string; count: number }>>;
|
|
|
|
|
summary?: string;
|
|
|
|
|
suggestions?: string[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function search(query: string, entityTypes?: string[], limit = 20): Promise<SearchResponse> {
|
|
|
|
|
const r = await apiClient.post('/api/v1/search', {
|
|
|
|
|
query,
|
|
|
|
|
entity_types: entityTypes,
|
|
|
|
|
limit,
|
|
|
|
|
});
|
|
|
|
|
return r.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function searchSuggest(q: string): Promise<string[]> {
|
|
|
|
|
const r = await apiClient.get('/api/v1/search/suggest', { params: { q } });
|
|
|
|
|
return r.data.suggestions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function searchSimilar(entityType: string, entityId: string): Promise<SearchResult[]> {
|
|
|
|
|
const r = await apiClient.post('/api/v1/search/similar', {
|
|
|
|
|
entity_type: entityType,
|
|
|
|
|
entity_id: entityId,
|
|
|
|
|
});
|
|
|
|
|
return r.data.similar;
|
|
|
|
|
}
|