Skip to content

Commit 80509e8

Browse files
committed
removal of search segmenter
1 parent 998e6e5 commit 80509e8

5 files changed

Lines changed: 3 additions & 254 deletions

File tree

background_tasks.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

docs/api-documentation/README.md

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -55,99 +55,4 @@ Paginated list endpoints return:
5555

5656
## Active Route Inventory
5757

58-
Applications:
59-
60-
- `POST /v2/applications`
61-
62-
Languages:
63-
64-
- `GET /v2/languages`
65-
- `POST /v2/languages`
66-
67-
Categories:
68-
69-
- `GET /v2/categories`
70-
- `GET /v2/categories/{category_id}`
71-
- `POST /v2/categories`
72-
73-
Tags:
74-
75-
- `GET /v2/tags`
76-
- `POST /v2/tags`
77-
- `DELETE /v2/tags/{tag_id}`
78-
- `POST /v2/texts/{text_id}/tags/{tag_id}`
79-
- `DELETE /v2/texts/{text_id}/tags/{tag_id}`
80-
- `POST /v2/segments/{segment_id}/tags/{tag_id}`
81-
- `DELETE /v2/segments/{segment_id}/tags/{tag_id}`
82-
83-
Persons:
84-
85-
- `GET /v2/persons`
86-
- `GET /v2/persons/{person_id}`
87-
- `POST /v2/persons`
88-
- `PATCH /v2/persons/{person_id}`
89-
90-
Texts:
91-
92-
- `GET /v2/texts`
93-
- `GET /v2/texts/{text_id}`
94-
- `POST /v2/texts`
95-
- `PATCH /v2/texts/{text_id}`
96-
- `GET /v2/texts/{text_id}/editions`
97-
- `POST /v2/texts/{text_id}/editions`
98-
99-
Content Search:
100-
101-
- `GET /v2/content-search`
102-
103-
Editions:
104-
105-
- `GET /v2/editions/{edition_id}`
106-
- `GET /v2/editions/{edition_id}/content`
107-
- `PATCH /v2/editions/{edition_id}/content`
108-
- `DELETE /v2/editions/{edition_id}`
109-
- `GET /v2/editions/{edition_id}/related`
110-
- `GET /v2/editions/{edition_id}/segments/related`
111-
- `GET /v2/editions/{edition_id}/segmentations`
112-
- `POST /v2/editions/{edition_id}/segmentations`
113-
- `GET /v2/editions/{edition_id}/alignments`
114-
- `POST /v2/editions/{edition_id}/alignments`
115-
- `GET /v2/editions/{edition_id}/pagination`
116-
- `POST /v2/editions/{edition_id}/pagination`
117-
- `GET /v2/editions/{edition_id}/table-of-contents`
118-
- `POST /v2/editions/{edition_id}/table-of-contents`
119-
- `GET /v2/editions/{edition_id}/bibliographic`
120-
- `POST /v2/editions/{edition_id}/bibliographic`
121-
- `GET /v2/editions/{edition_id}/durchens`
122-
- `POST /v2/editions/{edition_id}/durchens`
123-
124-
Annotation objects by ID:
125-
126-
- `GET /v2/segmentations/{segmentation_id}`
127-
- `DELETE /v2/segmentations/{segmentation_id}`
128-
- `GET /v2/alignments/{alignment_id}`
129-
- `DELETE /v2/alignments/{alignment_id}`
130-
- `GET /v2/paginations/{pagination_id}`
131-
- `DELETE /v2/paginations/{pagination_id}`
132-
- `GET /v2/table-of-contents/{toc_id}`
133-
- `DELETE /v2/table-of-contents/{toc_id}`
134-
- `GET /v2/bibliographic/{bibliographic_id}`
135-
- `DELETE /v2/bibliographic/{bibliographic_id}`
136-
- `GET /v2/durchens/{durchen_id}`
137-
- `DELETE /v2/durchens/{durchen_id}`
138-
139-
Segments:
140-
141-
- `GET /v2/segments/{segment_id}`
142-
- `GET /v2/segments/{segment_id}/content`
143-
- `GET /v2/segments/{segment_id}/related`
144-
- `GET /v2/segments/search`
145-
146-
Operational:
147-
148-
- `GET /__/health`
149-
- `GET /openapi.json`
150-
- `GET /docs`
151-
- `GET /redoc`
152-
153-
There is currently no registered `/v2/relations/...` route and no registered `/v2/schema/openapi` route. Text relations are exposed on text records (`translation_of`, `commentary_of`, `translations`, `commentaries`) and related edition lookup is exposed through `GET /v2/editions/{edition_id}/related`.
58+
Use `GET /docs`

routers/segments.py

Lines changed: 2 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import logging
22
from typing import TYPE_CHECKING, Annotated
33

4-
import httpx
54
from fastapi import APIRouter, Depends, Path, Query, status
65

7-
from config import settings
86
from dependencies import OptionalAppHeader, get_api_key, get_db, get_storage
9-
from exceptions import DataNotFoundError, InvalidRequestError
7+
from exceptions import DataNotFoundError
108
from models.annotation import SegmentWithContextOutput
11-
from models.requests import DirectRelatedSegmentsQueryParams, SegmentsQueryParams
9+
from models.requests import DirectRelatedSegmentsQueryParams
1210
from models.responses import PaginatedResponse
13-
from models.search import SearchFilter, SearchResponse, SearchResult
1411

