Skip to content

Add search functionality #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ public class SearchRepository {
DataSource dataSource;

public List<Product> searchProduct (String input) {
return null;
// lowercase the input
var lowerInput = input.toLowerCase(Locale.ROOT);

// create a query using named parameters that matches the lowerinput to the product description or product name
var query = em.createQuery("Select p from Product p where lower(p.description) like :input OR lower(p.productName) like :input", Product.class);

// set the input parameter
query.setParameter("input", "%" + lowerInput + "%");

// get the result list
var resultList = (List<Product>) query.getResultList();
return resultList;
}

}
5 changes: 5 additions & 0 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
</head>
<body>
<div class="container">
<!-- add a header fragment -->
<!--/*/ <th:block th:include="fragments/header :: header"></th:block> /*/-->
<!-- add a productsTable fragment -->
<!--/*/ <th:block th:include="fragments/productsTable :: productsTable"></th:block> /*/-->


</div>
</body>
Expand Down