Fully functional fulltext search
This commit is contained in:
@@ -2,8 +2,9 @@ from enum import Enum
|
||||
from datetime import datetime, date
|
||||
from typing import List, Literal
|
||||
|
||||
from pymongo import TEXT, IndexModel
|
||||
from pydantic import Field, BaseModel, validator
|
||||
from beanie import Document, Link
|
||||
from beanie import Document, Indexed
|
||||
|
||||
|
||||
class EntityType(BaseModel):
|
||||
@@ -14,13 +15,11 @@ class EntityType(BaseModel):
|
||||
|
||||
class Individual(EntityType):
|
||||
type: Literal['individual'] = 'individual'
|
||||
firstname: str
|
||||
middlenames: List[str] = Field(default=[])
|
||||
lastname: str
|
||||
surnames: List[str] = Field(default=[])
|
||||
firstname: Indexed(str, index_type=TEXT)
|
||||
middlenames: List[Indexed(str)] = Field(default=[])
|
||||
lastname: Indexed(str)
|
||||
surnames: List[Indexed(str)] = Field(default=[])
|
||||
day_of_birth: date
|
||||
job: str
|
||||
employer: str
|
||||
|
||||
|
||||
@property
|
||||
@@ -39,7 +38,7 @@ class Individual(EntityType):
|
||||
|
||||
|
||||
class Employee(EntityType):
|
||||
role: str
|
||||
role: Indexed(str)
|
||||
entity_id: str = Field(foreignKey={
|
||||
"reference": {
|
||||
"resource": "entity",
|
||||
@@ -51,21 +50,21 @@ class Employee(EntityType):
|
||||
|
||||
class Corporation(EntityType):
|
||||
type: Literal['corporation'] = 'corporation'
|
||||
title: str
|
||||
activity: str
|
||||
title: Indexed(str)
|
||||
activity: Indexed(str)
|
||||
employees: List[Employee] = Field(default=[])
|
||||
|
||||
|
||||
class Institution(BaseModel):
|
||||
type: Literal['institution'] = 'institution'
|
||||
title: str
|
||||
activity: str
|
||||
title: Indexed(str)
|
||||
activity: Indexed(str)
|
||||
employees: List[Employee] = Field(default=[])
|
||||
|
||||
|
||||
class Entity(Document):
|
||||
_id: str
|
||||
address: str
|
||||
address: Indexed(str, index_type=TEXT)
|
||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
||||
label: str = None
|
||||
|
||||
@@ -82,3 +81,7 @@ class Entity(Document):
|
||||
else datetime(year=dt.year, month=dt.month, day=dt.day,
|
||||
hour=0, minute=0, second=0)
|
||||
}
|
||||
|
||||
fulltext_search = ['label']
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user