- Create ocr_text table for storing per-region OCR results - Add tsvector search_vector column to photos with GIN index and auto-update trigger on filename/user_title/user_notes - Implement ocr_photo Celery task using rapidocr-onnxruntime - Add FTS leg to hybrid search: queries photos.search_vector and ocr_text via UNION, fused with semantic results via RRF (k=60) Migration 0004 backfills search_vector for existing rows. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
21 lines
741 B
Python
21 lines
741 B
Python
"""
|
|
OCR text model — stores text regions extracted from photos via rapidocr.
|
|
"""
|
|
from sqlalchemy import Column, String, Float, ForeignKey, Text, DateTime, func
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
import uuid
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class OCRText(Base):
|
|
__tablename__ = 'ocr_text'
|
|
|
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
photo_id = Column(String, ForeignKey('photos.id', ondelete='CASCADE'), nullable=False, index=True)
|
|
text = Column(Text, nullable=False)
|
|
language = Column(String(8), default='')
|
|
confidence = Column(Float)
|
|
bbox = Column(JSONB) # [x1, y1, x2, y2] normalized 0-1
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|