Introduction
In Step 3, I connected users via the Follow system. Now, in Step 4, I implemented a Search Feature to let users find content.
More importantly, I established a Logging Strategy. I'm not just printing logs to the console; I'm saving user search patterns to a file to analyze trends later.
1. Search Implementation: LIKE Query
For the search functionality, I used the standard SQL LIKE operator.
// FeedRepository.java
Page<Feed> findByContentContainingOrderByCreatedAtDesc(String keyword, Pageable pageable);
- How it works: It translates to SELECT * FROM feed WHERE content LIKE '%keyword%'.
- Performance Note: Starting a query with a wildcard (%) prevents the database from using standard B-Tree indexes (Full Table Scan).
- Future Improvement: For a production-level application with millions of rows, I would switch to Full-Text Search (MySQL) or a dedicated search engine like Elasticsearch. But for this project scope, LIKE is sufficient.
2. Logging Strategy: Why File Logging?
Console logs disappear when the server restarts. To analyze user behavior (e.g., "What are people searching for?"), logs must be persisted.
I configured logback in application.yml to write logs to a specific file (logs/simple-sns.log).
logging:
file:
name: logs/simple-sns.log
logback:
rollingpolicy:
max-history: 7 # Keep logs for 7 days
And in the Service layer, I added a structured log message:
log.info("[SEARCH] keyword: {}", keyword);
This specific format [SEARCH] acts as a tag that will make parsing easier in Step 6 (Statistics).
3. Conclusion
This step was about preparing for the future. By logging user actions, I am laying the groundwork for data-driven features like "Trending Keywords".
Top comments (0)