1"""Data models for advanced search functionality.

2

3 This module provides data models for search filters, facets, and results

4 used throughout the advanced search system.

5"""

6

7 from __future__ import annotations

8

9 from dataclasses import dataclass, field

10 from typing import TYPE_CHECKING, Any

11

12 if TYPE_CHECKING:

13 from datetime import datetime

14

15

16@dataclass

17 class SearchFilter:

18 """Represents a search filter criterion."""

19

20 field: str

21 operator: str # 'eq', 'ne', 'in', 'not_in', 'contains', 'starts_with', 'ends_with', 'range'

22 value: str | list[str] | tuple[Any, Any]

23 negate: bool = False

24

25

26@dataclass

27 class SearchFacet:

28 """Represents a search facet with possible values."""

29

30 name: str

31 values: list[tuple[str, int]] # (value, count) tuples

32 facet_type: str = "terms" # 'terms', 'range', 'date'

33

34

35@dataclass

36 class SearchResult:

37 """Enhanced search result with metadata."""

38

39 content_id: str

40 content_type: str

41 title: str

42 content: str

43 score: float

44 project: str | None = None

45 timestamp: datetime | None = None

46 metadata: dict[str, Any] = field(default_factory=dict)

47 highlights: list[str] = field(default_factory=list)

48 facets: dict[str, Any] = field(default_factory=dict)