1512
if TYPE_CHECKING:
1613
from database import Database
@@ -102,101 +99,6 @@ async def untag_segment(
10299
await db.tag.untag_segment(segment_id, tag_id)
103100

104101

105-
@router.get(
106-
"/search",
107-
summary="Search segments",
108-
description="Search segments using the external search API.",
109-
)
110-
async def search_segments(
111-
query: Annotated[str, Query(description="Search query")],
112-
params: Annotated[SegmentsQueryParams, Query()],
113-
_api_key: Annotated[str, Depends(get_api_key)],
114-
db: Annotated[Database, Depends(get_db)],
115-
) -> SearchResponse:
116-
"""Search segments."""
117-
filter_obj = SearchFilter(title=params.title) if params.title else None
118-
119-
try:
120-
logger.info("Forwarding search request to %s/search", settings.search_api_url)
121-
122-
request_params = {
123-
"query": query,
124-
"search_type": params.search_type,
125-
"limit": params.limit,
126-
"return_text": params.return_text,
127-
}
128-
if filter_obj and filter_obj.title:
129-
request_params["title"] = filter_obj.title
130-
131-
async with httpx.AsyncClient(timeout=60) as client:
132-
response = await client.get(f"{settings.search_api_url}/search", params=request_params)
133-
response.raise_for_status()
134-
search_response_data = response.json()
135-
136-
except httpx.RequestError:
137-
logger.exception("Error calling search API")
138-
raise InvalidRequestError("Failed to call search API") from None
139-
140-
enriched_results = []
141-
142-
for result_item in search_response_data.get("results", []):
143-
segment_id = result_item.get("id")
144-
if not segment_id:
145-
enriched_results.append(
146-
SearchResult(
147-
id=result_item.get("id", ""),
148-
distance=result_item.get("distance", 0.0),
149-
entity=result_item.get("entity", {}),
150-
segmentation_ids=[],
151-
)
152-
)
153-
continue
154-
155-
try:
156-
segment = await db.segment.get(segment_id)
157-
segmentation_ids = await db.segment.find_by_span(
158-
edition_id=segment.edition_id,
159-
start=segment.span.start,
160-
end=segment.span.end,
161-
)
162-
enriched_results.append(
163-
SearchResult(
164-
id=result_item.get("id", ""),
165-
distance=result_item.get("distance", 0.0),
166-
entity=result_item.get("entity", {}),
167-
segmentation_ids=segmentation_ids,
168-
)
169-
)
170-
except DataNotFoundError:
171-
logger.warning("Segment %s not found, skipping segmentation mapping", segment_id)
172-
enriched_results.append(
173-
SearchResult(
174-
id=result_item.get("id", ""),
175-
distance=result_item.get("distance", 0.0),
176-
entity=result_item.get("entity", {}),
177-
segmentation_ids=[],
178-
)
179-
)
180-
except Exception:
181-
logger.exception("Error processing segment %s", segment_id)
182-
enriched_results.append(
183-
SearchResult(
184-
id=result_item.get("id", ""),
185-
distance=result_item.get("distance", 0.0),
186-
entity=result_item.get("entity", {}),
187-
segmentation_ids=[],
188-
)
189-
)
190-
191-
return SearchResponse.model_validate(
192-
{
193-
"query": search_response_data.get("query", query),
194-
"results": enriched_results,
195-
"count": len(enriched_results),
196-
}
197-
)
198-
199-
200102
@router.get(
201103
"/{segment_id}",
202104
summary="Get segment",

routers/texts.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from fastapi import APIRouter, BackgroundTasks, Depends, Path, Query, status
55

6-
from background_tasks import trigger_search_segmenter
76
from content_search import ContentSearchService
87
from dependencies import OptionalAppHeader, get_api_key, get_content_search, get_db, get_storage
98
from identifier import generate_id
@@ -125,7 +124,6 @@ async def create_edition(
125124
segmentation=data.segmentation,
126125
)
127126

128-
background_tasks.add_task(trigger_search_segmenter, edition_id)
129127
background_tasks.add_task(content_search.index_edition, edition_id, db, storage)
130128

131129
return IdResponse(id=edition_id)

tests/conftest.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from contextlib import suppress
88
from pathlib import Path
99
from typing import LiteralString, cast
10-
from unittest.mock import patch
1110

1211
import httpx
1312
from neo4j import GraphDatabase
@@ -260,20 +259,6 @@ async def content_search(_opensearch_endpoint: str) -> AsyncGenerator[ContentSea
260259
await service.close()
261260

262261

263-
@pytest.fixture(autouse=True)
264-
def mock_search_segmenter():
265-
"""
266-
Prevent background threads / network calls during tests.
267-
268-
These helpers are "fire-and-forget" and call external services; tests should never
269-
hit the network or spawn those background threads.
270-
"""
271-
with (
272-
patch("background_tasks.trigger_search_segmenter"),
273-
patch("background_tasks.trigger_delete_search_segments"),
274-
):
275-
yield
276-
277262

278263
class MockS3Storage:
279264
"""In-memory S3 storage mock for tests."""

0 commit comments

Comments
 (0)