diff --git a/db-prep/services-normalized.py b/db-prep/services-normalized.py new file mode 100644 index 0000000..d4bb460 --- /dev/null +++ b/db-prep/services-normalized.py @@ -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 diff --git a/src/home/repositories.py b/src/home/repositories.py index 91f93a7..85e49c0 100644 --- a/src/home/repositories.py +++ b/src/home/repositories.py @@ -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)