Skip to content

Commit

Permalink
(#167) search bar fix (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
shub-garg authored Nov 18, 2024
1 parent 53c1a11 commit 5b346d9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
39 changes: 39 additions & 0 deletions db-prep/services-normalized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# import boto3

# dynamodb = boto3.resource('dynamodb')
# table = dynamodb.Table('services')

# response = table.scan()
# items = response['Items']

# for item in items:
# # Check if the 'Name' attribute exists
# if 'Name' in item:
# normalized_name = item['Name'].lower()

# # Update item with normalized fields
# table.update_item(
# Key={'Id': item['Id']}, # Use your table's primary key
# UpdateExpression="SET NormalizedName = :n",
# ExpressionAttributeValues={
# ':n': normalized_name
# }
# )
# else:
# print(f"Item {item} does not contain a 'Name' attribute.")
import boto3

dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("services")

response = table.scan()
items = response["Items"]

for item in items:
# Check if the 'Name' attribute exists
if "Name" not in item:
# Print the item being deleted
print(f"Deleting item: {item}")

# Delete the item from the table
table.delete_item(Key={"Id": item["Id"]}) # Use your table's primary key
11 changes: 8 additions & 3 deletions src/home/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ def fetch_items_with_filter(
):
filter_expression = None

search_query = search_query.lower() if search_query else None
# Create filter based on search query and category
if search_query and category_filter:
filter_expression = And(
Attr("Name").contains(search_query),
Attr("Category").contains(category_filter),
Attr("NormalizedName").contains(
search_query
), # Assuming data is stored in lowercase in "NormalizedName"
Attr("Category").contains(
category_filter
), # Assuming data is stored in lowercase in "NormalizedCategory"
)
elif search_query:
filter_expression = Attr("Name").contains(search_query)
filter_expression = Attr("NormalizedName").contains(search_query)
elif category_filter:
filter_expression = Attr("Category").contains(category_filter)

Expand Down

0 comments on commit 5b346d9

Please sign in to comment.