Skip to content

Commit

Permalink
Avoid duplicated terms
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanExtreme002 committed Jul 15, 2024
1 parent 2ce82c8 commit 99ce333
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Environments
.env
17 changes: 17 additions & 0 deletions back/src/api/search/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ async def insert_term(self, term: str) -> None:
"""
Insert a new term into the search engine.
"""
term = term.strip()

response = await self.client.search(
index=self.term_index_name,
body={
"query": {
"match_phrase": {
"term": term
}
}
}
)

# Check if the term already exists.
if response["hits"]["total"]["value"] > 0:
return

await self.client.index(
index=self.term_index_name,
document={"term": term},
Expand Down

0 comments on commit 99ce333

Please sign in to comment.