Skip to content

Commit

Permalink
Use similarity search on contact titles
Browse files Browse the repository at this point in the history
  • Loading branch information
shri committed Sep 4, 2024
1 parent bd41908 commit 352324c
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/app/domain/opportunities/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import structlog
from typing import TYPE_CHECKING, Any

from sqlalchemy import ColumnElement, insert, select, or_, and_, not_, func
from sqlalchemy import ColumnElement, insert, select, or_, and_, not_, func, text
from advanced_alchemy.filters import SearchFilter, LimitOffset
from advanced_alchemy.exceptions import RepositoryError
from advanced_alchemy.service import SQLAlchemyAsyncRepositoryService, is_dict, is_msgspec_model, is_pydantic_model
Expand Down Expand Up @@ -184,21 +184,13 @@ async def scan(
"New Zealand",
]
person_titles = [
"Head of Platform",
"Platform Engineering Manager",
"Lead Platform Enginner",
"Senior Platform Enginner",
"Staff Software Engineer",
"Staff Platform Engineer",
"Platform",
"Platform Engineering",
"Tech Lead",
"Lead Software Engineer",
"Staff Engineer",
"Head of Engineering",
"Director of Engineering",
"Senior Director of Engineering",
"Sr. Director of Engineering",
"VP of Engineering",
"Vice President of Engineering",
"SVP of Engineering",
"CTO",
"Co-founder",
]
Expand Down Expand Up @@ -239,9 +231,10 @@ async def scan(
# TODO: Fetch the contact(s) with the right title from an external source
person_statement = (
select(Person.id)
.where(func.lower(Person.title).in_([title.lower() for title in person_titles]))
.where(Person.title.op("%")(text("ANY(:titles)")).params(titles=person_titles))
.execution_options(populate_existing=True)
)
await self.repository.session.execute(text("SET pg_trgm.similarity_threshold = 0.5;"))
person_results = await self.repository.session.execute(statement=person_statement)
person_ids = [result[0] for result in person_results]

Expand Down

0 comments on commit 352324c

Please sign in to comment.