Science & Technology

#28 Project using Spring Search Feature

by Telusko

Share:

📚 Main topics

  • Why add searchSpring Data JPA provides basic repository methods, including finding a product by ID, but searching across fields such as name, description, or brand requires a custom repository method. 0:00
  • JPQL custom queryThe tutorial uses JPQL to search across multiple product fields. Unlike SQL, JPQL refers to entity class and field names rather than tables and columns. 2:01
  • Connecting the frontend and backendA search box sends a keyword to a backend endpoint, which passes it through the controller and service to the repository. 4:05
  • Implementing the queryThe repository query checks several product fields with a keyword and uses lowercasing and concatenation with wildcard characters for flexible, case-insensitive matching. 8:08

✨ Key takeaways

  • Search as you typeThe frontend sends a request whenever the user enters a character, allowing suggestions to appear without a separate search button. 4:05
  • Search multiple fieldsThe same keyword can match product names, descriptions, or brands, and the results are returned to the frontend. 13:54

🧠 Lessons learned

  • Use entity fields in JPQLA JPQL query uses the entity class name and its field names instead of SQL table and column names. 8:08
  • Check the full request flowWhen the search initially fails, verifying the endpoint and the data being returned helps identify the issue. 11:15

🏁 Conclusion/next steps

  • Test with sample productsAdding products with different names, descriptions, and brands demonstrates that the search can find matches across those fields. 13:18
  • Continue building the projectThe search feature is working, and the tutorial closes by looking ahead to future project features. 14:26

Transcript excerpt

0:00 so now it's time to implement the next feature which is a search feature now why search is important is because we are using Data JPA right which is spring data jpa and if you look at the repo layer it's quite empty so we are not defining any method or we not even declaring the methods we we got all the methods from the jpa repository so when things are simple like C operations it can be done with the help of JP repository but let's say if you want to find something which is not a primary key because whatever we are doing now if you're searching for if you're searching

0:30 for a product by the ID it is very easy right you can just use a product by ID and it works but what about if you want to search with some other things example if you want to search with the name or I the product name or the description or the amount the quantity I mean that's weird right why someone will search for buy quantity buy quantity doesn't matter you got the point right so if you have other fields to check with how do you make it work because Bight will not support example if I go back to my product service and let's say in any of

🔒 The full, searchable transcript is available with Pro.

🔒 Unlock Premium Features

This is a premium feature. Upgrade to unlock unlimited Q&A, transcripts, mindmaps, and translations.

🔒 Unlock Premium Features

Access to Chat is a premium feature. Upgrade now to unlock unlimited studying tools.

🔒 Unlock Premium Features

Access to Mindmap is a premium feature. Upgrade now to unlock unlimited studying tools.

🔒 Unlock Premium Features

Access to Translation is a premium feature. Upgrade now to unlock unlimited studying tools.

Get unlimited summaries, Q&A, transcripts and more with Pro

Upgrade to Pro

Suggestions

🔒 Unlock Premium Features

Access to AI Suggestions is a premium feature. Upgrade now to unlock unlimited studying tools.